77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
"""
|
|
Dynamic smoke tests - auto-parametrized from introspected routes.
|
|
Tests that all GET endpoints return 200 (or acceptable alternatives).
|
|
"""
|
|
import pytest
|
|
from tests.registry import (
|
|
GET_NO_PARAMS, GET_WITH_PARAMS,
|
|
resolve_path, PREFIX_TO_SEED, ROUTE_REGISTRY,
|
|
)
|
|
|
|
# Routes that require query params to avoid 422
|
|
ROUTES_NEEDING_QUERY = {
|
|
"/search/api": "?q=test",
|
|
}
|
|
|
|
# Routes that may legitimately return non-200 without full context
|
|
ACCEPTABLE_CODES = {200, 307, 308}
|
|
|
|
|
|
# ── Test 1: All GET endpoints without path params ───────────
|
|
@pytest.mark.parametrize(
|
|
"path",
|
|
[r.path for r in GET_NO_PARAMS],
|
|
ids=[f"GET {r.path}" for r in GET_NO_PARAMS],
|
|
)
|
|
async def test_get_no_params_returns_200(client, path):
|
|
"""Every GET endpoint without path params should return 200."""
|
|
url = path
|
|
# Append required query params if needed
|
|
for route_prefix, query_string in ROUTES_NEEDING_QUERY.items():
|
|
if path == route_prefix or path.rstrip("/") == route_prefix.rstrip("/"):
|
|
url = path + query_string
|
|
break
|
|
|
|
r = await client.get(url, follow_redirects=True)
|
|
assert r.status_code in ACCEPTABLE_CODES or r.status_code == 200, \
|
|
f"GET {url} returned {r.status_code}"
|
|
|
|
|
|
# ── Test 2: All GET endpoints with valid seed IDs ───────────
|
|
@pytest.mark.parametrize(
|
|
"path_template",
|
|
[r.path for r in GET_WITH_PARAMS],
|
|
ids=[f"GET {r.path}" for r in GET_WITH_PARAMS],
|
|
)
|
|
async def test_get_with_valid_id_returns_200(client, all_seeds, path_template):
|
|
"""GET endpoints with a valid seed UUID should return 200."""
|
|
path = resolve_path(path_template, all_seeds)
|
|
# Skip if we couldn't resolve (no seed for this prefix)
|
|
if "{" in path:
|
|
pytest.skip(f"No seed mapping for {path_template}")
|
|
|
|
r = await client.get(path, follow_redirects=True)
|
|
assert r.status_code == 200, f"GET {path} returned {r.status_code}"
|
|
|
|
|
|
# ── Test 3: GET with fake UUID returns 404 ──────────────────
|
|
FAKE_UUID = "00000000-0000-0000-0000-000000000000"
|
|
|
|
# Build fake-ID test cases from routes that have path params
|
|
_fake_id_cases = []
|
|
for r in GET_WITH_PARAMS:
|
|
import re
|
|
fake_path = re.sub(r"\{[^}]+\}", FAKE_UUID, r.path)
|
|
_fake_id_cases.append((fake_path, r.path))
|
|
|
|
@pytest.mark.parametrize(
|
|
"path,template",
|
|
_fake_id_cases if _fake_id_cases else [pytest.param("", "", marks=pytest.mark.skip)],
|
|
ids=[f"404 {c[1]}" for c in _fake_id_cases] if _fake_id_cases else ["NOTSET"],
|
|
)
|
|
async def test_get_with_fake_id_returns_404(client, path, template):
|
|
"""GET endpoints with a nonexistent UUID should return 404."""
|
|
r = await client.get(path, follow_redirects=True)
|
|
assert r.status_code in (404, 302, 303), \
|
|
f"GET {path} returned {r.status_code}, expected 404 or redirect"
|