This commit is contained in:
2026-10-01 23:47:20 +03:00
parent e47a45dc93
commit 86222f5f93
6 changed files with 49 additions and 11 deletions
+17 -3
View File
@@ -58,6 +58,11 @@ class TestSpecFile:
):
assert name in headers, name
def test_no_hardcoded_servers(self, spec):
"""Без блока servers: Swagger UI «Try it out» и клиенты работают
относительно хоста, с которого получена спецификация (любой порт/деплой)."""
assert "servers" not in spec
def test_error_schema_codes(self, spec):
codes = set(spec["components"]["schemas"]["Error"]["properties"]["code"]["enum"])
# все коды из таблицы docs/05 §5.3
@@ -81,8 +86,8 @@ class TestSpecFile:
class TestSpecServed:
def test_openapi_json_serves_file_spec(self, client: TestClient):
"""Живой сервис отдаёт /openapi.json из openapi.yaml, а не автогенерацию."""
response = client.get("/openapi.json")
"""Живой сервис отдаёт /api/openapi.json из openapi.yaml, а не автогенерацию."""
response = client.get("/api/openapi.json")
assert response.status_code == 200
served = response.json()
assert served["paths"].keys() == yaml.safe_load(SPEC_PATH.read_text())["paths"].keys()
@@ -90,6 +95,15 @@ class TestSpecServed:
assert served["components"]["securitySchemes"]["ApiKeyAuth"]["name"] == "X-API-Key"
def test_docs_ui_available(self, client: TestClient):
response = client.get("/docs")
response = client.get("/api/docs")
assert response.status_code == 200
assert "swagger" in response.text.lower()
def test_docs_moved_from_root(self, client: TestClient):
"""Swagger живёт под /api/docs; корневой /docs больше не отдаётся."""
assert client.get("/docs").status_code == 404
def test_redoc_available(self, client: TestClient):
response = client.get("/api/redoc")
assert response.status_code == 200
assert "redoc" in response.text.lower()