LichessStatTgWeb/tests/bot/test_wiring.py
vrubelroman 6351e18795 admin bot: /status redesigned around health, growth and activity; raw counters moved to /counters
- /status: verdict line (✅/⚠️, UTC time), 🩺 health (errors today/yesterday,
  Lichess 429 per 24 h from /health, age of the last player-status refresh,
  closed/not-found players, users who blocked the bot in 7 days), 📈 growth
  table (users/gamers/subscriptions: total, +today, +yesterday, +7 days,
  users without gamers), ⚡ activity today vs yesterday (commands, active
  users, notifications, Lichess requests). Flags: errors >= 10, any 429,
  status older than 30 min, no SUMMARY for yesterday, journal missing.
  Blocks fail independently (only a DB failure breaks the whole message).
- /counters: all raw command counters sorted by total + last SUMMARY as is.
- Database.get_admin_overview replaces get_admin_stats.
- events.summarize_days (one pass over events.log.1 + events.log, extra
  keys active_users/blocked/status_refresh_failed/cmd_by_name/lines),
  last_summary(); last_summary_line reads the rotated backup too.
- LichessAPI.get_service_health(timeout).
- Designer spec in docs/design/admin_status.md; README, CURRENT_STATE,
  CHANGELOG (Unreleased) updated; 25 new tests (61 bot tests total).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 06:16:53 +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: 26}, 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()