Debian Codegraph @

tests/backend_tests/text_test.py

raw
1 import logging
2 import os
3 import sys
4 from tempfile import mkdtemp
5
6 import pytest
7
8 from errbot.backends.text import TextBackend
9 from errbot.bootstrap import bot_config_defaults
10
11
12 @pytest.fixture
13 def text_backend():
14 tempdir = mkdtemp()
15
16 # reset the config every time
17 sys.modules.pop("errbot.config-template", None)
18 __import__("errbot.config-template")
19 config = sys.modules["errbot.config-template"]
20 bot_config_defaults(config)
21 config.BOT_DATA_DIR = tempdir
22 config.BOT_LOG_FILE = os.path.join(tempdir, "log.txt")
23 config.BOT_EXTRA_PLUGIN_DIR = []
24 config.BOT_LOG_LEVEL = logging.DEBUG
25 config.BOT_PREFIX = "!"
26 config.BOT_IDENTITY["username"] = "@testme"
27 config.BOT_ADMINS = ["@test_admin"]
28
29 return TextBackend(config)
30
31
32 def test_change_presence(text_backend, caplog):
33 with caplog.at_level(logging.DEBUG):
34 text_backend.change_presence("online", "I'm online")
35 assert len(caplog.messages) == 1
36 a_message = caplog.messages[0]
37 assert a_message.startswith("*** Changed presence")