added tests

This commit is contained in:
2026-04-12 09:35:35 -03:00
parent 5c82703ebe
commit 4de44baf98
14 changed files with 1056 additions and 49 deletions

133
tests/test_scenario_data.py Normal file
View File

@@ -0,0 +1,133 @@
"""Contract tests — scenario data CRUD."""
import pytest
from tests.base import ContractHelpers as H
from tests.endpoints import Endpoints as E
from tests.helpers import set_scenario
class TestFlights:
@pytest.mark.asyncio
async def test_list_flights(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.get(E.DATA_FLIGHTS)
H.assert_status(res, 200)
data = res.json()
H.assert_is_list(data, min_length=1)
H.assert_has_fields(data[0], "flight_id", "origin", "destination", "status")
@pytest.mark.asyncio
async def test_flights_change_with_scenario(self, client):
await set_scenario(client, "weather_disruption_ord")
ord_ids = {f["flight_id"] for f in (await client.get(E.DATA_FLIGHTS)).json()}
await set_scenario(client, "crew_swap_ewr")
ewr_ids = {f["flight_id"] for f in (await client.get(E.DATA_FLIGHTS)).json()}
assert ord_ids != ewr_ids, "Different scenarios should have different flights"
await set_scenario(client, "weather_disruption_ord")
@pytest.mark.asyncio
async def test_patch_flight_delay(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.patch(E.flight("UA432"), json={"delay_minutes": 120})
H.assert_status(res, 200)
assert res.json()["delay_minutes"] == 120
flights = (await client.get(E.DATA_FLIGHTS)).json()
ua432 = next(f for f in flights if f["flight_id"] == "UA432")
assert ua432["delay_minutes"] == 120
@pytest.mark.asyncio
async def test_patch_flight_status(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.patch(E.flight("UA432"), json={"status": "CANCELLED"})
H.assert_status(res, 200)
assert res.json()["status"] == "CANCELLED"
@pytest.mark.asyncio
async def test_patch_unknown_flight(self, client):
res = await client.patch(E.flight("FAKE"), json={"delay_minutes": 10})
H.assert_status(res, 200)
assert "error" in res.json()
class TestCrew:
@pytest.mark.asyncio
async def test_list_crew(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.get(E.DATA_CREW)
H.assert_status(res, 200)
data = res.json()
H.assert_is_list(data, min_length=1)
H.assert_has_fields(data[0], "crew_id", "name", "role", "hours_until_limit", "at_risk")
@pytest.mark.asyncio
async def test_patch_crew_duty_hours(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.patch(E.crew("CR-1001"), json={"duty_hours_elapsed": 13.5})
H.assert_status(res, 200)
data = res.json()
assert data["duty_hours_elapsed"] == 13.5
assert data["at_risk"] is True
assert data["hours_until_limit"] == 0.5
class TestCrewNotes:
@pytest.mark.asyncio
async def test_get_notes(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.get(E.DATA_CREW_NOTES)
H.assert_status(res, 200)
data = res.json()
assert isinstance(data, dict)
assert "UA432" in data
assert len(data["UA432"]) > 0
@pytest.mark.asyncio
async def test_update_notes(self, client):
await set_scenario(client, "weather_disruption_ord")
new_notes = ["Test note alpha", "Test note beta"]
res = await client.put(E.crew_notes("UA432"), json={"notes": new_notes})
H.assert_status(res, 200)
assert res.json()["notes"] == new_notes
all_notes = (await client.get(E.DATA_CREW_NOTES)).json()
assert all_notes["UA432"] == new_notes
class TestMaintenance:
@pytest.mark.asyncio
async def test_get_maintenance(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.get(E.DATA_MAINTENANCE)
H.assert_status(res, 200)
assert isinstance(res.json(), dict)
@pytest.mark.asyncio
async def test_maintenance_has_mel_items(self, client):
await set_scenario(client, "maintenance_delay_sfo")
data = (await client.get(E.DATA_MAINTENANCE)).json()
assert len(data) > 0
for tail, items in data.items():
for item in items:
H.assert_has_fields(item, "mel_id", "system", "description")
class TestRebookings:
@pytest.mark.asyncio
async def test_get_rebookings(self, client):
await set_scenario(client, "weather_disruption_ord")
res = await client.get(E.DATA_REBOOKINGS)
H.assert_status(res, 200)
data = res.json()
H.assert_is_list(data, min_length=1)
H.assert_has_fields(data[0], "pax_id", "name", "urgency", "original_flight")
@pytest.mark.asyncio
async def test_empty_in_normal_ops(self, client):
await set_scenario(client, "normal_ops")
data = (await client.get(E.DATA_REBOOKINGS)).json()
assert len(data) == 0
await set_scenario(client, "weather_disruption_ord")