screen-locker/screen_locker/tests/test_gate_bonus_tutor.py
Krzysztof kuhy Rudnicki 96ad163ee6
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
earned_time 0.9.0: tutor earner renamed automation -> tutor
Pins bumped at all four sites; tests follow TUTOR / tutor_bonus_units.
pylint 4.1.3 (freshness gate).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YADHKXzZhhePzQ2rNoXFcK
2026-10-12 16:38:25 +02:00

75 lines
2.8 KiB
Python

"""The real registry's tutor rung through the live pass (earned_time 0.8.0).
Units are credited minutes: a ``detail.minutes`` row pays its minutes, a legacy
block row (no ``detail.minutes``) pays 15, and the rung stops paying at 60.
"""
from __future__ import annotations
from datetime import datetime, time
from typing import TYPE_CHECKING, Any
from unittest.mock import MagicMock
import earned_time
import pytest
from screen_locker._gate_bonus import apply_counted_bonus
from screen_locker.tests._earned_fixtures import signed, signing_key, write_ledger
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path
@pytest.fixture
def key(tmp_path: Path) -> Iterator[Path]:
with signing_key(tmp_path) as path:
yield path
@pytest.mark.usefixtures("key")
def test_the_real_tutor_rung_pays_legacy_blocks_as_15_minutes_up_to_60() -> None:
"""Legacy block rows (no ``detail.minutes``) pay 15 minutes each (0.8.0)."""
tutor = getattr(earned_time, "TUTOR", None)
if tutor is None:
pytest.skip("installed earned_time predates TUTOR (< 0.9)")
cutover = earned_time.TUTOR_FROM.isoformat()
state: dict[str, Any] = {}
adjust = MagicMock(return_value=True)
rows: list[dict[str, Any]] = []
for number in range(1, 6):
ended = datetime.combine(earned_time.TUTOR_FROM, time(18, number)).astimezone()
rows.append(
signed(
{
"kind": "credit",
"entry_id": f"s-b{number}",
"day": cutover,
"detail": {"block": number, "ended_at": ended.timestamp()},
}
)
)
write_ledger(tutor, rows)
apply_counted_bonus(state, adjust, tutor, cutover)
assert [c.args[0] for c in adjust.call_args_list] == [15, 15, 15, 15]
# Units are minutes now: five block rows count 75; the cap stops the pay.
assert state["tutor_bonus_units"] == {"date": cutover, "units": 75}
@pytest.mark.usefixtures("key")
def test_the_real_tutor_rung_pays_each_credited_minute() -> None:
"""A per-minute row (``detail.minutes``) pays exactly its minutes."""
tutor = getattr(earned_time, "TUTOR", None)
if tutor is None:
pytest.skip("installed earned_time predates TUTOR (< 0.9)")
cutover = earned_time.TUTOR_FROM.isoformat()
state: dict[str, Any] = {}
adjust = MagicMock(return_value=True)
ended = datetime.combine(earned_time.TUTOR_FROM, time(18, 7)).astimezone()
detail = {"block": 7, "minutes": 7, "ended_at": ended.timestamp()}
row = {"kind": "credit", "entry_id": "s-m7", "day": cutover, "detail": detail}
write_ledger(tutor, [signed(row)])
apply_counted_bonus(state, adjust, tutor, cutover)
adjust.assert_called_once_with(7)
assert state["tutor_bonus_units"] == {"date": cutover, "units": 7}