D16a: единое правило классификации recurring — только по знаку
This commit is contained in:
1 parent
0307533cef
commit
e7d14ba25d
4 files changed
+87
-1
No files matched your search
@@ -3,6 +3,7 @@ from decimal import Decimal
|
||||
import pytest
|
||||
|
||||
from application.forecast import ForecastError, ForecastService
|
||||
from domain import Account, FinancialModel, RecurringCashflow
|
||||
|
||||
_MAIN_ACCOUNT = "Основной счёт"
|
||||
_SAVINGS_ACCOUNT = "Сбережения"
|
||||
@@ -41,6 +42,46 @@ class TestForecastService:
|
||||
assert results == []
|
||||
|
||||
|
||||
class TestRecurringClassificationBySign:
|
||||
"""D16a: recurring классифицируется только по знаку, `category` — подпись."""
|
||||
|
||||
@staticmethod
|
||||
def _model(*recurring: RecurringCashflow) -> FinancialModel:
|
||||
return FinancialModel(
|
||||
accounts=[Account(name="Счёт", balance=Decimal("0"))],
|
||||
recurring=list(recurring),
|
||||
)
|
||||
|
||||
def test_negative_amount_with_income_category_is_expense(self):
|
||||
model = self._model(RecurringCashflow(amount=Decimal("-500"), category="income"))
|
||||
summary = ForecastService(model).summary(months=1)
|
||||
|
||||
assert summary["total_income"] == Decimal("0")
|
||||
assert summary["total_expenses"] == Decimal("500")
|
||||
assert summary["total_balance"] == Decimal("-500")
|
||||
|
||||
def test_positive_amount_with_expense_category_is_income(self):
|
||||
model = self._model(RecurringCashflow(amount=Decimal("500"), category="expense"))
|
||||
summary = ForecastService(model).summary(months=1)
|
||||
|
||||
assert summary["total_income"] == Decimal("500")
|
||||
assert summary["total_expenses"] == Decimal("0")
|
||||
assert summary["total_balance"] == Decimal("500")
|
||||
|
||||
def test_category_does_not_affect_classification(self):
|
||||
# Оба платежа противоположны своим категориям: по знаку это
|
||||
# доход 500 и расход 500, а не наоборот.
|
||||
model = self._model(
|
||||
RecurringCashflow(amount=Decimal("-500"), category="income"),
|
||||
RecurringCashflow(amount=Decimal("500"), category="expense"),
|
||||
)
|
||||
summary = ForecastService(model).summary(months=1)
|
||||
|
||||
assert summary["total_income"] == Decimal("500")
|
||||
assert summary["total_expenses"] == Decimal("500")
|
||||
assert summary["total_balance"] == Decimal("0")
|
||||
|
||||
|
||||
class TestForecastCharacterization:
|
||||
"""Фиксация текущих чисел движка прогноза.
|
||||
|
||||
|
||||
Reference in new issue
Block a user