mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 20:27:13 +01:00
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.12) (push) Has been cancelled
Tests / lock-popup-safety (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
workout-locker.timer (added in e5db254) re-runs the full lock-decision
chain every 30 minutes, but is_relaxed_day() is a pure date check with
no memory of an earlier same-day dismissal. Clicking "Skip — No
Penalty" only closed the window without persisting anything, so the
next tick re-derived reason=relaxed_day and rebuilt the same popup.
Now the skip button writes a relaxed_day_skip marker to the log
(excluded from weekly counting and sync, same treatment as heat_skip),
and the startup chain checks for it before re-entering the relaxed-day
branch. Also renames workout_log.json to log.json throughout the repo,
tests, docs, and Dart comments, since the fix touches that file anyway.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qH2hJ6mvCJd3ZXpAJSaF7
117 lines
3.3 KiB
Python
117 lines
3.3 KiB
Python
"""Tests for post-sick-day workout verification (--verify-workout)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock
|
|
|
|
from screen_locker.tests.conftest import create_locker
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
class TestHandleVerifyWorkoutResult:
|
|
"""Tests for _handle_verify_workout_result."""
|
|
|
|
def test_verified_adjusts_shutdown_and_saves(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""On verified: adjust shutdown, save log, show success."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
locker.log_file = tmp_path / "log.json"
|
|
object.__setattr__(
|
|
locker,
|
|
"_adjust_shutdown_time_later",
|
|
MagicMock(return_value=True),
|
|
)
|
|
|
|
locker._handle_verify_workout_result("verified", "1 session found")
|
|
|
|
assert locker.workout_data["type"] == "phone_verified"
|
|
assert locker.workout_data["after_sick_day"] == "true"
|
|
locker._adjust_shutdown_time_later.assert_called_once()
|
|
locker.root.after.assert_called()
|
|
|
|
def test_verified_without_adjustment(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""On verified but adjustment fails: still saves and shows success."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
locker.log_file = tmp_path / "log.json"
|
|
object.__setattr__(
|
|
locker,
|
|
"_adjust_shutdown_time_later",
|
|
MagicMock(return_value=False),
|
|
)
|
|
|
|
locker._handle_verify_workout_result("verified", "1 session found")
|
|
|
|
assert locker.workout_data["type"] == "phone_verified"
|
|
locker.root.after.assert_called()
|
|
|
|
def test_not_verified_shows_retry(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""On not_verified: show retry screen."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
object.__setattr__(
|
|
locker,
|
|
"_show_verify_retry",
|
|
MagicMock(),
|
|
)
|
|
|
|
locker._handle_verify_workout_result(
|
|
"not_verified",
|
|
"No workout today",
|
|
)
|
|
|
|
locker._show_verify_retry.assert_called_once_with(
|
|
"No workout today",
|
|
)
|
|
|
|
def test_error_shows_retry(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""On error: show retry screen."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
object.__setattr__(
|
|
locker,
|
|
"_show_verify_retry",
|
|
MagicMock(),
|
|
)
|
|
|
|
locker._handle_verify_workout_result("error", "ADB failed")
|
|
|
|
locker._show_verify_retry.assert_called_once_with("ADB failed")
|
|
|
|
|
|
class TestShowVerifyRetry:
|
|
"""Tests for _show_verify_retry."""
|
|
|
|
def test_shows_retry_and_close_buttons(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Show TRY AGAIN and Close buttons."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
|
|
locker._show_verify_retry("No workout found")
|
|
|
|
# Verify container was cleared and buttons were packed
|
|
locker.container.first.winfo_children.return_value = []
|