From 0840f521b059f4a2e29bf6254b96f8107f7f2586 Mon Sep 17 00:00:00 2001 From: igorlimam Date: Mon, 2 Nov 2020 19:35:04 +0000 Subject: [PATCH 1/2] implementa stub de teste para GET /schedule --- api/src/routes/tests/test_schedule.py | 11 +++++++++++ requirements.txt | 3 +++ 2 files changed, 14 insertions(+) create mode 100644 api/src/routes/tests/test_schedule.py create mode 100644 requirements.txt diff --git a/api/src/routes/tests/test_schedule.py b/api/src/routes/tests/test_schedule.py new file mode 100644 index 0000000..5353a16 --- /dev/null +++ b/api/src/routes/tests/test_schedule.py @@ -0,0 +1,11 @@ +from unittest import mock + +import pytest + + +@pytest.fixture +def stub_de_dado(): + return True + +def test_stub(stub_de_dado): + assert stub_de_dado \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7a4de45 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask==1.1.2 +paramiko==2.7.2 +pytest==6.1.2 \ No newline at end of file From f8c6e1c1042db0e442d992200164cc337f7f1731 Mon Sep 17 00:00:00 2001 From: igorlimam Date: Mon, 2 Nov 2020 20:36:53 +0000 Subject: [PATCH 2/2] implementa teste de schedule valido para get /schedule Eu estou tendo um problemao em relacao ao import da api. Acontece que so consigo usar o client de teste do flask referente a api quando o arquivo de teste esta no mesmo nivel de diretorio da api, o que impede de criar uma estrutura adequada para armazenar os testes --- api/src/routes/tests/test_schedule.py | 11 -------- api/test_schedule.py | 36 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) delete mode 100644 api/src/routes/tests/test_schedule.py create mode 100644 api/test_schedule.py diff --git a/api/src/routes/tests/test_schedule.py b/api/src/routes/tests/test_schedule.py deleted file mode 100644 index 5353a16..0000000 --- a/api/src/routes/tests/test_schedule.py +++ /dev/null @@ -1,11 +0,0 @@ -from unittest import mock - -import pytest - - -@pytest.fixture -def stub_de_dado(): - return True - -def test_stub(stub_de_dado): - assert stub_de_dado \ No newline at end of file diff --git a/api/test_schedule.py b/api/test_schedule.py new file mode 100644 index 0000000..b757fc3 --- /dev/null +++ b/api/test_schedule.py @@ -0,0 +1,36 @@ +from unittest import mock + +import pytest + +from api import app + + +@pytest.fixture +def client(): + client = app.test_client() + return client + + +@pytest.fixture +def schedule_valido(): + LCC1 = [] + LCC2 = [ + { "course" : "Lab. de Prog2", "startTime": "10:00", "endTime": "12:00" }, + { "course" : "Prog1", "startTime": "08:00", "endTime": "10:00" } + ] + LCC3 = [] + return {"LCC1": LCC1, "LCC2": LCC2, "LCC3": LCC3} + + +@mock.patch('src.services.scheduleService.scheduleService') +def test_schedule_service_valido(mock_schedule_service, schedule_valido, client): + mock_schedule_service.return_value = expected_schedule = schedule_valido + expected_status_code = 200 + + response = client.get('/schedule') + actual_schedule = response.json + actual_status_code = response.status_code + + assert actual_status_code == expected_status_code + assert all(actual_schedule[campo] == expected_schedule[campo] for campo in expected_schedule) + assert all(campo in expected_schedule for campo in actual_schedule) \ No newline at end of file