Coverage for tests/test_removed_endpoints.py: 100%
15 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-13 19:28 +0000
1"""3.0 retires legacy routes while retaining ordinary framework slash redirects."""
3import pytest
4from httpx import ASGITransport, AsyncClient
6from data_api.api.api import app
8REMOVED = [
9 ("GET", "/departments"),
10 ("GET", "/departments/"),
11 ("GET", "/departments/search"),
12 ("GET", "/announcements/lists/departments"),
13 ("GET", "/courses/search"),
14 ("POST", "/courses/search"),
15 ("GET", "/courses/lists/microcredits"),
16 ("GET", "/newsletters/NTHU-Newsletter"),
17 ("GET", "/locations/search"),
18 ("GET", "/buses/info/stops"),
19 ("GET", "/buses/schedules"),
20 ("GET", "/buses/stops/校門"),
21 ("GET", "/libraries/space"),
22 ("GET", "/libraries/lost_and_found"),
23 ("GET", "/energy/electricity_usage"),
24]
27@pytest.mark.parametrize("method,path", REMOVED)
28async def test_retired_routes_are_not_served(method, path):
29 async with AsyncClient(
30 transport=ASGITransport(app=app), base_url="http://test", follow_redirects=False
31 ) as client:
32 response = await client.request(method, path)
33 expected = (
34 422
35 if method == "GET" and path == "/courses/search"
36 else (405 if method == "POST" and path == "/courses/search" else 404)
37 )
38 assert response.status_code == expected
39 assert "location" not in response.headers
42def test_only_current_routes_are_registered():
43 paths = app.openapi()["paths"]
44 assert all(not path.endswith("/") for path in paths)
45 assert all(
46 not operation.get("deprecated", False)
47 for methods in paths.values()
48 for operation in methods.values()
49 )