File size: 7,436 Bytes
aefe381 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | """API endpoint tests."""
class TestCrowdAPI:
"""Test crowd data endpoints."""
def test_crowd_summary(self, auth_client):
resp = auth_client.get("/api/crowd/summary")
assert resp.status_code == 200
data = resp.get_json()
assert "total_current" in data
assert "overall_occupancy" in data
assert "zones" in data
def test_crowd_heatmap(self, auth_client):
resp = auth_client.get("/api/crowd/heatmap")
assert resp.status_code == 200
data = resp.get_json()
assert "heatmap_points" in data
def test_crowd_zone(self, auth_client):
resp = auth_client.get("/api/crowd/zone/north_stand")
assert resp.status_code == 200
data = resp.get_json()
assert "zone" in data
def test_crowd_zone_not_found(self, auth_client):
resp = auth_client.get("/api/crowd/zone/nonexistent")
assert resp.status_code == 404
def test_crowd_recommend(self, auth_client):
resp = auth_client.get("/api/crowd/recommend")
assert resp.status_code == 200
class TestQueueAPI:
"""Test queue endpoints."""
def test_queue_summary(self, auth_client):
resp = auth_client.get("/api/queue/summary")
assert resp.status_code == 200
data = resp.get_json()
assert "total_stations" in data
def test_queue_stations(self, auth_client):
resp = auth_client.get("/api/queue/stations")
assert resp.status_code == 200
data = resp.get_json()
assert isinstance(data, list)
def test_queue_stations_by_category(self, auth_client):
resp = auth_client.get("/api/queue/stations?category=food")
assert resp.status_code == 200
data = resp.get_json()
assert all(s["category"] == "food" for s in data)
def test_queue_shortest(self, auth_client):
resp = auth_client.get("/api/queue/shortest")
assert resp.status_code == 200
def test_queue_join(self, auth_client):
resp = auth_client.post(
"/api/queue/join",
json={"station_id": "f_n1"},
)
assert resp.status_code == 200
data = resp.get_json()
assert "id" in data
def test_queue_join_no_auth(self, client):
resp = client.post("/api/queue/join", json={"station_id": "f_n1"})
assert resp.status_code == 401
def test_queue_tickets(self, auth_client):
auth_client.post("/api/queue/join", json={"station_id": "f_n1"})
resp = auth_client.get("/api/queue/tickets")
assert resp.status_code == 200
data = resp.get_json()
assert isinstance(data, list)
class TestNavigationAPI:
"""Test navigation endpoints."""
def test_navigate_route(self, auth_client):
resp = auth_client.get("/api/navigate/route?from=gate_1&to=food_north")
assert resp.status_code == 200
data = resp.get_json()
assert "from" in data
assert "to" in data
assert "estimated_time_display" in data
def test_navigate_nearest(self, auth_client):
resp = auth_client.get("/api/navigate/nearest?from=gate_1&type=food_court")
assert resp.status_code == 200
data = resp.get_json()
assert "target_zone" in data
def test_navigate_pois(self, auth_client):
resp = auth_client.get("/api/navigate/pois")
assert resp.status_code == 200
data = resp.get_json()
assert isinstance(data, list)
assert len(data) > 0
def test_navigate_missing_params(self, auth_client):
resp = auth_client.get("/api/navigate/route")
assert resp.status_code == 400
class TestChatAPI:
"""Test chatbot endpoints."""
def test_chat_message(self, auth_client):
resp = auth_client.post(
"/api/chat",
json={"message": "Where is the food?"},
)
assert resp.status_code == 200
data = resp.get_json()
assert "response" in data
assert len(data["response"]) > 0
def test_chat_suggestions(self, auth_client):
resp = auth_client.get("/api/chat/suggestions")
assert resp.status_code == 200
data = resp.get_json()
assert isinstance(data, list)
def test_chat_no_auth(self, client):
resp = client.post("/api/chat", json={"message": "Hello"})
assert resp.status_code == 401
def test_chat_empty_message(self, auth_client):
resp = auth_client.post("/api/chat", json={"message": ""})
assert resp.status_code == 400
def test_chat_long_message(self, auth_client):
resp = auth_client.post("/api/chat", json={"message": "x" * 501})
assert resp.status_code == 400
class TestNotificationAPI:
"""Test notification endpoints."""
def test_get_notifications(self, auth_client):
resp = auth_client.get("/api/notifications")
assert resp.status_code == 200
def test_unread_count(self, auth_client):
resp = auth_client.get("/api/notifications/unread")
assert resp.status_code == 200
data = resp.get_json()
assert "count" in data
class TestSimulatorAPI:
"""Test simulator control endpoints."""
def test_simulator_status(self, auth_client):
resp = auth_client.get("/api/simulator/status")
assert resp.status_code == 200
data = resp.get_json()
assert "running" in data
assert "phase" in data
def test_simulator_start_requires_operator(self, auth_client):
resp = auth_client.post("/api/simulator/start")
assert resp.status_code == 403
def test_simulator_start_as_operator(self, operator_client):
resp = operator_client.post("/api/simulator/start")
assert resp.status_code == 200
def test_simulator_stop_as_operator(self, operator_client):
resp = operator_client.post("/api/simulator/stop")
assert resp.status_code == 200
def test_simulator_set_phase(self, operator_client):
resp = operator_client.post(
"/api/simulator/phase",
json={"phase": "halftime"},
)
assert resp.status_code == 200
def test_simulator_set_speed(self, operator_client):
resp = operator_client.post(
"/api/simulator/speed",
json={"speed": 2.0},
)
assert resp.status_code == 200
class TestEventVenueAPI:
"""Test event and venue info endpoints."""
def test_event_info(self, auth_client):
resp = auth_client.get("/api/event")
assert resp.status_code == 200
data = resp.get_json()
assert "name" in data
assert "sport" in data
def test_venue_info(self, auth_client):
resp = auth_client.get("/api/venue")
assert resp.status_code == 200
data = resp.get_json()
assert "name" in data
assert "zones" in data
class TestTranslationAPI:
"""Test translation endpoints."""
def test_languages_list(self, auth_client):
resp = auth_client.get("/api/languages")
assert resp.status_code == 200
data = resp.get_json()
assert "en" in data
def test_translate_text(self, auth_client):
resp = auth_client.post(
"/api/translate",
json={"text": "Hello", "target_lang": "hi"},
)
assert resp.status_code == 200
data = resp.get_json()
assert "translated" in data
|