test(api): контрактные тесты «схема ↔ реализация» (Refs #19)
contract-openapi / openapi-contract (push) Has been cancelled
contract-openapi / ts-client-is-current (push) Has been cancelled

- test_openapi_spec: валидность 3.1, полнота операций по ТЗ, writeOnly-секреты,
  единый формат Error, соответствие pydantic-моделей схемам.
- test_contract_responses: все эндпоинты против схем, ошибки 401/404/409/422/503,
  WS-кадры, отсутствие секретов в ответах.
- test_contract_negative: доказательство AC — подмена реализации на расходящуюся
  роняет контрактный тест с указанием пути до поля.
This commit is contained in:
2026-10-22 00:22:46 +03:00
parent 7d9cf8ca5e
commit 3dac7e730a
4 changed files with 665 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
"""Общие фикстуры контрактных тестов."""
from __future__ import annotations
from collections.abc import Iterator
from typing import Any
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from awg_api.app import create_app
from awg_api.contract import load_spec
from awg_api.state import MockState
TEST_TOKEN = "test-token-contract"
@pytest.fixture(scope="session")
def spec() -> dict[str, Any]:
"""Спецификация контракта (docs/openapi.yaml)."""
return load_spec()
@pytest.fixture
def state() -> MockState:
return MockState()
@pytest.fixture
def app(state: MockState) -> FastAPI:
return create_app(state=state, token=TEST_TOKEN)
@pytest.fixture
def client(app: FastAPI) -> Iterator[TestClient]:
with TestClient(app) as test_client:
yield test_client
@pytest.fixture
def auth_headers() -> dict[str, str]:
return {"Authorization": f"Bearer {TEST_TOKEN}"}
@pytest.fixture
def token() -> str:
return TEST_TOKEN