Files

38 lines
1.5 KiB
Python
Raw Permalink Normal View History

"""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()