mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
Один чек часто смешивает несколько категорий трат (гипермаркет: часть — продукты, часть — бытовая химия). Раньше такую транзакцию приходилось огрублять до одной категории или дробить вручную на несколько записей. Теперь у транзакции есть второй режим: 2+ доли (TransactionSplit) с суммами по разным категориям, которые обязаны в точности складываться в сумму транзакции. - Новая модель TransactionSplit + миграция. - split_rule_violation() проверяет инварианты на создании и редактировании. - category_rollup.py — общий helper, которым теперь пользуются Dashboard, отчёт по категориям и бюджеты, учитывая доли сплитов наравне с обычными транзакциями. - Фильтр по категории в списке транзакций находит и сплит-транзакции. - Сплиты попадают в полный бэкап/восстановление БД. - 13 новых backend-тестов. - Фронтенд: переключатель «Разбить на несколько категорий» в форме транзакции с повторяемыми строками и индикатором остатка суммы; строка транзакции в списке показывает все категории сплита.
Backend tests
Real integration tests against a real Postgres database — a dedicated
aurum_test database created fresh, migrated, and dropped again on every
run. They never touch the real aurum database or its data: the app's
lifespan startup (which seeds against the real DB) is never triggered, and
every route's DB dependency is overridden to point at aurum_test instead.
Running
The stack must already be up (docker compose up -d). Test dependencies
aren't baked into the production image, so install them once per container
lifetime, then run pytest inside the running backend container — it's the
only place with network access to Postgres:
docker compose exec backend pip install -r requirements-dev.txt
docker compose exec backend pytest -v
Re-run just pytest -v for subsequent runs; the pip install only needs
repeating after a container restart/rebuild.
Adding a test
- Use the
clientfixture (anhttpx.AsyncClientwired to the app) to hit the API the same way the frontend does — prefer this over reaching into services/models directly, so tests keep verifying the actual contract. account_idandcategoriesfixtures give you the same default account/categories a real fresh install seeds.- Every table is truncated and reseeded before each test (see
conftest.py::_clean_database), so tests don't need to worry about leftover state or guess at IDs from a previous test.