Improve activity response metadata
This commit is contained in:
@@ -8,6 +8,31 @@ from app.main import ActivityResult, app
|
||||
from app.settings import get_settings
|
||||
|
||||
|
||||
def test_activity_json_reports_stale_header(monkeypatch) -> None:
|
||||
monkeypatch.setenv("GITHUB_USERNAME", "octocat")
|
||||
monkeypatch.setenv("GITEA_BASE_URL", "https://gitea.example.com")
|
||||
monkeypatch.setenv("GITEA_USERNAME", "octocat")
|
||||
get_settings.cache_clear()
|
||||
|
||||
async def fake_collect_merged_activity(settings, cache, options):
|
||||
return ActivityResult(
|
||||
merged={"2026-01-01": {"github": 1, "gitea": 2, "total": 3}},
|
||||
stale=True,
|
||||
from_date=date(2026, 1, 1),
|
||||
to_date=date(2026, 1, 1),
|
||||
days_count=1,
|
||||
)
|
||||
|
||||
monkeypatch.setattr("app.main.collect_merged_activity", fake_collect_merged_activity)
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/activity.json")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["x-activity-stale"] == "true"
|
||||
assert response.json()["stale"] is True
|
||||
|
||||
|
||||
def test_activity_svg_returns_svg_content_type(monkeypatch) -> None:
|
||||
monkeypatch.setenv("GITHUB_USERNAME", "octocat")
|
||||
monkeypatch.setenv("GITEA_BASE_URL", "https://gitea.example.com")
|
||||
@@ -35,4 +60,18 @@ def test_activity_svg_returns_svg_content_type(monkeypatch) -> None:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"].startswith("image/svg+xml")
|
||||
assert response.headers["x-activity-stale"] == "false"
|
||||
assert "<svg" in response.text
|
||||
|
||||
|
||||
def test_activity_json_rejects_year_and_days_together(monkeypatch) -> None:
|
||||
monkeypatch.setenv("GITHUB_USERNAME", "octocat")
|
||||
monkeypatch.setenv("GITEA_BASE_URL", "https://gitea.example.com")
|
||||
monkeypatch.setenv("GITEA_USERNAME", "octocat")
|
||||
get_settings.cache_clear()
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/activity.json?year=2026&days=30")
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.json() == {"detail": "Provide either year or days, not both"}
|
||||
|
||||
Reference in New Issue
Block a user