generated from coulomb/repo-seed
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
PUBLIC_ENDPOINTS = [
|
|
"/api/v2/hubs",
|
|
"/api/v2/hub-capability-manifests",
|
|
"/api/v2/widget-types",
|
|
"/api/v2/event-types",
|
|
"/api/v2/annotation-categories",
|
|
"/api/v2/policy-scopes",
|
|
"/api/v2/openapi.json",
|
|
"/api/v2/openapi.yaml",
|
|
]
|
|
|
|
PROTECTED_ENDPOINTS = [
|
|
"/api/v2/api-consumers",
|
|
"/api/v2/widgets",
|
|
"/api/v2/interaction-events",
|
|
"/api/v2/annotations",
|
|
"/api/v2/requirement-candidates",
|
|
"/api/v2/decision-records",
|
|
"/api/v2/deployment-records",
|
|
"/api/v2/outcome-signals",
|
|
"/api/v2/hub-registry",
|
|
]
|
|
|
|
|
|
def test_public_api_v2_endpoints_respond(app):
|
|
client = TestClient(app)
|
|
|
|
for endpoint in PUBLIC_ENDPOINTS:
|
|
response = client.get(endpoint)
|
|
assert response.status_code == 200, endpoint
|
|
|
|
|
|
def test_hubs_seed_core_hub(app):
|
|
response = TestClient(app).get("/api/v2/hubs")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()[0]["slug"] == "core-hub"
|
|
|
|
|
|
def test_protected_api_v2_endpoints_fail_before_business_logic(app):
|
|
client = TestClient(app)
|
|
|
|
for endpoint in PROTECTED_ENDPOINTS:
|
|
response = client.get(endpoint)
|
|
assert response.status_code == 401, endpoint
|
|
assert response.json()["detail"]["code"] == "unauthorized"
|
|
|
|
|
|
def test_openapi_contains_compatibility_routes(app):
|
|
payload = TestClient(app).get("/api/v2/openapi.json").json()
|
|
|
|
assert "/api/v2/hubs" in payload["paths"]
|
|
assert "/api/v2/widgets" in payload["paths"]
|