Corp/backend/tests/test_openapi_contract.py
Игорь Надеин 4f6244ab1f
Some checks failed
Deploy production / deploy (push) Failing after 2s
Fix CORP runtime errors and harden deployment and media access
2026-09-10 16:40:08 +03:00

58 lines
1.9 KiB
Python

"""Production schema checks must describe endpoints without guessing string types."""
from io import StringIO
import pytest
import yaml
from django.core.management import call_command
@pytest.mark.django_db
def test_openapi_schema_validates_without_warnings():
output = StringIO()
call_command(
"spectacular",
validate=True,
fail_on_warn=True,
stdout=output,
stderr=StringIO(),
)
schema = yaml.safe_load(output.getvalue())
components = schema["components"]["schemas"]
assert components["Project"]["properties"]["can_manage"]["type"] == "boolean"
assert components["Skill"]["properties"]["experience"]["type"] == "integer"
assert components["Skill"]["properties"]["next_rank"]["nullable"] is True
assert components["Employee"]["properties"]["skills"]["type"] == "array"
assert (
components["ChatUserSettings"]["properties"]["notifications_enabled"]["type"]
== "boolean"
)
assert "DayResponse" in components
assert "AnalyticsOptionsResponse" in components
assert "PushReplyResponse" in components
attachment_response = schema["paths"]["/api/v1/requests/{id}/attachment/download/"][
"get"
]["responses"]["200"]
assert attachment_response["content"]["application/octet-stream"]["schema"] == {
"type": "string",
"format": "binary",
}
for suffix, content_type in [
("", "application/octet-stream"),
("thumbnail/", "image/png"),
]:
operation = schema["paths"][
f"/api/v1/communications/messages/{{id}}/attachments/{{attachment_id}}/{suffix}"
]["get"]
assert operation["responses"]["200"]["content"][content_type]["schema"] == {
"type": "string",
"format": "binary",
}
assert (
next(p for p in operation["parameters"] if p["name"] == "attachment_id")[
"schema"
]["type"]
== "integer"
)