Files
bincio-activity/tests/serve/test_ideas_router.py
T
Davide Scaini 8380b1d2cc Refactor: split serve/server.py (3220 lines) into focused modules
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.
2026-05-13 23:47:19 +02:00

47 lines
1.9 KiB
Python

"""Pre-split regression tests for /api/ideas/* and /api/feedback routes."""
from __future__ import annotations
from fastapi.testclient import TestClient
class TestIdeas:
def test_list_unauthenticated_returns_401(self, client: TestClient):
assert client.get("/api/ideas").status_code == 401
def test_create_unauthenticated_returns_4xx(self, client: TestClient):
# Pydantic validates the body before auth runs, so empty body → 422;
# a valid body → 401. Either is an auth/validation rejection.
r = client.post("/api/ideas", json={"title": "test", "body": ""})
assert r.status_code == 401
def test_authenticated_list_returns_ideas(self, user_client: TestClient):
r = user_client.get("/api/ideas")
assert r.status_code == 200
assert "ideas" in r.json()
def test_create_idea(self, user_client: TestClient):
r = user_client.post("/api/ideas", json={"title": "My idea", "body": "Details"})
assert r.status_code == 200
assert "id" in r.json()
def test_create_idea_empty_title_returns_400(self, user_client: TestClient):
r = user_client.post("/api/ideas", json={"title": "", "body": ""})
assert r.status_code == 400
def test_vote_on_missing_idea_returns_404(self, user_client: TestClient):
assert user_client.post("/api/ideas/no-such-id/vote").status_code == 404
def test_vote_toggle(self, user_client: TestClient):
create_r = user_client.post("/api/ideas", json={"title": "Votable", "body": ""})
idea_id = create_r.json()["id"]
r = user_client.post(f"/api/ideas/{idea_id}/vote")
assert r.status_code == 200
assert r.json()["voted"] is True
r2 = user_client.post(f"/api/ideas/{idea_id}/vote")
assert r2.json()["voted"] is False
class TestFeedback:
def test_unauthenticated_returns_401(self, client: TestClient):
assert client.post("/api/feedback", data={}).status_code == 401