8380b1d2cc
serve/server.py is now 69 lines — app factory, middleware, and router
registration only.
New modules:
deps.py (168 lines) — module-level globals + auth dependency functions
models.py (85 lines) — all Pydantic request/response models
tasks.py (136 lines) — background workers and job tracker
routers/ — one file per domain (10 routers, ~2750 lines total)
auth.py, me.py, admin.py, activities.py, uploads.py,
segments.py, strava.py, garmin.py, ideas.py, feed.py
cli.py updated to set globals on deps instead of server.
88 new regression tests in tests/serve/ cover auth guards and key
behaviours for every router; 294 total passing after the split.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""Pre-split regression tests for /api/segments/* routes."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestSegments:
|
|
def test_list_unauthenticated_returns_401(self, client: TestClient):
|
|
assert client.get("/api/segments").status_code == 401
|
|
|
|
def test_create_unauthenticated_returns_401(self, client: TestClient):
|
|
# Pydantic validates required fields before auth; send a valid body
|
|
r = client.post("/api/segments", json={
|
|
"name": "Test", "polyline": [[0, 0], [1, 1]], "distance_m": 600.0,
|
|
})
|
|
assert r.status_code == 401
|
|
|
|
def test_delete_unauthenticated_returns_401(self, client: TestClient):
|
|
assert client.delete("/api/segments/some-id").status_code == 401
|
|
|
|
def test_get_efforts_unauthenticated_returns_401(self, client: TestClient):
|
|
assert client.get("/api/segments/some-id/efforts").status_code == 401
|
|
|
|
def test_authenticated_list_returns_list(self, user_client: TestClient):
|
|
r = user_client.get("/api/segments")
|
|
assert r.status_code == 200
|
|
assert isinstance(r.json(), list)
|
|
|
|
def test_create_short_segment_returns_400(self, user_client: TestClient):
|
|
r = user_client.post("/api/segments", json={
|
|
"name": "Too short",
|
|
"polyline": [[45.0, 7.0], [45.001, 7.001]],
|
|
"distance_m": 100.0,
|
|
})
|
|
assert r.status_code == 400
|
|
|
|
def test_missing_segment_returns_404(self, user_client: TestClient):
|
|
assert user_client.get("/api/segments/no-such-segment").status_code == 404
|