"""Runtime sticker disable switch tests; no real Telegram delivery.""" from pathlib import Path import sys import tempfile import unittest from unittest.mock import AsyncMock, patch BASE = Path(__file__).resolve().parents[1] sys.path[:0] = [str(BASE / "bot-utility"), str(BASE)] from chat import engine class StickerSwitchTests(unittest.IsolatedAsyncioTestCase): def test_disabled_hides_tags_from_model(self): with patch.object(engine, "load_setting", return_value={"stickers": False}), \ patch.object(engine.os, "listdir") as listdir: self.assertEqual(engine.available_sticker_tags(), []) listdir.assert_not_called() def test_enabled_still_loads_existing_tags(self): with tempfile.TemporaryDirectory() as directory: Path(directory, "happy.webp").write_bytes(b"sticker") with patch.object(engine, "load_setting", return_value={"stickers": True}), \ patch.object(engine, "STICKERS_DIR", directory): self.assertEqual(engine.available_sticker_tags(), ["happy"]) async def test_disabled_blocks_direct_send_even_with_tag(self): bot = type("Bot", (), {"send_sticker": AsyncMock()})() channel = type("Channel", (), {"bot": bot})() with patch.object(engine, "load_setting", return_value={"stickers": False}), \ patch.object(engine, "_resolve_delivery") as resolve: await engine._maybe_send_sticker(channel, 1, "happy") resolve.assert_not_called() bot.send_sticker.assert_not_awaited() if __name__ == "__main__": unittest.main()