"""Shared fixtures: a synthetic DuckDB snapshot + FastAPI TestClient (rate limit disabled, fresh cache).""" from __future__ import annotations import os import warnings from pathlib import Path import pytest warnings.filterwarnings("ignore", message=".*httpx2.*") os.environ.setdefault("CA_ADMIN_TOKEN", "test-admin-token") from fastapi.testclient import TestClient from countryatlas.api.cache import ResponseCache from countryatlas.api.main import create_app from countryatlas.config import settings from tests.fixtures.make_fixture_db import COUNTRIES, INDICATORS, RUN_ID, build, value settings.admin_token = "test-admin-token" PREFIX = "/api/v1" @pytest.fixture(scope="session") def fixture_db(tmp_path_factory: pytest.TempPathFactory) -> Path: return build(tmp_path_factory.mktemp("atlas") / "atlas.duckdb") @pytest.fixture(scope="session") def app(fixture_db: Path): return create_app(fixture_db, rate_limit_per_minute=0, cache=ResponseCache()) @pytest.fixture(scope="session") def client(app) -> TestClient: with TestClient(app, raise_server_exceptions=False) as c: yield c @pytest.fixture def get(client: TestClient): def _get(path: str, status: int = 200, **kw): r = client.get(PREFIX + path, **kw) assert r.status_code == status, f"{path} → {r.status_code}: {r.text[:400]}" return r return _get def assert_provenance(p: dict) -> None: assert p is not None, "missing provenance" for k in ("source", "source_name", "dataset", "series_code", "retrieved_at", "source_updated_at", "url", "transform", "licence"): assert k in p, f"provenance missing {k}" assert p["source"] in ("worldbank", "imf", "owid", "who") assert p["url"].startswith("http") assert p["retrieved_at"] def assert_meta(body: dict) -> None: assert body["meta"]["run_id"] == RUN_ID assert body["meta"]["built_at"] == "2026-09-11T00:00:00Z" assert body["meta"]["generated_at"].endswith("Z") __all__ = ["COUNTRIES", "INDICATORS", "PREFIX", "RUN_ID", "assert_meta", "assert_provenance", "value"]