98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
from datetime import datetime
|
|
|
|
from app.models.arrival import Arrival
|
|
from app.models.local_flight import LocalFlight, LocalFlightStatus, LocalFlightType
|
|
from app.models.movement import Movement, MovementType
|
|
|
|
|
|
def test_circuit_lifecycle_for_local_flight(auth_client, db):
|
|
flight = LocalFlight(
|
|
registration="G-CIR1",
|
|
type="C152",
|
|
callsign="GCIR1",
|
|
pob=1,
|
|
flight_type=LocalFlightType.CIRCUITS,
|
|
status=LocalFlightStatus.CIRCUIT,
|
|
created_by="test",
|
|
)
|
|
db.add(flight)
|
|
db.commit()
|
|
db.refresh(flight)
|
|
|
|
create_response = auth_client.post(
|
|
"/api/v1/circuits/",
|
|
json={"local_flight_id": flight.id, "circuit_timestamp": "2026-06-20T10:10:00"},
|
|
)
|
|
|
|
assert create_response.status_code == 200
|
|
circuit = create_response.json()
|
|
assert circuit["local_flight_id"] == flight.id
|
|
|
|
assert auth_client.get(f"/api/v1/circuits/{circuit['id']}").status_code == 200
|
|
assert auth_client.get("/api/v1/circuits/").json()[0]["id"] == circuit["id"]
|
|
assert auth_client.get(f"/api/v1/circuits/flight/{flight.id}").json()[0]["id"] == circuit["id"]
|
|
|
|
movement = db.query(Movement).filter(Movement.entity_type == "LOCAL_FLIGHT").one()
|
|
assert movement.movement_type == MovementType.TOUCH_AND_GO
|
|
assert movement.aircraft_registration == "G-CIR1"
|
|
|
|
update_response = auth_client.put(
|
|
f"/api/v1/circuits/{circuit['id']}",
|
|
json={"circuit_timestamp": "2026-06-20T10:20:00"},
|
|
)
|
|
assert update_response.status_code == 200
|
|
assert update_response.json()["circuit_timestamp"] == "2026-06-20T10:20:00"
|
|
|
|
delete_response = auth_client.delete(f"/api/v1/circuits/{circuit['id']}")
|
|
assert delete_response.status_code == 200
|
|
assert delete_response.json()["detail"] == "Circuit record deleted"
|
|
|
|
|
|
def test_circuit_lifecycle_for_arrival_and_error_paths(auth_client, db):
|
|
arrival = Arrival(
|
|
registration="G-CIR2",
|
|
type="PA28",
|
|
callsign="GCIR2",
|
|
pob=2,
|
|
in_from="EGLL",
|
|
status="INBOUND",
|
|
eta=datetime(2026, 6, 20, 10, 0),
|
|
created_by="test",
|
|
)
|
|
db.add(arrival)
|
|
db.commit()
|
|
db.refresh(arrival)
|
|
|
|
create_response = auth_client.post(
|
|
"/api/v1/circuits/",
|
|
json={"arrival_id": arrival.id, "circuit_timestamp": "2026-06-20T10:10:00"},
|
|
)
|
|
|
|
assert create_response.status_code == 200
|
|
circuit = create_response.json()
|
|
assert circuit["arrival_id"] == arrival.id
|
|
assert auth_client.get(f"/api/v1/circuits/arrival/{arrival.id}").json()[0]["id"] == circuit["id"]
|
|
|
|
movement = db.query(Movement).filter(Movement.entity_type == "ARRIVAL").one()
|
|
assert movement.movement_type == MovementType.TOUCH_AND_GO
|
|
assert movement.from_location == "EGLL"
|
|
|
|
missing_entity = auth_client.post(
|
|
"/api/v1/circuits/",
|
|
json={"circuit_timestamp": "2026-06-20T10:10:00"},
|
|
)
|
|
both_entities = auth_client.post(
|
|
"/api/v1/circuits/",
|
|
json={
|
|
"local_flight_id": 1,
|
|
"arrival_id": arrival.id,
|
|
"circuit_timestamp": "2026-06-20T10:10:00",
|
|
},
|
|
)
|
|
|
|
assert missing_entity.status_code == 400
|
|
assert both_entities.status_code == 400
|
|
assert auth_client.get("/api/v1/circuits/404").status_code == 404
|
|
assert auth_client.put("/api/v1/circuits/404", json={"circuit_timestamp": "2026-06-20T10:20:00"}).status_code == 404
|
|
assert auth_client.delete("/api/v1/circuits/404").status_code == 404
|