Тест контракта читает ../docs/dev/api-contract-goodwill.openapi.yaml (без docs — skip); README: раздел гудвилла и коды INVALID_SHARE/DUPLICATE_ROW/MONEY_OUT_OF_RANGE; OpenSpec goodwill-table: пакетное сохранение, доля два знака, итоги по ГО и УК, единицы, Decisions made without discussion R-1…R-6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
"""Контракт гудвилла в docs (`dev/api-contract-goodwill.openapi.yaml`) совпадает с маршрутами и схемами приложения."""
|
||
|
||
from decimal import Decimal
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
import yaml
|
||
|
||
from src.app import app
|
||
from src.schemas.goodwill import GoodwillRowIn
|
||
from src.services.goodwill import validate_decision
|
||
|
||
CONTRACT = Path(__file__).resolve().parents[3] / "docs/dev/api-contract-goodwill.openapi.yaml"
|
||
|
||
|
||
def test_contract_matches_application():
|
||
if not CONTRACT.exists():
|
||
pytest.skip("нет ../docs: контракт гудвилла не проверен")
|
||
contract = yaml.safe_load(CONTRACT.read_text())
|
||
actual = app.openapi()
|
||
paths = {key: value for key, value in actual["paths"].items() if "/goodwill" in key}
|
||
assert contract["paths"] == paths
|
||
for name, schema in contract["components"]["schemas"].items():
|
||
assert schema == actual["components"]["schemas"][name], name
|
||
|
||
|
||
def test_share_with_comma():
|
||
data = GoodwillRowIn(ownership_share="80,12", include_in_kfo=True, comment="Доля подтверждена")
|
||
assert validate_decision(data).ownership_share == Decimal("80.12")
|