diff --git a/flights-domain/flights-information/src/tests/dummy_test.py b/flights-domain/flights-information/src/tests/dummy_test.py deleted file mode 100644 index 3460836..0000000 --- a/flights-domain/flights-information/src/tests/dummy_test.py +++ /dev/null @@ -1,49 +0,0 @@ -from fastapi.testclient import TestClient - -from src.api.main import app - -client = TestClient(app) - - -def test_create_flight(test_db): - response = client.post( - "/flights", - json={ - "flight_code": "ABC125", - "status": "En ruta", - "origin": "Ciudad B", - "destination": "Ciudad A", - "departure_time": "2023-10-10 10:00 AM", - "arrival_time": "2023-10-10 12:00 PM", - "gate": "A2", - }, - ) - assert response.status_code == 200 - assert response.json() == { - "id": 1, - "flight_code": "ABC125", - "status": "En ruta", - "origin": "Ciudad B", - "destination": "Ciudad A", - "departure_time": "2023-10-10 10:00 AM", - "arrival_time": "2023-10-10 12:00 PM", - "gate": "A2", - } - - -def test_get_flight(test_db): - response = client.get("/flights/1") - assert response.status_code == 200 - # retrieved_fligt = Flight(**response.json()) - assert response.json() == { - "id": 1, - "flight_code": "ABC125", - "status": "En ruta", - "origin": "Ciudad B", - "destination": "Ciudad A", - "departure_time": "2023-10-10 10:00 AM", - "arrival_time": "2023-10-10 12:00 PM", - "gate": "A2", - } - # assert retrieved_fligt.id == flight_instance.id - # assert retrieved_fligt.__eq__(flight_instance) diff --git a/flights-domain/flights-information/src/tests/test_flights.py b/flights-domain/flights-information/src/tests/test_flights.py new file mode 100644 index 0000000..f0bd295 --- /dev/null +++ b/flights-domain/flights-information/src/tests/test_flights.py @@ -0,0 +1,47 @@ +from fastapi.testclient import TestClient +import src.api.cruds.flight + +from src.api.main import app + +client = TestClient(app) + + +mocked_flight = { + "id": 1, + "flight_code": "ABC125", + "status": "En ruta", + "origin": "Ciudad B", + "destination": "Ciudad A", + "departure_time": "2023-10-10 10:00 AM", + "arrival_time": "2023-10-10 12:00 PM", + "gate": "A2", + } + +class AttrDict(dict): + def __init__(self, *args, **kwargs): + super(AttrDict, self).__init__(*args, **kwargs) + self.__dict__ = self + + + +def test_not_found_flight(monkeypatch): + + def mock_get_flight_by_id(db,id): + return None + + monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id) + + resp = client.get("/flights/1") + assert resp.status_code == 404 + +def test_successful_get_flight(monkeypatch): + + def mock_get_flight_by_id(db,id): + return mocked_flight + + monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id) + + + response = client.get("/flights/1") + assert response.status_code == 200 + assert response.json() == mocked_flight