From 454ddccfd57550277a9bb2c20c6d4cee1ee00992 Mon Sep 17 00:00:00 2001 From: Leonardo Facundes Date: Sat, 12 Oct 2019 17:10:57 -0300 Subject: [PATCH] Adicinando script de testes automatizados para rotas --- Pipfile | 1 + test_script.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test_script.py diff --git a/Pipfile b/Pipfile index 5c0fa88..f95a06a 100644 --- a/Pipfile +++ b/Pipfile @@ -17,3 +17,4 @@ python_version = "3" [scripts] lint = "pylint laguinho/" start = "flask run" +test = "python test_script.py" \ No newline at end of file diff --git a/test_script.py b/test_script.py new file mode 100644 index 0000000..7a83dca --- /dev/null +++ b/test_script.py @@ -0,0 +1,50 @@ +import laguinho +import unittest +import json + +class FlaskTestCase(unittest.TestCase): + app = laguinho.create_app() + tester = app.test_client() + content_sent = { + "name": "Name Teste", + "url": "https://url.teste.com", + "path": "path/teste", + "maintainers": [ + "Maintainer Teste One", + "Maintainer Teste Two", + "Maintainer Teste Three" + ], + "format": "csv", + "contributable": True + } + + def test_index(self): + response = self.tester.get('/', content_type='html/text') + self.assertEqual(response.status_code, 200) + + def test_datasets_publish(self): + response = self.tester.post('/datasets', data=json.dumps(self.content_sent), content_type='application/json') + + # verificando se o item é igual ao content_sent + self.assertEqual(json.loads(response.data), self.content_sent) + + def test_datasets_get_datasets(self): + self.tester.post('/datasets', data=json.dumps(self.content_sent), content_type='application/json') + self.tester.post('/datasets', data=json.dumps(self.content_sent), content_type='application/json') + response = self.tester.get('/datasets', content_type='html/text') + response_json = json.loads(response.data) + + # verificando se a lista contém 2 itens + self.assertEqual(len(response_json), 2) + # verificando se o primeiro item da lista é igual ao content_sent + self.assertEqual(response_json[1], self.content_sent) + + def test_datasets_get_datasets_by_name(self): + self.tester.post('/datasets', data=json.dumps(self.content_sent), content_type='application/json') + response = self.tester.get('/datasets/Name%20Teste') + + # verificando se o item é igual ao content_sent + self.assertEqual(json.loads(response.data), self.content_sent) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file