api/v1/schema n'est plus auth, schema renvoie table schema, adaptation des tests #78
This commit is contained in:
+3
-5
@@ -6,6 +6,7 @@ from src.api.auth import require_token
|
||||
from src.api.filters import FilterError, build_where
|
||||
from src.db import count_marches, query_marches
|
||||
from src.db import schema as duckdb_schema
|
||||
from src.utils.data import DATA_SCHEMA
|
||||
|
||||
bp = Blueprint(
|
||||
"api_v1",
|
||||
@@ -85,12 +86,9 @@ def health():
|
||||
|
||||
|
||||
@bp.route("/schema")
|
||||
@bp.doc(security=[{"BearerAuth": []}])
|
||||
@require_token
|
||||
def schema():
|
||||
"""Liste des colonnes disponibles dans le dataset DECP."""
|
||||
cols = [{"name": name, "type": str(dtype)} for name, dtype in duckdb_schema.items()]
|
||||
return {"columns": cols}
|
||||
"""Liste des champs disponibles dans le dataset DECP (format TableSchema)."""
|
||||
return {"fields": list(DATA_SCHEMA.values())}
|
||||
|
||||
|
||||
@bp.route("/data")
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
def test_schema_without_token_returns_401(api_client):
|
||||
def test_schema_accessible_without_token(api_client):
|
||||
client, _ = api_client
|
||||
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
|
||||
resp = client.get("/api/v1/schema", headers=valid_token_header)
|
||||
resp = client.get("/api/v1/schema")
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert "columns" in data
|
||||
assert isinstance(data["columns"], list)
|
||||
assert len(data["columns"]) > 0
|
||||
first = data["columns"][0]
|
||||
assert set(first.keys()) >= {"name", "type"}
|
||||
# uid doit être présent dans le schéma DECP de test
|
||||
names = [c["name"] for c in data["columns"]]
|
||||
assert "fields" in data
|
||||
assert isinstance(data["fields"], list)
|
||||
assert len(data["fields"]) > 0
|
||||
first = data["fields"][0]
|
||||
assert set(first.keys()) >= {"name", "type", "title", "description"}
|
||||
names = [f["name"] for f in data["fields"]]
|
||||
assert "uid" in names
|
||||
|
||||
@@ -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)
|
||||
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)
|
||||
|
||||
@@ -49,7 +49,7 @@ def test_matomo_disabled_skips_call(monkeypatch, api_client, valid_token_header)
|
||||
"_post_matomo",
|
||||
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)
|
||||
assert called == []
|
||||
|
||||
@@ -69,7 +69,7 @@ def test_matomo_enabled_posts_event(monkeypatch, api_client, valid_token_header)
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
assert len(captured) == 1
|
||||
|
||||
Reference in New Issue
Block a user