예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
 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')
예제 #5
0
 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')
예제 #6
0
 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')
예제 #7
0
 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)
예제 #8
0
 def new_user(self,user,typ):
   self.log.debug('new_user(%s,%s)' % (user,typ))
   return MockUser('MOCK_NEW_USER')
예제 #9
0
 def get_real(self,room,nick):
   self.log.debug('get_real(%s,%s)' % (room,nick))
   return MockUser('MOCK_REALNAME',Message.PRIVATE)