SPB Git forge

spb/countryatlas

Public
20commits 1branches 0releases
268.3 MBsize
maindefault branch
12 days agolast push
TypeScript 57% Python 38.6% JavaScript 3.6% CSS 0.6%
2.0 KB · 67 lines python
Raw Blame History
1"""Shared fixtures: a synthetic DuckDB snapshot + FastAPI TestClient (rate limit disabled, fresh cache)."""2from __future__ import annotations34import os5import warnings6from pathlib import Path78import pytest910warnings.filterwarnings("ignore", message=".*httpx2.*")11os.environ.setdefault("CA_ADMIN_TOKEN", "test-admin-token")1213from fastapi.testclient import TestClient1415from countryatlas.api.cache import ResponseCache16from countryatlas.api.main import create_app17from countryatlas.config import settings18from tests.fixtures.make_fixture_db import COUNTRIES, INDICATORS, RUN_ID, build, value1920settings.admin_token = "test-admin-token"2122PREFIX = "/api/v1"232425@pytest.fixture(scope="session")26def fixture_db(tmp_path_factory: pytest.TempPathFactory) -> Path:27    return build(tmp_path_factory.mktemp("atlas") / "atlas.duckdb")282930@pytest.fixture(scope="session")31def app(fixture_db: Path):32    return create_app(fixture_db, rate_limit_per_minute=0, cache=ResponseCache())333435@pytest.fixture(scope="session")36def client(app) -> TestClient:37    with TestClient(app, raise_server_exceptions=False) as c:38        yield c394041@pytest.fixture42def get(client: TestClient):43    def _get(path: str, status: int = 200, **kw):44        r = client.get(PREFIX + path, **kw)45        assert r.status_code == status, f"{path} → {r.status_code}: {r.text[:400]}"46        return r4748    return _get495051def assert_provenance(p: dict) -> None:52    assert p is not None, "missing provenance"53    for k in ("source", "source_name", "dataset", "series_code", "retrieved_at", "source_updated_at", "url", "transform", "licence"):54        assert k in p, f"provenance missing {k}"55    assert p["source"] in ("worldbank", "imf", "owid", "who")56    assert p["url"].startswith("http")57    assert p["retrieved_at"]585960def assert_meta(body: dict) -> None:61    assert body["meta"]["run_id"] == RUN_ID62    assert body["meta"]["built_at"] == "2026-09-11T00:00:00Z"63    assert body["meta"]["generated_at"].endswith("Z")646566__all__ = ["COUNTRIES", "INDICATORS", "PREFIX", "RUN_ID", "assert_meta", "assert_provenance", "value"]67