Files
LedgerLine/tests/test_contract_insights.py
Movses Aslanyan ccf1783779 Add Phase 0a black-box integration test suite
81 tests across 11 files plus a 5-module harness (load, pg, streams,
containers, payloads), covering all eleven Phase 0 goals and all 13 named
chaos-flag pathologies. Talks to the system only over HTTP, Postgres, Redis,
and the Docker CLI -- no imports of application code. RED-BASELINE.md records
the suite failing red against the empty repo before any implementation
existed; README.md documents the request-contract fields invented to fill
gaps in the spec, measurement methodology, and known-flaky tests.

This suite is a frozen contract from this point forward per CLAUDE.md.
2026-09-05 08:11:59 +03:30

38 lines
1.5 KiB
Python

"""G1 -- GET /api/accounts/{id}/insights: contract shape, not the analytics
themselves (the N+1 and missing-index differential live in test_pathologies.py)."""
import uuid
import pytest
pytestmark = pytest.mark.contract
async def test_insights_for_cold_account(api, manifest):
"""G1: insights works for an ordinary (non-hot) account."""
resp = await api.get(f"/api/accounts/{manifest['cold_account_ids_sample'][0]}/insights")
assert resp.status_code == 200
assert isinstance(resp.json(), dict) and resp.json()
async def test_insights_for_hot_account(api, manifest):
"""G1: insights also works for a hot, high-volume account."""
resp = await api.get(f"/api/accounts/{manifest['hot_account_ids'][0]}/insights")
assert resp.status_code == 200
assert isinstance(resp.json(), dict) and resp.json()
async def test_insights_unknown_account_404(api):
"""G1: insights for a nonexistent account returns 404 with the error envelope."""
resp = await api.get(f"/api/accounts/{uuid.uuid4()}/insights")
assert resp.status_code == 404
assert "error" in resp.json()
async def test_insights_repeated_calls_are_consistent(api, manifest):
"""G1: two immediate calls for the same account return the same aggregate figures."""
account_id = manifest["clean_account_id"]
first = await api.get(f"/api/accounts/{account_id}/insights")
second = await api.get(f"/api/accounts/{account_id}/insights")
assert first.status_code == second.status_code == 200
assert first.json() == second.json()