def test_get_gazettes_should_request_gazettes_to_interface_object(self): interface = self.create_mock_gazette_interface() set_gazette_interface(interface) client = TestClient(app) response = client.get("/gazettes/4205902") self.assertEqual(response.status_code, 200) interface.get_gazettes.assert_called_once()
def test_get_gazettes_should_return_json_with_items(self): today = date.today() interface = self.create_mock_gazette_interface([{ "territory_id": "4205902", "date": today, "url": "https://queridodiario.ok.org.br/", }]) set_gazette_interface(interface) client = TestClient(app) response = client.get("/gazettes/4205902") interface.get_gazettes.assert_called_once() self.assertEqual(interface.get_gazettes.call_args.args[0].territory_id, "4205902") self.assertEqual(response.status_code, 200) self.assertEqual( response.json(), [{ "territory_id": "4205902", "date": today.strftime("%Y-%m-%d"), "url": "https://queridodiario.ok.org.br/", }], )
def test_get_gazettes_should_return_empty_list_when_no_gazettes_is_found( self): today = date.today() interface = self.create_mock_gazette_interface() set_gazette_interface(interface) client = TestClient(app) response = client.get("/gazettes/4205902") interface.get_gazettes.assert_called_once() self.assertEqual(interface.get_gazettes.call_args.args[0].territory_id, "4205902") self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), [])
def test_get_gazettes_without_territory_id_should_fail(self): set_gazette_interface(MockGazetteAccessInterface()) client = TestClient(app) response = client.get("/gazettes/") self.assertEqual(response.status_code, 404)
def test_gazettes_endpoint_should_accept_territory_id(self): set_gazette_interface(self.create_mock_gazette_interface()) client = TestClient(app) response = client.get("/gazettes/4205902") self.assertEqual(response.status_code, 200)
def test_api_should_not_fail_when_try_to_set_any_object_as_gazettes_interface( self): set_gazette_interface(MockGazetteAccessInterface())
def test_api_should_fail_when_try_to_set_any_object_as_gazettes_interface( self): with self.assertRaises(Exception): set_gazette_interface(MagicMock())
import os import uvicorn from api import app, set_gazette_interface from gazettes import create_gazettes_interface from database import create_database_data_mapper database = os.environ["POSTGRES_DB"] user = os.environ["POSTGRES_USER"] password = os.environ["POSTGRES_PASSWORD"] host = os.environ["POSTGRES_HOST"] database_gateway = create_database_data_mapper(database, user, password, host) gazettes_interface = create_gazettes_interface(database_gateway) set_gazette_interface(gazettes_interface) uvicorn.run(app, host="0.0.0.0", port=8080)