3dac7e730a
- test_openapi_spec: валидность 3.1, полнота операций по ТЗ, writeOnly-секреты, единый формат Error, соответствие pydantic-моделей схемам. - test_contract_responses: все эндпоинты против схем, ошибки 401/404/409/422/503, WS-кадры, отсутствие секретов в ответах. - test_contract_negative: доказательство AC — подмена реализации на расходящуюся роняет контрактный тест с указанием пути до поля.
49 lines
1.0 KiB
Python
49 lines
1.0 KiB
Python
"""Общие фикстуры контрактных тестов."""
|
|
|
|
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
|