"""Частичные правки шапки ОСВ и доменные ошибки до записи в БД.""" import pytest from src.common.exceptions import DomainValidationError from src.domain.osv_header import corrected_header CURRENT = {"period_year": 2025, "period_quarter": "Q3", "is_cumulative": True, "osv_account_code": "60"} @pytest.mark.parametrize( "patch", [ {"period_year": 1899}, {"period_year": 2100}, {"period_year": True}, {"period_year": "2025"}, {"period_quarter": "Q0"}, {"period_quarter": []}, {"period_quarter": None}, {"is_cumulative": None}, {"is_cumulative": "true"}, {"period_quarter": "Q1", "is_cumulative": False}, ], ) def test_invalid_period(patch: dict[str, object]) -> None: with pytest.raises(DomainValidationError) as error: corrected_header(CURRENT, patch) assert error.value.code == "INVALID_PERIOD" @pytest.mark.parametrize("year", [1900, 2099]) def test_valid_year_boundaries(year: int) -> None: assert corrected_header(CURRENT, {"period_year": year})["period_year"] == year def test_account_only_does_not_require_period() -> None: current = dict(CURRENT, period_quarter=None) assert corrected_header(current, {"osv_account_code": "60.1"}) == dict(current, osv_account_code="60.01") assert corrected_header(CURRENT, {}) == CURRENT @pytest.mark.parametrize("account", [None, "", " ", 60, []]) def test_empty_or_invalid_account(account: object) -> None: with pytest.raises(DomainValidationError) as error: corrected_header(CURRENT, {"osv_account_code": account}) assert error.value.code == "INVALID_ACCOUNT_CODE"