arm-core/api/tests/test_goodwill_domain.py

53 lines
2.5 KiB
Python

"""Расчёт и жизненный цикл на реальной сумме вложений Приманыческого."""
from decimal import Decimal
from pathlib import Path
from uuid import UUID
import pytest
from src.domain.goodwill import Decision, Investment, build, totals
from tests.test_goodwill_golden import investment_rows
pytestmark = pytest.mark.fixtures
A, B, C = (UUID(int=i) for i in (1, 2, 3))
def test_calculation_and_lifecycle(fixtures_dir: Path) -> None:
fv = Decimal(investment_rows(fixtures_dir)[0]["closing_debit"])
source = [Investment(A, B, fv)]
rows = build(source, {}, {B: Decimal("100000.00")})
assert rows[0].goodwill_amount is None
saved = {(A, B): Decision(Decimal("12.3456"), True, "Обоснование")}
row = build(source, saved, {B: Decimal("100000.00")})[0]
assert row.participation_amount == Decimal("12345.60")
assert row.goodwill_amount == fv - Decimal("12345.60")
gone = build([], saved, {})[0]
assert not gone.has_investments and gone.goodwill_amount is None
assert gone.financial_investment_amount is None
assert gone.decision == saved[A, B]
assert totals([gone], True)["financial_investment_amount"] == 0
assert build(source, saved, {B: Decimal("100000.00")})[0] == row
def test_zero_missing_capital_and_warning(fixtures_dir: Path) -> None:
fv = Decimal(investment_rows(fixtures_dir)[0]["closing_debit"])
source = [Investment(A, B, fv), Investment(C, B, fv)]
saved = {(A, B): Decision(Decimal("70"), True, "A"), (C, B): Decision(Decimal("40"), True, "C")}
rows = build(source, saved, {B: Decimal("0")})
assert all(r.participation_amount == 0 and r.goodwill_amount == fv for r in rows)
assert all("OWNERSHIP_TOTAL_EXCEEDED" in r.warnings for r in rows)
assert totals(rows, False)["goodwill_in_kfo_amount"] == 0
assert all(r.goodwill_amount is None for r in build(source, saved, {}))
def test_rounding_and_unselected(fixtures_dir: Path) -> None:
fv = Decimal(investment_rows(fixtures_dir)[0]["closing_debit"])
source = [Investment(A, B, fv)]
row = build(source, {(A, B): Decision(Decimal("0.0001"), False, None)}, {B: Decimal("5000")})[0]
assert row.participation_amount is None
selected = build(source, {(A, B): Decision(Decimal("0.0001"), True, "Подтверждено")}, {B: Decimal("5000")})[0]
assert selected.participation_amount == Decimal("0.01")
assert totals([row], True)["goodwill_amount"] == 0
assert totals([row], True)["financial_investment_amount"] == fv