make caching opt-in
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
@@ -6,30 +8,31 @@ from app.main import ActivityResult, app
|
||||
from app.settings import get_settings
|
||||
|
||||
|
||||
def test_activity_svg_returns_svg_content_type(monkeypatch, tmp_path) -> None:
|
||||
def test_activity_svg_returns_svg_content_type(monkeypatch) -> None:
|
||||
monkeypatch.setenv("GITHUB_USERNAME", "octocat")
|
||||
monkeypatch.setenv("GITEA_BASE_URL", "https://gitea.example.com")
|
||||
monkeypatch.setenv("GITEA_USERNAME", "octocat")
|
||||
monkeypatch.setenv("CACHE_DIR", str(tmp_path))
|
||||
get_settings.cache_clear()
|
||||
with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir:
|
||||
monkeypatch.setenv("CACHE_DIR", temp_dir)
|
||||
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},
|
||||
"2026-01-02": {"github": 0, "gitea": 0, "total": 0},
|
||||
},
|
||||
stale=False,
|
||||
from_date=date(2026, 1, 1),
|
||||
to_date=date(2026, 1, 2),
|
||||
days_count=2,
|
||||
)
|
||||
async def fake_collect_merged_activity(settings, cache, options):
|
||||
return ActivityResult(
|
||||
merged={
|
||||
"2026-01-01": {"github": 1, "gitea": 2, "total": 3},
|
||||
"2026-01-02": {"github": 0, "gitea": 0, "total": 0},
|
||||
},
|
||||
stale=False,
|
||||
from_date=date(2026, 1, 1),
|
||||
to_date=date(2026, 1, 2),
|
||||
days_count=2,
|
||||
)
|
||||
|
||||
monkeypatch.setattr("app.main.collect_merged_activity", fake_collect_merged_activity)
|
||||
monkeypatch.setattr("app.main.collect_merged_activity", fake_collect_merged_activity)
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/activity.svg")
|
||||
client = TestClient(app)
|
||||
response = client.get("/activity.svg")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"].startswith("image/svg+xml")
|
||||
assert "<svg" in response.text
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"].startswith("image/svg+xml")
|
||||
assert "<svg" in response.text
|
||||
|
||||
Reference in New Issue
Block a user