fids/flights-domain/flights-information/src/tests/functional/flights_functional_test.py

75 lines
2.1 KiB
Python

import json
from datetime import datetime
from fastapi.testclient import TestClient
from src.api.main import app
from src.api.models.flight import Flight
client = TestClient(app)
creating_flight = {
"flight_code": "ABC123",
"status": "pending",
"origin": "SLA",
"destination": "AEP",
"departure_time": datetime(2023, 10, 23, 12, 0, 0).isoformat(),
"arrival_time": datetime(2023, 10, 24, 12, 0, 0).isoformat(),
"gate": "10",
}
flights = [
Flight(
flight_code="ABC123",
status="pending",
origin="SLA",
destination="AEP",
departure_time=datetime(2023, 10, 23, 12, 0, 0),
arrival_time=datetime(2023, 10, 24, 12, 0, 0),
gate="10",
),
Flight(
flight_code="ABC124",
status="pending",
origin="AEP",
destination="SLA",
departure_time=datetime(2023, 10, 24, 12, 0, 0),
arrival_time=datetime(2023, 10, 25, 12, 0, 0),
gate="10",
),
]
def test_post_flight(test_database, get_flight):
test_database.query(Flight).delete()
api_call_retrieved_flight = client.post(
"/flights", data=json.dumps(creating_flight)
)
api_call_retrieved_flight_data = api_call_retrieved_flight.json()
db_retrieved_flight = get_flight(api_call_retrieved_flight_data["id"])
assert db_retrieved_flight.flight_code == creating_flight["flight_code"]
def test_patch_flight(test_database, create_flight):
test_database.query(Flight).delete()
created_flight = create_flight(flights[0])
api_call_retrieved_flight = client.patch(
f"/flights/{created_flight.id}", data=json.dumps({"status": "on-boarding"})
)
assert api_call_retrieved_flight.status_code == 200
api_call_retrieved_flight_data = api_call_retrieved_flight.json()
assert api_call_retrieved_flight_data["id"] == created_flight.id
assert api_call_retrieved_flight_data["status"] == "on-boarding"
def test_all_flights(test_database, create_flight):
test_database.query(Flight).delete()
create_flight(flights[0])
create_flight(flights[1])
resp = client.get("/flights")
print(resp.json())
assert resp.status_code == 200