Files
F-r-ldraledigplannerare/backend/tests/unit/test_default_tier_pool_share.py
T
jacobh2 e4719cb9ae Rework balances around per-parent days left and deduce the partner from FK
Manual entry now takes one parent's sjukpenningnivå, lägstanivå and
dubbeldagar left (plus optional reserved days) and derives the rest in
build_snapshot, shared with the scraper. The scraper also reads the
family panel and exposes a partner deduction; with two parents it is
saved as a 'deduced' snapshot (migration 002). Parent count is the single
source of entitlement: one member gets 480 days and 96 savable at age 4,
two get 240 and 48 each. Workspaces are capped at two parents.

Also lands the in-flight squash of migrations 002–011 into the initial
schema and the removal of planning_mode.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-19 12:27:29 +02:00

37 lines
1.7 KiB
Python

"""Tests for `default_tier_pool_share` — the assumed per-parent tier share
used when no FK snapshot exists yet.
See its docstring in `app/utils/tip_predicates.py` and the "Bug A" history:
`AllocationInputLoader.load` and `PlanningService._tier_pool_left` must never
derive this differently, which is why it takes an explicit `parent_count`
now instead of always halving (a sole parent gets the whole pool, not half
of it).
"""
from app.config import settings
from app.utils.tip_predicates import default_tier_pool_share
class TestDefaultTierPoolShare:
def test_sole_parent_gets_the_full_pool(self) -> None:
sjuk, lagsta = default_tier_pool_share(settings.rules, parent_count=1)
assert (sjuk, lagsta) == (390, 90)
def test_zero_parents_is_treated_as_a_sole_parent(self) -> None:
"""Defensive: an empty workspace (shouldn't normally happen) still
gets a sane default rather than a divide/half-of-nothing edge case."""
sjuk, lagsta = default_tier_pool_share(settings.rules, parent_count=0)
assert (sjuk, lagsta) == (390, 90)
def test_two_parents_split_the_pool_in_half(self) -> None:
sjuk, lagsta = default_tier_pool_share(settings.rules, parent_count=2)
assert (sjuk, lagsta) == (195, 45)
def test_more_than_two_parents_still_splits_in_half(self) -> None:
"""The domain model caps workspaces at 2 parents (see
`WorkspaceService.add_placeholder_parent`), but this helper doesn't
itself need to assume that cap holds -- any partnered case (>= 2)
gets the halved share, matching FK's own per-parent allocation."""
sjuk, lagsta = default_tier_pool_share(settings.rules, parent_count=3)
assert (sjuk, lagsta) == (195, 45)