diff options
| author | Christian Cleberg <[email protected]> | 2026-04-11 13:58:01 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-11 13:58:01 -0500 |
| commit | 6149ca9c394df7d316f80db05ad0fc2aea6c550d (patch) | |
| tree | 11f6cebc445e14b4a79adae648eb46d4be710071 /tests/test_contributions_api.py | |
| parent | b6d1348abf907b8b9c16ab87487eb9384dc4cc89 (diff) | |
| download | hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.tar.gz hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.tar.bz2 hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.zip | |
feat: add lazy actor indexing for contribution lookups
Diffstat (limited to 'tests/test_contributions_api.py')
| -rw-r--r-- | tests/test_contributions_api.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/test_contributions_api.py b/tests/test_contributions_api.py index e221602..22d0af3 100644 --- a/tests/test_contributions_api.py +++ b/tests/test_contributions_api.py @@ -1,9 +1,10 @@ from datetime import UTC, datetime from fastapi.testclient import TestClient +from sqlalchemy import select from srht_contrib.main import create_app -from srht_contrib.models import ContributionEvent +from srht_contrib.models import ContributionEvent, TrackedActor def test_read_only_contribution_routes_are_public_and_write_routes_require_api_key(settings, db_engine, session_factory) -> None: @@ -45,6 +46,8 @@ def test_contributions_api_returns_zero_filled_range(client: TestClient, db_sess response = client.get("/api/contributions/~ccleberg?from=2026-03-28&to=2026-03-30") assert response.status_code == 200 + assert response.json()["is_indexed"] is True + assert response.json()["indexing_state"] == "indexed" assert response.json()["days"] == [ {"date": "2026-03-28", "count": 0, "score": 0.0}, {"date": "2026-03-29", "count": 0, "score": 0.0}, @@ -52,6 +55,20 @@ def test_contributions_api_returns_zero_filled_range(client: TestClient, db_sess ] +def test_public_read_registers_actor_for_lazy_indexing(client: TestClient, db_session) -> None: + response = client.get("/api/contributions/~ccleberg?from=2026-03-28&to=2026-03-30") + + tracked_actor = db_session.scalar(select(TrackedActor).where(TrackedActor.actor == "~ccleberg")) + + assert response.status_code == 200 + assert response.json()["is_indexed"] is False + assert response.json()["indexing_state"] == "pending" + assert response.json()["last_polled_at"] is None + assert tracked_actor is not None + assert tracked_actor.is_active is True + assert tracked_actor.last_requested_at is not None + + def test_contribution_stats_api(client: TestClient, db_session) -> None: db_session.add_all( [ @@ -88,6 +105,8 @@ def test_contribution_stats_api(client: TestClient, db_session) -> None: assert response.json()["total_score"] == 1.5 assert response.json()["longest_streak"] == 2 assert response.json()["current_streak"] == 2 + assert response.json()["is_indexed"] is True + assert response.json()["indexing_state"] == "indexed" def test_invalid_date_input_returns_400(client: TestClient) -> None: |
