48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
"""Контроль агрегата нового API: строгий порог до округления, ручные правила."""
|
|
|
|
from decimal import Decimal
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from src.domain.corrections import calculate_totals
|
|
from tests.test_intercompany_matrix_golden import _source
|
|
|
|
|
|
@pytest.mark.fixtures
|
|
def test_real_exact_trade_pair(fixtures_dir: Path) -> None:
|
|
debit = _source(fixtures_dir, "schastl", "62", 21)
|
|
credit = _source(fixtures_dir, "rb", "60", 409)
|
|
result = calculate_totals(Decimal(debit["closing_debit"]), Decimal(credit["closing_credit"]))
|
|
assert result.eliminated_amount == Decimal("106311116.46")
|
|
assert result.deviation_percent == 0
|
|
assert result.status == "AUTO"
|
|
|
|
|
|
@pytest.mark.fixtures
|
|
@pytest.mark.parametrize(("ratio", "exceeds"), [("1.049999999", False), ("1.05", False), ("1.050000001", True)])
|
|
def test_threshold_before_display_rounding(fixtures_dir: Path, ratio: str, exceeds: bool) -> None:
|
|
amount = Decimal(_source(fixtures_dir, "schastl", "62", 21)["closing_debit"])
|
|
result = calculate_totals(amount, amount * Decimal(ratio))
|
|
assert result.exceeds_threshold is exceeds
|
|
assert result.eliminated_amount == (0 if exceeds else amount)
|
|
|
|
|
|
@pytest.mark.fixtures
|
|
@pytest.mark.parametrize("factor", ["0", "-1"])
|
|
def test_nonpositive_side_has_no_percentage_or_elimination(fixtures_dir: Path, factor: str) -> None:
|
|
amount = Decimal(_source(fixtures_dir, "rb", "66", 25)["closing_credit"])
|
|
result = calculate_totals(amount * Decimal(factor), amount)
|
|
assert result.deviation_percent is None
|
|
assert result.eliminated_amount == 0
|
|
assert result.exceeds_threshold
|
|
assert result.status == ("ONE_SIDED" if factor == "0" else "DISCREPANCY")
|
|
|
|
|
|
@pytest.mark.fixtures
|
|
def test_special_manual_rules_do_not_inherit_min(fixtures_dir: Path) -> None:
|
|
amount = Decimal(_source(fixtures_dir, "rb", "66", 25)["closing_credit"])
|
|
result = calculate_totals(amount, amount, manual=True)
|
|
assert result.eliminated_amount == 0
|
|
assert result.status == "MANUAL"
|