53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""Contract tests — scenario management."""
|
|
|
|
import pytest
|
|
|
|
from tests.base import ContractHelpers as H
|
|
from tests.endpoints import Endpoints as E
|
|
|
|
|
|
class TestListScenarios:
|
|
@pytest.mark.asyncio
|
|
async def test_returns_list(self, client):
|
|
res = await client.get(E.SCENARIOS)
|
|
H.assert_status(res, 200)
|
|
H.assert_is_list(res.json(), min_length=4)
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_each_has_metadata(self, client):
|
|
data = (await client.get(E.SCENARIOS)).json()
|
|
for s in data:
|
|
H.assert_has_fields(s, "scenario_id", "name", "description", "hubs", "flight_count")
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_known_scenarios_present(self, client):
|
|
ids = [s["scenario_id"] for s in (await client.get(E.SCENARIOS)).json()]
|
|
assert "normal_ops" in ids
|
|
assert "weather_disruption_ord" in ids
|
|
assert "maintenance_delay_sfo" in ids
|
|
assert "crew_swap_ewr" in ids
|
|
|
|
|
|
class TestActiveScenario:
|
|
@pytest.mark.asyncio
|
|
async def test_get_active(self, client):
|
|
res = await client.get(E.SCENARIO_ACTIVE)
|
|
H.assert_status(res, 200)
|
|
H.assert_has_fields(res.json(), "scenario_id", "name")
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_switch_scenario(self, client):
|
|
res = await client.put(E.SCENARIO_ACTIVE, json={"scenario_id": "normal_ops"})
|
|
H.assert_status(res, 200)
|
|
assert res.json()["scenario_id"] == "normal_ops"
|
|
|
|
res = await client.get(E.SCENARIO_ACTIVE)
|
|
assert res.json()["scenario_id"] == "normal_ops"
|
|
|
|
await client.put(E.SCENARIO_ACTIVE, json={"scenario_id": "weather_disruption_ord"})
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_switch_invalid(self, client):
|
|
res = await client.put(E.SCENARIO_ACTIVE, json={"scenario_id": "nonexistent"})
|
|
H.assert_status(res, 400)
|