LichessStatTgWeb/tests/bot/test_wiring.py
vrubelroman 533c0a7694 onboarding phase 1: one-screen /start, any text is a player name, URL/@ normalisation, next-step texts, /addtoken trap closed
Analysis: docs/analysis/onboarding_funnel.md (56% of users never add a player;
drop happens on the first screen; non-ru/en users convert at 25%).
Design: docs/design/onboarding.md.

- /start: one message. New user: promise + "send a Lichess username, e.g.
  DrNykterstein" with [❓ Где взять имя] / [🇬🇧 English] (language switch edits
  the message in place). Returning user: their players + /today /addgamer /help.
- /addgamer asks for the name directly (the two-button menu from 2025-12-03 is gone).
- Any non-command text in a private chat is a player-name attempt: no awaiting
  flag, PicklePersistence removed. onboarding.normalise_username accepts
  lichess.org URLs, @name, quotes, "add Name"; chess.com and non-name text get
  their own hints; nothing is sent to Lichess for them.
- Every reply ends with the next step (success: hourly report is on, /today,
  send another name). One no_players empty state for /today, /week, /getgamers,
  /delgamer, /setperiod, /profile, /year.
- /help: 18 lines in three groups; /year and /lang aliases; command menu set
  from code for en (default) and ru at startup (set_my_commands).
- /addtoken trap: non-lip_ text gets a hint instead of "invalid token"; any
  other command inside the conversation ends it and runs; /cancel outside a
  conversation answers "nothing to cancel".
- All echoed input html-escaped. Terminology unified: игрок / имя на Lichess /
  отчёт (player / Lichess username / report).
- events: user_start screen=, addgamer_input kind= normalised=, addgamer_result
  format|chesscom, lang_set via=, addtoken_result not_a_token; text in_flow= gone.
- i18n: 18 dead keys removed, 21 added; docs (README, USER_GUIDE, about,
  CURRENT_STATE, CHANGELOG Unreleased) updated; 107 bot tests (was 61).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 07:36:31 +00:00

33 lines
1.1 KiB
Python

"""Handler wiring of both bots against the real python-telegram-bot: the handler counts per group."""
from tests.bot import _env # noqa: F401 (environment before bot imports)
import unittest
from telegram.ext import Application
from bot import LichessBot
from admin_bot import AdminBot
DUMMY_TOKEN = "123456:ABCDEF"
def handler_groups(application: Application) -> dict:
return {group: len(handlers) for group, handlers in application.handlers.items()}
class WiringTests(unittest.TestCase):
def test_user_bot_handlers(self):
application = Application.builder().token(DUMMY_TOKEN).build()
bot = LichessBot()
bot.setup_handlers(application)
self.assertEqual({-1: 1, 0: 27}, handler_groups(application))
self.assertIs(application, bot.monitor.application)
def test_admin_bot_handlers(self):
application = Application.builder().token(DUMMY_TOKEN).build()
AdminBot().setup_handlers(application)
self.assertEqual({0: 7}, handler_groups(application)) # 2 conversations + start, status, counters, events, events_file
if __name__ == '__main__':
unittest.main()