c1693d7dcc
tests/gateway/conftest.py already installs a comprehensive telegram mock at collection time (line 330), before any test module's imports run. The per-file copies were fully redundant — each was a simpler subset (plain strings, setdefault, fewer error classes) of the conftest version (which uses _fake_str_enum for PTB-faithful StrEnum semantics, sys.modules overwrite to win over partial/broken imports, and a full error hierarchy including BadRequest, Forbidden, RetryAfter, Conflict, InvalidToken). Removed: function def + module-level call + now-unused imports (sys, MagicMock where no longer referenced) + dangling comment blocks that referenced the deleted mock, in 27 test files. Left untouched: tests/gateway/conftest.py (canonical source) and tests/e2e/conftest.py (separate conftest tree that may run in isolation). Found by /simplify-code review of PR #90560.
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
"""Tests for Telegram connect() non-retryable fatal error on missing credentials.
|
|
|
|
When Telegram has no bot token or no python-telegram-bot installed, connect()
|
|
must set a non-retryable fatal error so the gateway does not queue it for
|
|
background reconnection (#31049).
|
|
"""
|
|
|
|
|
|
import pytest
|
|
|
|
from gateway.config import PlatformConfig
|
|
import plugins.platforms.telegram.adapter as telegram_mod # noqa: E402
|
|
from plugins.platforms.telegram.adapter import TelegramAdapter # noqa: E402
|
|
|
|
|
|
class TestTelegramUnconfiguredNonRetryable:
|
|
"""Verify that missing dependency/token sets a non-retryable fatal error."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_no_telegram_lib_sets_non_retryable_fatal(self, monkeypatch):
|
|
"""connect() with python-telegram-bot unavailable → non-retryable fatal error."""
|
|
adapter = TelegramAdapter(PlatformConfig(enabled=True, token="fake"))
|
|
monkeypatch.setattr(telegram_mod, "TELEGRAM_AVAILABLE", False)
|
|
result = await adapter.connect()
|
|
assert result is False
|
|
assert adapter.has_fatal_error is True
|
|
assert adapter.fatal_error_retryable is False
|
|
assert adapter.fatal_error_code == "missing_dependency"
|
|
|