72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
"""The Telegram commands — the chat is a remote control, so it needs testing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.services import settings_service, tasks_service, telegram_bot
|
|
|
|
|
|
def test_unknown_input_is_ignored(session):
|
|
assert telegram_bot.handle_text("hello there") is None
|
|
assert telegram_bot.handle_text("/nonsense") is None
|
|
|
|
|
|
def test_help_lists_the_verbs(session):
|
|
reply = telegram_bot.handle_text("/help")
|
|
assert "/start_work" in reply and "/report" in reply
|
|
|
|
|
|
def test_start_pause_resume_and_status(session):
|
|
assert "started" in telegram_bot.handle_text("/start_work 10").lower()
|
|
status = telegram_bot.handle_text("/status")
|
|
assert "work" in status.lower() or "focus" in status.lower()
|
|
assert "Paused" in telegram_bot.handle_text("/pause")
|
|
assert "Resumed" in telegram_bot.handle_text("/resume")
|
|
assert "Stopped" in telegram_bot.handle_text("/stop")
|
|
|
|
|
|
def test_stop_without_a_timer_explains_itself(session):
|
|
assert "No interval is running" in telegram_bot.handle_text("/stop")
|
|
|
|
|
|
def test_today_numbers_tasks_and_done_closes_them(session):
|
|
settings_service.load_settings(session)
|
|
first = tasks_service.create_local_task(session, title="Alpha task")
|
|
tasks_service.create_local_task(session, title="Beta task")
|
|
|
|
listing = telegram_bot.handle_text("/today")
|
|
assert "Alpha task" in listing and "<b>1.</b>" in listing
|
|
|
|
reply = telegram_bot.handle_text("/done 1")
|
|
assert "Alpha task" in reply
|
|
session.expire_all()
|
|
assert session.get(type(first), first.id).is_done is True
|
|
|
|
assert "No task with that number" in telegram_bot.handle_text("/done 99")
|
|
|
|
|
|
def test_done_without_a_listing_asks_for_one(session):
|
|
telegram_bot._INDEX.clear()
|
|
assert "/today" in telegram_bot.handle_text("/done 1")
|
|
|
|
|
|
def test_report_and_streak_render(session):
|
|
assert "Daily report" in telegram_bot.handle_text("/report")
|
|
assert "Streak" in telegram_bot.handle_text("/streak")
|
|
assert "Weekly review" in telegram_bot.handle_text("/week")
|
|
|
|
|
|
def test_block_command_describes_the_policy(session):
|
|
settings = settings_service.load_settings(session)
|
|
settings.blocker.enabled = True
|
|
settings.blocker.blocked_domains = ["youtube.com"]
|
|
settings_service.save_settings(session, settings)
|
|
reply = telegram_bot.handle_text("/block")
|
|
assert "Blocker" in reply and "Domains" in reply
|
|
|
|
|
|
def test_russian_replies_when_configured(session):
|
|
settings = settings_service.load_settings(session)
|
|
settings.notifications.report.language = "ru"
|
|
settings_service.save_settings(session, settings)
|
|
assert "помидорку" in telegram_bot.handle_text("/help")
|