test: add channel filter and JSON log tests
TestChannelFilter: allowed/denied/PM/no-config/core-exempt/ampersand. TestChannelConfig: TOML loading, defaults. TestJsonFormatter: fields, exception, unicode, single-line, timestamp format.
This commit is contained in:
@@ -625,6 +625,58 @@ class TestBotAPI:
|
||||
assert bot.conn.sent == ["TOPIC #ch :new topic"]
|
||||
|
||||
|
||||
class TestChannelFilter:
|
||||
"""Test per-channel plugin allow/deny."""
|
||||
|
||||
@staticmethod
|
||||
def _make_bot(channels_cfg: dict | None = None) -> Bot:
|
||||
"""Create a Bot with optional per-channel config."""
|
||||
config = {
|
||||
"server": {"host": "localhost", "port": 6667, "tls": False,
|
||||
"nick": "test", "user": "test", "realname": "test"},
|
||||
"bot": {"prefix": "!", "channels": [], "plugins_dir": "plugins"},
|
||||
"channels": channels_cfg or {},
|
||||
}
|
||||
return Bot(config, PluginRegistry())
|
||||
|
||||
def test_core_always_allowed(self):
|
||||
bot = self._make_bot({"#locked": {"plugins": ["core"]}})
|
||||
assert bot._plugin_allowed("core", "#locked") is True
|
||||
|
||||
def test_listed_plugin_allowed(self):
|
||||
bot = self._make_bot({"#ops": {"plugins": ["core", "dns"]}})
|
||||
assert bot._plugin_allowed("dns", "#ops") is True
|
||||
|
||||
def test_unlisted_plugin_denied(self):
|
||||
bot = self._make_bot({"#ops": {"plugins": ["core", "dns"]}})
|
||||
assert bot._plugin_allowed("encode", "#ops") is False
|
||||
|
||||
def test_unconfigured_channel_allows_all(self):
|
||||
bot = self._make_bot({"#locked": {"plugins": ["core"]}})
|
||||
assert bot._plugin_allowed("encode", "#open") is True
|
||||
|
||||
def test_no_channels_config_allows_all(self):
|
||||
bot = self._make_bot()
|
||||
assert bot._plugin_allowed("anything", "#test") is True
|
||||
|
||||
def test_pm_always_allowed(self):
|
||||
bot = self._make_bot({"#locked": {"plugins": ["core"]}})
|
||||
assert bot._plugin_allowed("encode", "someone") is True
|
||||
|
||||
def test_none_channel_allowed(self):
|
||||
bot = self._make_bot({"#locked": {"plugins": ["core"]}})
|
||||
assert bot._plugin_allowed("encode", None) is True
|
||||
|
||||
def test_channel_without_plugins_key(self):
|
||||
bot = self._make_bot({"#other": {"some_setting": True}})
|
||||
assert bot._plugin_allowed("encode", "#other") is True
|
||||
|
||||
def test_ampersand_channel(self):
|
||||
bot = self._make_bot({"&local": {"plugins": ["core", "dns"]}})
|
||||
assert bot._plugin_allowed("dns", "&local") is True
|
||||
assert bot._plugin_allowed("encode", "&local") is False
|
||||
|
||||
|
||||
class TestSplitUtf8:
|
||||
"""Test UTF-8 safe message splitting."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user