fids/flights-domain/flights-information/src/tests/unit/flights_unit_test.py

42 lines
1.1 KiB
Python

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