def process_chat(self,text,typ,direct=False,prefix=None,cond=True): self.bot.opts['only_direct'] = direct self.bot.opts['cmd_prefix'] = prefix user = MockUser('MOCK_USERNAME',typ) msg = Message(typ,user,text) self.bot.protocol.queue_msg(msg) try: self.bot.run_forever() except QueueEmpty: pass if cond: self.assertIn(user.get_base(),self.bot.last_cmd) else: self.assertNotIn(user.get_base(),self.bot.last_cmd)
def process_chat(self, text, typ, direct=False, prefix=None, cond=True): self.bot.opts['only_direct'] = direct self.bot.opts['cmd_prefix'] = prefix user = MockUser('MOCK_USERNAME', typ) msg = Message(typ, user, text) self.bot.protocol.queue_msg(msg) try: self.bot.run_forever() except QueueEmpty: pass if cond: self.assertIn(user.get_base(), self.bot.last_cmd) else: self.assertNotIn(user.get_base(), self.bot.last_cmd)
def test_hooks_fail_status(self): types = [Message.STATUS, Message.PRIVATE, Message.GROUP, Message.ERROR] users = [ Message.PRIVATE, Message.PRIVATE, Message.GROUP, Message.PRIVATE ] hooks = ['HOOK_STATUS', 'HOOK_PRIVATE', 'HOOK_GROUP', 'HOOK_ERROR'] statuses = [Message.AVAILABLE, None, None, None] msgs = ['MOCK_STATUS', None, None, None] for (typ, user, hook, status, msg) in zip(types, users, hooks, statuses, msgs): user = MockUser('MOCK_USERNAME', user) msg = Message(typ, user, 'MOCK', status, msg) self.bot.protocol.queue_msg(msg) self.process([x for x in hooks if x != hook], False)
def test_status_hook_runs(self): user = MockUser('MOCK_USERNAME', Message.PRIVATE) msg = Message(Message.STATUS, user, 'MOCK', Message.AVAILABLE, 'MOCK_STATUS') self.bot.protocol.queue_msg(msg) self.process('HOOK_STATUS')
def test_group_hook_runs(self): user = MockUser('MOCK_USERNAME', Message.GROUP) msg = Message(Message.GROUP, user, 'MOCK') self.bot.protocol.queue_msg(msg) self.process('HOOK_GROUP')
def test_priv_hook_runs(self): user = MockUser('MOCK_USERNAME', Message.PRIVATE) msg = Message(Message.PRIVATE, user, 'MOCK') self.bot.protocol.queue_msg(msg) self.process('HOOK_PRIV')
def queue_msg(self,msg=None): self.log.debug('queue_msg(%s)' % msg) if not msg: user = MockUser('MOCK_USERNAME',Message.PRIVATE) msg = Message(Message.PRIVATE,user,'MOCK_BODY') self.queue.insert(0,msg)
def new_user(self,user,typ): self.log.debug('new_user(%s,%s)' % (user,typ)) return MockUser('MOCK_NEW_USER')
def get_real(self,room,nick): self.log.debug('get_real(%s,%s)' % (room,nick)) return MockUser('MOCK_REALNAME',Message.PRIVATE)