tests: Add comprehensive test suite for Telegram handlers - #718
tests: Add comprehensive test suite for Telegram handlers#718ImMohammad20000 wants to merge 8 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe PR adds shared Telegram test fakes and broad async coverage for admin, client, base, and error handlers. It also improves test database isolation across SQLite, PostgreSQL, and MySQL and removes stale local SQLite artifacts before migrations. ChangesTelegram fixtures and local database cleanup
Bulk admin action flows
Admin menu and user handlers
Client, base, and error handlers
Cross-database test isolation
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/telegram/handlers/test_error_handler.py (1)
16-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the cleanup and alert contracts, not only that calls occurred.
The message-path test does not verify old messages are deleted or state is cleared; the callback-path test would pass without
show_alert=Trueor the required...truncation suffix.Proposed assertions
async def test_handle_exception_value_error_message_path(monkeypatch, fake_state, fake_message): state = fake_state + state._state = "busy" state._data = {"messages_to_delete": [1, 2]} ... await error_handler.handle_exception(event, state) msg.answer.assert_awaited_once() + msg.bot.delete_messages.assert_awaited_once_with(msg.chat.id, [1, 2]) + assert await state.get_state() is None + assert await state.get_value("messages_to_delete") == [msg.message_id + 1] ... callback.answer.assert_awaited_once() sent_text = callback.answer.await_args.args[0] assert len(sent_text) == 200 + assert sent_text.endswith("...") + assert callback.answer.await_args.kwargs == {"show_alert": True}Also applies to: 33-37
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/telegram/handlers/test_error_handler.py` around lines 16 - 18, Strengthen the error-handler tests around handle_exception in both message and callback paths: assert that prior messages are deleted, state is cleared, and the user notification uses show_alert=True with the required “...” truncation suffix. Verify the exact cleanup and alert arguments rather than only checking that answer was awaited.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/api/__init__.py`:
- Around line 105-112: Update the database cleanup block in the test setup to
run only for SQLite URLs, parse the configured database path from DATABASE_URL,
and remove that exact database file plus its -shm and -wal sidecars. Stop
checking or deleting hardcoded CWD paths such as test.db, while preserving the
existing best-effort cleanup behavior.
---
Nitpick comments:
In `@tests/telegram/handlers/test_error_handler.py`:
- Around line 16-18: Strengthen the error-handler tests around handle_exception
in both message and callback paths: assert that prior messages are deleted,
state is cleared, and the user notification uses show_alert=True with the
required “...” truncation suffix. Verify the exact cleanup and alert arguments
rather than only checking that answer was awaited.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3d75c352-6714-4b6b-86e7-d4c2e7178ed5
📒 Files selected for processing (10)
tests/api/__init__.pytests/telegram/conftest.pytests/telegram/handlers/admin/test_bulk_actions.pytests/telegram/handlers/admin/test_confirm_action.pytests/telegram/handlers/admin/test_main_menu.pytests/telegram/handlers/admin/test_user.pytests/telegram/handlers/client/test_show_info.pytests/telegram/handlers/test_base.pytests/telegram/handlers/test_error_handler.pytests/test_record_usages.py
Summary
Type of change
Checklist
I tested the change locally or explained why it cannot be tested.
I added or updated tests for behavior changes.
I did not include secrets, tokens, private keys, or unrelated changes.
I updated documentation, translations, or examples if needed.
I checked database migrations when models or schema changed.
Summary by CodeRabbit