Files
shirobana-bot/tests/test_mode_config.py
RRRosmontis 34089d0042 Initial import of Shirobana bot backend
Include utility modules, shared channels, prompts, read-only skills, wardrobe memory and regression tests. Externalize legacy credentials and exclude private runtime state.
2026-11-11 00:25:30 +08:00

29 lines
1.1 KiB
Python

import json
import tempfile
import unittest
from pathlib import Path
from unittest.mock import mock_open, patch
import identity
from agent.modes import ModeStore
class ModeConfigTest(unittest.TestCase):
def test_admin_chat_other_command_and_saved_override(self):
with tempfile.TemporaryDirectory() as tmp:
store = ModeStore(Path(tmp) / "modes.db")
config = json.dumps({"chat_mode": {"default": "command", "admin": "chat", "group": "command"}})
with patch("pathlib.Path.open", mock_open(read_data=config)), \
patch.object(identity, "is_admin", side_effect=lambda uid: uid == 1):
self.assertEqual(store.get_mode("tg", 1), "chat")
self.assertEqual(store.get_mode("tg", 2), "command")
self.assertEqual(store.get_mode("tg", 1, 123), "command")
store.set_mode("tg", 2, "chat")
self.assertEqual(store.get_mode("tg", 2), "chat")
store.set_mode("tg", 1, "command")
self.assertEqual(store.get_mode("tg", 1), "command")
if __name__ == "__main__":
unittest.main()