Commit 14b08620 authored by Guillaume Binet's avatar Guillaume Binet

bot_config and test fixes

parent b3246675
......@@ -78,7 +78,7 @@ a *payload* parameter::
class Github(BotPlugin):
@webhook(r'/github/', form_param = 'payload')
def notification(self, payload):
for room in self.bot_configuration.CHATROOM_PRESENCE:
for room in self.bot_config.CHATROOM_PRESENCE:
self.send(
room,
'Commit on %s!' % payload['repository']['name'],
......
......@@ -709,7 +709,7 @@ class Backend(object):
# but in case of a groupchat, we should only try to send to the MUC address
# itself (bot@conference.domain.tld)
response.to = mess.frm.stripped.split('/')[0]
elif str(mess.to) == self.main_config.BOT_IDENTITY['username']:
elif str(mess.to) == self.bot_config.BOT_IDENTITY['username']:
# This is a direct private message, not initiated through a MUC. Use
# stripped to remove the resource so that the response goes to the
# client with the highest priority
......@@ -772,7 +772,7 @@ class Backend(object):
# correct in all cases because a MUC could give us another nickname, but it
# covers 99% of the MUC cases, so it should suffice for the time being.
if (jid.bare_match(self.jid) or
type_ == "groupchat" and mess.nick == self.main_config.CHATROOM_FN): # noqa
type_ == "groupchat" and mess.nick == self.bot_config.CHATROOM_FN): # noqa
logging.debug("Ignoring message from self")
return False
......@@ -790,8 +790,8 @@ class Backend(object):
prefixed = False # Keeps track whether text was prefixed with a bot prefix
only_check_re_command = False # Becomes true if text is determed to not be a regular command
tomatch = text.lower() if self.main_config.BOT_ALT_PREFIX_CASEINSENSITIVE else text
if len(self.main_config.BOT_ALT_PREFIXES) > 0 and tomatch.startswith(self.bot_alt_prefixes):
tomatch = text.lower() if self.bot_config.BOT_ALT_PREFIX_CASEINSENSITIVE else text
if len(self.bot_config.BOT_ALT_PREFIXES) > 0 and tomatch.startswith(self.bot_alt_prefixes):
# Yay! We were called by one of our alternate prefixes. Now we just have to find out
# which one... (And find the longest matching, in case you have 'err' and 'errbot' and
# someone uses 'errbot', which also matches 'err' but would leave 'bot' to be taken as
......@@ -806,22 +806,22 @@ class Backend(object):
text = text[longest:]
# Now also remove the separator from the text
for sep in self.main_config.BOT_ALT_PREFIX_SEPARATORS:
for sep in self.bot_config.BOT_ALT_PREFIX_SEPARATORS:
# While unlikely, one may have separators consisting of
# more than one character
l = len(sep)
if text[:l] == sep:
text = text[l:]
elif type_ == "chat" and self.main_config.BOT_PREFIX_OPTIONAL_ON_CHAT:
elif type_ == "chat" and self.bot_config.BOT_PREFIX_OPTIONAL_ON_CHAT:
logging.debug("Assuming '%s' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True" % text)
# In order to keep noise down we surpress messages about the command
# not being found, because it's possible a plugin will trigger on what
# was said with trigger_message.
surpress_cmd_not_found = True
elif not text.startswith(self.main_config.BOT_PREFIX):
elif not text.startswith(self.bot_config.BOT_PREFIX):
only_check_re_command = True
if text.startswith(self.main_config.BOT_PREFIX):
text = text[len(self.main_config.BOT_PREFIX):]
if text.startswith(self.bot_config.BOT_PREFIX):
text = text[len(self.bot_config.BOT_PREFIX):]
prefixed = True
text = text.strip()
......@@ -844,7 +844,7 @@ class Backend(object):
if len(text_split) > 1:
args = ' '.join(text_split[1:])
if command == self.main_config.BOT_PREFIX: # we did "!!" so recall the last command
if command == self.bot_config.BOT_PREFIX: # we did "!!" so recall the last command
if len(user_cmd_history):
cmd, args = user_cmd_history[-1]
else:
......@@ -909,13 +909,13 @@ class Backend(object):
try:
self.check_command_access(mess, cmd)
except ACLViolation as e:
if not self.main_config.HIDE_RESTRICTED_ACCESS:
if not self.bot_config.HIDE_RESTRICTED_ACCESS:
self.send_simple_reply(mess, str(e))
return
f = self.re_commands[cmd] if match else self.commands[cmd]
if f._err_command_admin_only and self.main_config.BOT_ASYNC:
if f._err_command_admin_only and self.bot_config.BOT_ASYNC:
# If it is an admin command, wait until the queue is completely depleted so
# we don't have strange concurrency issues on load/unload/updates etc...
self.thread_pool.wait()
......@@ -940,7 +940,7 @@ class Backend(object):
)
return
if self.main_config.BOT_ASYNC:
if self.bot_config.BOT_ASYNC:
wr = WorkRequest(
self._execute_and_send,
[],
......@@ -978,8 +978,8 @@ class Backend(object):
return str(reply_)
def send_reply(reply_):
for part in split_string_after(reply_, self.main_config.MESSAGE_SIZE_LIMIT):
self.send_simple_reply(mess, part, cmd in self.main_config.DIVERT_TO_PRIVATE)
for part in split_string_after(reply_, self.bot_config.MESSAGE_SIZE_LIMIT):
self.send_simple_reply(mess, part, cmd in self.bot_config.DIVERT_TO_PRIVATE)
commands = self.re_commands if match else self.commands
try:
......@@ -1003,7 +1003,7 @@ class Backend(object):
"""
an overridable check to see if a user is an administrator
"""
return usr in self.main_config.BOT_ADMINS
return usr in self.bot_config.BOT_ADMINS
def check_command_access(self, mess, cmd):
"""
......@@ -1014,23 +1014,23 @@ class Backend(object):
usr = str(get_jid_from_message(mess))
typ = mess.type
if cmd not in self.main_config.ACCESS_CONTROLS:
self.main_config.ACCESS_CONTROLS[cmd] = self.main_config.ACCESS_CONTROLS_DEFAULT
if cmd not in self.bot_config.ACCESS_CONTROLS:
self.bot_config.ACCESS_CONTROLS[cmd] = self.bot_config.ACCESS_CONTROLS_DEFAULT
if 'allowusers' in self.main_config.ACCESS_CONTROLS[cmd] and usr not in self.main_config.ACCESS_CONTROLS[cmd]['allowusers']:
if 'allowusers' in self.bot_config.ACCESS_CONTROLS[cmd] and usr not in self.bot_config.ACCESS_CONTROLS[cmd]['allowusers']:
raise ACLViolation("You're not allowed to access this command from this user")
if 'denyusers' in self.main_config.ACCESS_CONTROLS[cmd] and usr in self.main_config.ACCESS_CONTROLS[cmd]['denyusers']:
if 'denyusers' in self.bot_config.ACCESS_CONTROLS[cmd] and usr in self.bot_config.ACCESS_CONTROLS[cmd]['denyusers']:
raise ACLViolation("You're not allowed to access this command from this user")
if typ == 'groupchat':
stripped = mess.frm.stripped
if 'allowmuc' in self.main_config.ACCESS_CONTROLS[cmd] and self.main_config.ACCESS_CONTROLS[cmd]['allowmuc'] is False:
if 'allowmuc' in self.bot_config.ACCESS_CONTROLS[cmd] and self.bot_config.ACCESS_CONTROLS[cmd]['allowmuc'] is False:
raise ACLViolation("You're not allowed to access this command from a chatroom")
if 'allowrooms' in self.main_config.ACCESS_CONTROLS[cmd] and stripped not in self.main_config.ACCESS_CONTROLS[cmd]['allowrooms']:
if 'allowrooms' in self.bot_config.ACCESS_CONTROLS[cmd] and stripped not in self.bot_config.ACCESS_CONTROLS[cmd]['allowrooms']:
raise ACLViolation("You're not allowed to access this command from this room")
if 'denyrooms' in self.main_config.ACCESS_CONTROLS[cmd] and stripped in self.main_config.ACCESS_CONTROLS[cmd]['denyrooms']:
if 'denyrooms' in self.bot_config.ACCESS_CONTROLS[cmd] and stripped in self.bot_config.ACCESS_CONTROLS[cmd]['denyrooms']:
raise ACLViolation("You're not allowed to access this command from this room")
else:
if 'allowprivate' in self.main_config.ACCESS_CONTROLS[cmd] and self.main_config.ACCESS_CONTROLS[cmd]['allowprivate'] is False:
if 'allowprivate' in self.bot_config.ACCESS_CONTROLS[cmd] and self.bot_config.ACCESS_CONTROLS[cmd]['allowprivate'] is False:
raise ACLViolation("You're not allowed to access this command via private message to me")
f = self.commands[cmd] if cmd in self.commands else self.re_commands[cmd]
......@@ -1055,7 +1055,7 @@ class Backend(object):
matches.extend(difflib.get_close_matches(full_cmd, ununderscore_keys))
matches = set(matches)
if matches:
return part1 + '\n\nDid you mean "' + self.main_config.BOT_PREFIX + ('" or "' + self.main_config.BOT_PREFIX).join(matches) + '" ?'
return part1 + '\n\nDid you mean "' + self.bot_config.BOT_PREFIX + ('" or "' + self.bot_config.BOT_PREFIX).join(matches) + '" ?'
else:
return part1
......@@ -1091,7 +1091,7 @@ class Backend(object):
del (self.commands[name])
def warn_admins(self, warning):
for admin in self.main_config.BOT_ADMINS:
for admin in self.bot_config.BOT_ADMINS:
self.send(admin, warning)
def top_of_help_message(self):
......@@ -1124,7 +1124,7 @@ class Backend(object):
description = 'Available commands:'
usage = '\n'.join(sorted([
self.main_config.BOT_PREFIX + '%s: %s' % (name, (command.__doc__ or
self.bot_config.BOT_PREFIX + '%s: %s' % (name, (command.__doc__ or
'(undocumented)').strip().split('\n', 1)[0])
for (name, command) in self.commands.items()
if name != 'help'
......
......@@ -212,7 +212,7 @@ class GraphicBackend(ErrBot):
def send_command(self, text):
self.app.new_message(text, False)
msg = Message(text)
msg.frm = self.main_config.BOT_ADMINS[0] # assume this is the admin talking
msg.frm = self.bot_config.BOT_ADMINS[0] # assume this is the admin talking
msg.to = self.jid # To me only
self.callback_message(msg)
self.app.input.clear()
......@@ -228,7 +228,7 @@ class GraphicBackend(ErrBot):
self.connect_callback() # notify that the connection occured
# create window and components
self.app = ChatApplication(sys.argv, backend=self, config=self.main_config)
self.app = ChatApplication(sys.argv, backend=self, config=self.bot_config)
try:
self.app.exec_()
finally:
......
......@@ -17,7 +17,7 @@ class TextBackend(ErrBot):
self.jid = Identifier('Err')
def serve_forever(self):
me = Identifier(self.main_config.BOT_ADMINS[0])
me = Identifier(self.bot_config.BOT_ADMINS[0])
self.connect_callback() # notify that the connection occured
self.callback_presence(Presence(identifier=me, status=ONLINE))
try:
......
......@@ -60,7 +60,7 @@ class ToxConnection(Tox):
self.backend = backend
self.incoming_streams = {}
self.outgoing_streams = {}
state_file = join(backend.main_config.BOT_DATA_DIR, 'tox.state')
state_file = join(backend.bot_config.BOT_DATA_DIR, 'tox.state')
if exists(state_file):
self.load_from_file(state_file)
self.set_name(name)
......@@ -337,7 +337,7 @@ class ToxBackend(ErrBot):
def is_admin(self, friend_number):
pk = self.conn.get_client_id(int(friend_number))
logging.debug("Check if %s is admin" % pk)
return any(pka.startswith(pk) for pka in self.main_config.BOT_ADMINS)
return any(pka.startswith(pk) for pka in self.bot_config.BOT_ADMINS)
def send_message(self, mess):
super(ToxBackend, self).send_message(mess)
......@@ -379,7 +379,7 @@ class ToxBackend(ErrBot):
if checked and not status:
logging.info('TOX: Disconnected from DHT.')
self.conn.connect(self.main_config.TOX_BOOTSTRAP_SERVER)
self.conn.connect(self.bot_config.TOX_BOOTSTRAP_SERVER)
checked = False
self.conn.do()
......@@ -387,7 +387,7 @@ class ToxBackend(ErrBot):
except KeyboardInterrupt:
pass
finally:
self.conn.save_to_file(TOX_STATEFILE)
self.conn.save_to_file(self.bot_config.TOX_STATEFILE)
self.disconnect_callback()
self.shutdown()
......
......@@ -33,8 +33,8 @@ class BotPluginBase(StoreMixin):
return holder.bot.mode
@property
def bot_configuration(self):
return holder.bot.main_config
def bot_config(self):
return holder.bot.bot_config
def activate(self):
"""
......@@ -43,7 +43,7 @@ class BotPluginBase(StoreMixin):
"""
classname = self.__class__.__name__
logging.debug('Init storage for %s' % classname)
filename = os.path.join(self.bot_configuration.BOT_DATA_DIR, PLUGINS_SUBDIR, classname + '.db')
filename = os.path.join(self.bot_config.BOT_DATA_DIR, PLUGINS_SUBDIR, classname + '.db')
logging.debug('Loading %s' % filename)
self.open_storage(filename)
holder.bot.inject_commands_from(self)
......
......@@ -25,14 +25,14 @@ class ChatRoom(BotPlugin):
logging.info('Callback_connect')
if not self.connected:
self.connected = True
for room in self.bot_configuration.CHATROOM_PRESENCE:
for room in self.bot_config.CHATROOM_PRESENCE:
if isinstance(room, basestring):
room, username, password = (room, self.bot_configuration.CHATROOM_FN, None)
room, username, password = (room, self.bot_config.CHATROOM_FN, None)
else:
room, username, password = (room[0], self.bot_configuration.CHATROOM_FN, room[1])
room, username, password = (room[0], self.bot_config.CHATROOM_FN, room[1])
logging.info("Joining room {} with username {}".format(room, username))
try:
self.query_room(room).join(username=self.bot_configuration.CHATROOM_FN, password=password)
self.query_room(room).join(username=self.bot_config.CHATROOM_FN, password=password)
except NotImplementedError:
# Backward compatibility for backends which do not yet have a
# query_room implementation and still have a join_room method.
......@@ -95,7 +95,7 @@ class ChatRoom(BotPlugin):
args[0].strip()
room, password = (args[0], None) if arglen == 1 else (args[0], args[1])
self.query_room(room).join(username=self.bot_configuration.CHATROOM_FN, password=password)
self.query_room(room).join(username=self.bot_config.CHATROOM_FN, password=password)
return "Joined the room {}".format(room)
@botcmd(split_args_with=SeparatorArgParser())
......@@ -253,17 +253,17 @@ class ChatRoom(BotPlugin):
mess_type = mess.type
if mess_type == 'chat':
username = mess.frm.node
if username in self.bot_configuration.CHATROOM_RELAY:
if username in self.bot_config.CHATROOM_RELAY:
logging.debug('Message to relay from %s.' % username)
body = mess.body
rooms = self.bot_configuration.CHATROOM_RELAY[username]
rooms = self.bot_config.CHATROOM_RELAY[username]
for room in rooms:
self.send(room, body, message_type='groupchat')
elif mess_type == 'groupchat':
fr = mess.frm
chat_room = fr.node + '@' + fr.domain if fr.domain else fr.node
if chat_room in self.bot_configuration.REVERSE_CHATROOM_RELAY:
users_to_relay_to = self.bot_configuration.REVERSE_CHATROOM_RELAY[chat_room]
if chat_room in self.bot_config.REVERSE_CHATROOM_RELAY:
users_to_relay_to = self.bot_config.REVERSE_CHATROOM_RELAY[chat_room]
logging.debug('Message to relay to %s.' % users_to_relay_to)
body = '[%s] %s' % (fr.resource, mess.body)
for user in users_to_relay_to:
......
......@@ -179,10 +179,10 @@ class Webserver(BotPlugin):
yield ("Generating a new private key and certificate. This could take a "
"while if your system is slow or low on entropy")
key_path = os.sep.join((self.bot_configutation.BOT_DATA_DIR, "webserver_key.pem"))
cert_path = os.sep.join((self.bot_configuration.BOT_DATA_DIR, "webserver_certificate.pem"))
key_path = os.sep.join((self.bot_config.BOT_DATA_DIR, "webserver_key.pem"))
cert_path = os.sep.join((self.bot_config.BOT_DATA_DIR, "webserver_certificate.pem"))
make_ssl_certificate(key_path=key_path, cert_path=cert_path)
yield "Certificate successfully generated and saved in {}".format(self.bot_configuration.BOT_DATA_DIR)
yield "Certificate successfully generated and saved in {}".format(self.bot_config.BOT_DATA_DIR)
suggested_config = self.config
suggested_config['SSL']['enabled'] = True
......
......@@ -51,7 +51,7 @@ CONFIGS = b'configs' if PY2 else 'configs'
REPOS = b'repos' if PY2 else 'repos'
BL_PLUGINS = b'bl_plugins' if PY2 else 'bl_plugins'
def main_config_defaults(config):
def bot_config_defaults(config):
if not hasattr(config, 'ACCESS_CONTROLS_DEFAULT'):
config.ACCESS_CONTROLS_DEFAULT = {}
if not hasattr(config, 'ACCESS_CONTROLS'):
......@@ -81,17 +81,17 @@ class ErrBot(Backend, StoreMixin):
MSG_UNKNOWN_COMMAND = 'Unknown command: "%(command)s". '
startup_time = datetime.now()
def __init__(self, config):
self.main_config = config
def __init__(self, bot_config):
self.bot_config = bot_config
self.plugin_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
self.plugin_dir = os.path.join(bot_config.BOT_DATA_DIR, PLUGINS_SUBDIR)
self.open_storage(os.path.join(config.BOT_DATA_DIR, 'core.db'))
self.prefix = config.BOT_PREFIX
self.open_storage(os.path.join(bot_config.BOT_DATA_DIR, 'core.db'))
self.prefix = bot_config.BOT_PREFIX
# be sure we have a configs entry for the plugin configurations
if CONFIGS not in self:
self[CONFIGS] = {}
super(ErrBot, self).__init__(config)
super(ErrBot, self).__init__(bot_config)
@staticmethod
def _dispatch_to_plugins(method, *args, **kwargs):
......@@ -166,7 +166,7 @@ class ErrBot(Backend, StoreMixin):
def update_dynamic_plugins(self):
all_candidates, errors = update_plugin_places(
[self.plugin_dir + os.sep + d for d in self.get(REPOS, {}).keys()],
self.main_config.BOT_EXTRA_PLUGIN_DIR)
self.bot_config.BOT_EXTRA_PLUGIN_DIR)
self.all_candidates = all_candidates
return errors
......@@ -622,7 +622,7 @@ class ErrBot(Backend, StoreMixin):
for (name, command) in self.commands.items():
clazz = get_class_that_defined_method(command)
commands = clazz_commands.get(clazz, [])
if not self.main_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name):
if not self.bot_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name):
commands.append((name, command))
clazz_commands[clazz] = commands
......@@ -634,7 +634,7 @@ class ErrBot(Backend, StoreMixin):
for (name, command) in clazz_commands[clazz]
if name != 'help'
and not command._err_command_hidden
and (not self.main_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name))
and (not self.bot_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name))
]))
usage += '\n\n'
elif args in (clazz.__name__ for clazz in self.get_command_classes()):
......@@ -647,7 +647,7 @@ class ErrBot(Backend, StoreMixin):
(self.get_doc(command).strip()).split('\n', 1)[0])
for (name, command) in commands
if not command._err_command_hidden
and (not self.main_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name))
and (not self.bot_config.HIDE_RESTRICTED_COMMANDS or may_access_command(name))
]))
else:
return super(ErrBot, self).help(mess, '_'.join(args.strip().split(' ')))
......@@ -694,7 +694,7 @@ class ErrBot(Backend, StoreMixin):
clazz = get_class_that_defined_method(command)
clazz = str.__module__ + '.' + clazz.__name__ # makes the fuul qualified name
commands = clazz_commands.get(clazz, [])
if not self.main_config.HIDE_RESTRICTED_COMMANDS or self.check_command_access(mess, name)[0]:
if not self.bot_config.HIDE_RESTRICTED_COMMANDS or self.check_command_access(mess, name)[0]:
commands.append((name, command))
clazz_commands[clazz] = commands
......@@ -839,7 +839,7 @@ class ErrBot(Backend, StoreMixin):
if args.isdigit():
n = int(args)
if self.main_config.BOT_LOG_FILE:
with open(self.main_config.BOT_LOG_FILE, 'r') as f:
if self.bot_config.BOT_LOG_FILE:
with open(self.bot_config.BOT_LOG_FILE, 'r') as f:
return tail(f, n)
return 'No log is configured, please define BOT_LOG_FILE in config.py'
......@@ -8,8 +8,8 @@ def main(bot_class, logger, config):
from errbot.utils import PLUGINS_SUBDIR
from errbot import holder
from errbot.errBot import main_config_defaults
main_config_defaults(config)
from errbot.errBot import bot_config_defaults
bot_config_defaults(config)
if config.BOT_LOG_FILE:
hdlr = logging.FileHandler(config.BOT_LOG_FILE)
......
......@@ -3,7 +3,7 @@ import sys
import logging
from tempfile import mkdtemp
from os.path import sep
from errbot.errBot import main_config_defaults
from errbot.errBot import bot_config_defaults
__import__('errbot.config-template')
config_module = sys.modules['errbot.config-template']
......@@ -32,15 +32,17 @@ class DummyBackend(Backend):
outgoing_message_queue = Queue()
jid = Identifier('err@localhost/err')
def __init__(self):
def __init__(self, extra_config={}):
class Config:
BOT_IDENTITY = {'username': 'err@localhost'}
BOT_ASYNC = False
BOT_PREFIX = '!'
CHATROOM_FN = 'blah'
self.main_config = Config()
main_config_defaults(self.main_config)
super(DummyBackend, self).__init__(self.main_config)
self.bot_config = Config()
for key in extra_config:
setattr(self.bot_config, key, extra_config[key])
bot_config_defaults(self.bot_config)
super(DummyBackend, self).__init__(self.bot_config)
self.inject_commands_from(self)
def build_message(self, text):
......@@ -256,7 +258,7 @@ class TestExecuteAndSend(unittest.TestCase):
def test_output_longer_than_max_message_size_is_split_into_multiple_messages_when_returned(self):
dummy = self.dummy
m = self.example_message
self.dummy.main_config.MESSAGE_SIZE_LIMIT = len(LONG_TEXT_STRING)
self.dummy.bot_config.MESSAGE_SIZE_LIMIT = len(LONG_TEXT_STRING)
dummy._execute_and_send(cmd='return_long_output', args=['foo', 'bar'], match=None, mess=m,
jid='noterr@localhost', template_name=dummy.return_long_output._err_command_template)
......@@ -267,7 +269,7 @@ class TestExecuteAndSend(unittest.TestCase):
def test_output_longer_than_max_message_size_is_split_into_multiple_messages_when_yielded(self):
dummy = self.dummy
m = self.example_message
self.dummy.main_config.MESSAGE_SIZE_LIMIT = len(LONG_TEXT_STRING)
self.dummy.bot_config.MESSAGE_SIZE_LIMIT = len(LONG_TEXT_STRING)
dummy._execute_and_send(cmd='yield_long_output', args=['foo', 'bar'], match=None, mess=m,
jid='noterr@localhost', template_name=dummy.yield_long_output._err_command_template)
......@@ -304,8 +306,8 @@ class BotCmds(unittest.TestCase):
self.dummy.callback_message(self.makemessage("!return_args_as_str one two"))
self.assertEquals("one two", self.dummy.pop_message().body)
@patch('errbot.backends.base.BOT_PREFIX_OPTIONAL_ON_CHAT', new=True)
def test_callback_message_with_prefix_optional(self):
self.dummy = DummyBackend({'BOT_PREFIX_OPTIONAL_ON_CHAT': True})
m = self.makemessage("return_args_as_str one two")
self.dummy.callback_message(m)
self.assertEquals("one two", self.dummy.pop_message().body)
......@@ -319,10 +321,8 @@ class BotCmds(unittest.TestCase):
self.dummy.callback_message(m)
self.assertEquals("one two", self.dummy.pop_message().body)
@patch('errbot.backends.base.BOT_ALT_PREFIXES', new=('Err',))
@patch('errbot.backends.base.BOT_ALT_PREFIX_SEPARATORS', new=(',', ';'))
def test_callback_message_with_bot_alt_prefixes(self):
self.dummy = DummyBackend()
self.dummy = DummyBackend({'BOT_ALT_PREFIXES': ('Err',), 'BOT_ALT_PREFIX_SEPARATORS': (',', ';')})
self.dummy.callback_message(self.makemessage("Err return_args_as_str one two"))
self.assertEquals("one two", self.dummy.pop_message().body)
self.dummy.callback_message(self.makemessage("Err, return_args_as_str one two"))
......@@ -341,10 +341,8 @@ class BotCmds(unittest.TestCase):
"This command also allows extra text in front - regex command with capture group: Captured text"))
self.assertEquals("Captured text", self.dummy.pop_message().body)
@patch('errbot.backends.base.BOT_ALT_PREFIXES', new=('Err',))
@patch('errbot.backends.base.BOT_ALT_PREFIX_SEPARATORS', new=(',', ';'))
def test_callback_message_with_re_botcmd_and_alt_prefixes(self):
self.dummy = DummyBackend()
self.dummy = DummyBackend({'BOT_ALT_PREFIXES': ('Err',), 'BOT_ALT_PREFIX_SEPARATORS': (',', ';')})
self.dummy.callback_message(self.makemessage("!regex command with prefix"))
self.assertEquals("Regex command", self.dummy.pop_message().body)
self.dummy.callback_message(self.makemessage("Err regex command with prefix"))
......@@ -451,8 +449,8 @@ class BotCmds(unittest.TestCase):
]
for test in tests:
self.dummy.main_config.ACCESS_CONTROLS_DEFAULT = test['acl_default']
self.dummy.main_config.ACCESS_CONTROLS = test['acl']
self.dummy.bot_config.ACCESS_CONTROLS_DEFAULT = test['acl_default']
self.dummy.bot_config.ACCESS_CONTROLS = test['acl']
logger = logging.getLogger(__name__)
logger.info("** message: {}".format(test['message'].body))
logger.info("** acl: {!r}".format(test['acl']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment