init
This commit is contained in:
121 files changed
+17641
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""Blocking policy: when it is on, and what is on the list."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.services import blocker_service, pomodoro, settings_service
|
||||
|
||||
|
||||
def test_disabled_blocker_blocks_nothing(session, settings):
|
||||
pomodoro.start(session, settings, kind="work")
|
||||
policy = blocker_service.policy(session, settings)
|
||||
assert policy["active"] is False and policy["domains"] == []
|
||||
|
||||
|
||||
def test_during_work_mode_follows_the_timer(session, settings):
|
||||
settings.blocker.enabled = True
|
||||
settings.blocker.blocked_domains = ["youtube.com"]
|
||||
settings_service.save_settings(session, settings)
|
||||
|
||||
assert blocker_service.policy(session, settings)["active"] is False
|
||||
|
||||
pomodoro.start(session, settings, kind="work")
|
||||
policy = blocker_service.policy(session, settings)
|
||||
assert policy["active"] is True
|
||||
assert "www.youtube.com" in policy["domains"]
|
||||
|
||||
pomodoro.complete(session, settings, auto_next=False)
|
||||
assert blocker_service.policy(session, settings)["active"] is False
|
||||
|
||||
|
||||
def test_breaks_do_not_block_unless_asked(session, settings):
|
||||
settings.blocker.enabled = True
|
||||
settings_service.save_settings(session, settings)
|
||||
pomodoro.start(session, settings, kind="short_break")
|
||||
assert blocker_service.policy(session, settings)["active"] is False
|
||||
|
||||
settings.blocker.block_during_breaks = True
|
||||
settings_service.save_settings(session, settings)
|
||||
assert blocker_service.policy(session, settings)["active"] is True
|
||||
|
||||
|
||||
def test_always_mode_ignores_the_timer(session, settings):
|
||||
settings.blocker.enabled = True
|
||||
settings.blocker.mode = "always"
|
||||
settings_service.save_settings(session, settings)
|
||||
assert blocker_service.policy(session, settings)["active"] is True
|
||||
|
||||
|
||||
def test_allowlist_wins_over_the_blocklist(session, settings):
|
||||
settings.blocker.blocked_domains = ["youtube.com"]
|
||||
settings.blocker.allowed_domains = ["m.youtube.com"]
|
||||
hosts = blocker_service.expand_domains(settings)
|
||||
assert "youtube.com" in hosts
|
||||
assert "m.youtube.com" not in hosts
|
||||
|
||||
|
||||
def test_events_are_grouped_for_the_report(session, settings):
|
||||
for _ in range(3):
|
||||
blocker_service.record_event(session, settings, kind="domain", target="YouTube.com")
|
||||
blocker_service.record_event(session, settings, kind="app", target="steam")
|
||||
summary = blocker_service.events_for_day(session, settings)
|
||||
assert summary["total"] == 4
|
||||
assert summary["by_target"][0] == {"target": "youtube.com", "count": 3}
|
||||
Reference in new issue
Block a user