api/v1/schema n'est plus auth, schema renvoie table schema, adaptation des tests #78

This commit is contained in:
Colin Maudry
2026-06-16 17:03:14 +02:00
parent fede22f314
commit ffaf200c07
3 changed files with 16 additions and 19 deletions
+3 -5
View File
@@ -6,6 +6,7 @@ from src.api.auth import require_token
from src.api.filters import FilterError, build_where from src.api.filters import FilterError, build_where
from src.db import count_marches, query_marches from src.db import count_marches, query_marches
from src.db import schema as duckdb_schema from src.db import schema as duckdb_schema
from src.utils.data import DATA_SCHEMA
bp = Blueprint( bp = Blueprint(
"api_v1", "api_v1",
@@ -85,12 +86,9 @@ def health():
@bp.route("/schema") @bp.route("/schema")
@bp.doc(security=[{"BearerAuth": []}])
@require_token
def schema(): def schema():
"""Liste des colonnes disponibles dans le dataset DECP.""" """Liste des champs disponibles dans le dataset DECP (format TableSchema)."""
cols = [{"name": name, "type": str(dtype)} for name, dtype in duckdb_schema.items()] return {"fields": list(DATA_SCHEMA.values())}
return {"columns": cols}
@bp.route("/data") @bp.route("/data")
+10 -11
View File
@@ -1,19 +1,18 @@
def test_schema_without_token_returns_401(api_client): def test_schema_accessible_without_token(api_client):
client, _ = api_client client, _ = api_client
resp = client.get("/api/v1/schema") resp = client.get("/api/v1/schema")
assert resp.status_code == 401 assert resp.status_code == 200
def test_schema_returns_columns(api_client, valid_token_header): def test_schema_returns_fields(api_client):
client, _ = api_client client, _ = api_client
resp = client.get("/api/v1/schema", headers=valid_token_header) resp = client.get("/api/v1/schema")
assert resp.status_code == 200 assert resp.status_code == 200
data = resp.get_json() data = resp.get_json()
assert "columns" in data assert "fields" in data
assert isinstance(data["columns"], list) assert isinstance(data["fields"], list)
assert len(data["columns"]) > 0 assert len(data["fields"]) > 0
first = data["columns"][0] first = data["fields"][0]
assert set(first.keys()) >= {"name", "type"} assert set(first.keys()) >= {"name", "type", "title", "description"}
# uid doit être présent dans le schéma DECP de test names = [f["name"] for f in data["fields"]]
names = [c["name"] for c in data["columns"]]
assert "uid" in names assert "uid" in names
+3 -3
View File
@@ -29,7 +29,7 @@ def test_after_request_hook_increments_counter_async(api_client, valid_token_hea
# Faire une requête (qui doit déclencher l'incrément) # Faire une requête (qui doit déclencher l'incrément)
client.get("/api/v1/health") # pas authentifiée → ne compte pas client.get("/api/v1/health") # pas authentifiée → ne compte pas
client.get("/api/v1/schema", headers=valid_token_header) client.get("/api/v1/data", headers=valid_token_header) # /schema est public
tracking.flush(timeout=2.0) tracking.flush(timeout=2.0)
@@ -49,7 +49,7 @@ def test_matomo_disabled_skips_call(monkeypatch, api_client, valid_token_header)
"_post_matomo", "_post_matomo",
lambda **kw: called.append(kw), lambda **kw: called.append(kw),
) )
client.get("/api/v1/health") client.get("/api/v1/data", headers=valid_token_header) # authentifiée → hook actif
tracking.flush(timeout=2.0) tracking.flush(timeout=2.0)
assert called == [] assert called == []
@@ -69,7 +69,7 @@ def test_matomo_enabled_posts_event(monkeypatch, api_client, valid_token_header)
) )
client, _ = api_client client, _ = api_client
client.get("/api/v1/schema", headers=valid_token_header) client.get("/api/v1/data", headers=valid_token_header) # /schema est public
tracking.flush(timeout=2.0) tracking.flush(timeout=2.0)
assert len(captured) == 1 assert len(captured) == 1