Merge remote-tracking branch 'origin/main'

This commit is contained in:
2026-06-28 07:41:54 -04:00
2 changed files with 38 additions and 1 deletions
+3 -1
View File
@@ -187,7 +187,7 @@ class CRUDLocalFlight:
current_time = timestamp if timestamp is not None else datetime.utcnow() current_time = timestamp if timestamp is not None else datetime.utcnow()
if status == LocalFlightStatus.GROUND: if status == LocalFlightStatus.GROUND:
db_obj.contact_dt = current_time db_obj.contact_dt = current_time
elif status == LocalFlightStatus.DEPARTED: elif status == LocalFlightStatus.DEPARTED and not db_obj.departed_dt:
db_obj.departed_dt = current_time db_obj.departed_dt = current_time
elif status == LocalFlightStatus.LANDED and not db_obj.landed_dt: elif status == LocalFlightStatus.LANDED and not db_obj.landed_dt:
db_obj.landed_dt = current_time db_obj.landed_dt = current_time
@@ -200,6 +200,8 @@ class CRUDLocalFlight:
# Takeoff: happens once when transitioning away from GROUND # Takeoff: happens once when transitioning away from GROUND
if old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT) and not db_obj.takeoff_dt: if old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT) and not db_obj.takeoff_dt:
db_obj.takeoff_dt = current_time db_obj.takeoff_dt = current_time
if not db_obj.departed_dt:
db_obj.departed_dt = current_time
db.add(db_obj) db.add(db_obj)
db.commit() db.commit()
+35
View File
@@ -194,6 +194,7 @@ def test_local_flight_lifecycle_special_lists_and_not_found_paths(auth_client, d
assert departed_response.status_code == 200 assert departed_response.status_code == 200
assert departed_response.json()["takeoff_dt"] == "2026-06-20T10:05:00" assert departed_response.json()["takeoff_dt"] == "2026-06-20T10:05:00"
assert departed_response.json()["departed_dt"] == "2026-06-20T10:05:00"
assert landed_response.status_code == 200 assert landed_response.status_code == 200
assert landed_response.json()["landed_dt"] == "2026-06-20T10:45:00" assert landed_response.json()["landed_dt"] == "2026-06-20T10:45:00"
@@ -222,6 +223,40 @@ def test_local_flight_lifecycle_special_lists_and_not_found_paths(auth_client, d
assert auth_client.delete("/api/v1/local-flights/404").status_code == 404 assert auth_client.delete("/api/v1/local-flights/404").status_code == 404
def test_local_flight_takeoff_to_local_sets_departed_dt(auth_client):
create_response = auth_client.post(
"/api/v1/local-flights/",
json={
"registration": "g-air",
"type": "PA28",
"pob": 2,
"flight_type": "LOCAL",
"duration": 30,
"etd": "2026-06-20T09:00:00",
},
)
assert create_response.status_code == 200
takeoff_response = auth_client.patch(
f"/api/v1/local-flights/{create_response.json()['id']}/status",
json={"status": "LOCAL", "timestamp": "2026-06-20T09:05:00"},
)
assert takeoff_response.status_code == 200
assert takeoff_response.json()["status"] == "LOCAL"
assert takeoff_response.json()["takeoff_dt"] == "2026-06-20T09:05:00"
assert takeoff_response.json()["departed_dt"] == "2026-06-20T09:05:00"
landing_response = auth_client.patch(
f"/api/v1/local-flights/{create_response.json()['id']}/status",
json={"status": "LANDED", "timestamp": "2026-06-20T09:35:00"},
)
assert landing_response.status_code == 200
assert landing_response.json()["status"] == "LANDED"
assert landing_response.json()["landed_dt"] == "2026-06-20T09:35:00"
def test_overflight_lifecycle_special_lists_and_not_found_paths(auth_client, db): def test_overflight_lifecycle_special_lists_and_not_found_paths(auth_client, db):
payload = { payload = {
"registration": "g-ovr", "registration": "g-ovr",