Ejemplo n.º 1
0
 def test_snark(self):
     self.assertIn('snark', self.bot.commands)
     snark = self.bot.commands['snark']
     for msg_content in test_messages:
         msg_content = msg_content.replace('{bot-mention}', '<@!'+self.bot.user.id+'>')
         self.assertTrue(snark._matches(testlib.TestMessage(content=msg_content)))
         self.assertIsNone(self.loop.run_until_complete(snark._action(testlib.TestMessage())) )
Ejemplo n.º 2
0
    def test_example(self):
        self.assertIn('zzc_invalid', self.bot.commands)
        zz_invalid = self.bot.commands['zzc_invalid']
        # matches() should always evaluate to true for zz_invalid when the bot is mentioned
        self.assertTrue(zz_invalid._matches(testlib.TestMessage(content='<@!'+self.bot.user.id+'> ')))

        self.bot.last_message = None
        self.assertIsNone(self.loop.run_until_complete(zz_invalid._action(testlib.TestMessage())) )
        self.assertIsNotNone(self.bot.last_message)
Ejemplo n.º 3
0
 def test_authorize(self):
     # set up pipe
     maintainer_id = '2' * 18
     owner_id = '1' * 18
     test_pipe = pipe_class.Pipe(name='test pipe',
                                 root_channel=root_id,
                                 channels=[dest_id],
                                 owner=owner_id)
     self.piper.public_namespace.pipes.append(test_pipe)
     # test authorize
     author = testlib.TestMember(user_id=owner_id)
     for content in authorize_messages:
         content = content.replace('{bot-mention}',
                                   '<@!' + self.bot.user.id + '>')
         content = content.replace('{maintainer-mention}',
                                   '<@!' + maintainer_id + '>')
         msg = testlib.TestMessage(content=content, author=author)
         self.assertTrue(self.pipe_authorize._matches(msg),
                         'Match failed for %s' % content)
         self.loop.run_until_complete(self.pipe_authorize._action(msg))
         # print(self.bot.last_message)
         # print(test_pipe.maintainers)
         self.assertIn(maintainer_id, test_pipe.maintainers,
                       'Correct maintainer not added for %s' % content)
     # remove pipe
     self.piper.public_namespace.pipes.remove(test_pipe)
Ejemplo n.º 4
0
 def test_piper(self):
     # set up pipe
     test_pipe = pipe_class.Pipe(name='test pipe',
                                 root_channel=root_id,
                                 channels=[dest_id])
     self.piper.public_namespace.pipes.append(test_pipe)
     # test piper
     channel = testlib.TestChannel(channel_id=root_id,
                                   server=testlib.TestServer())
     for content in piper_messages:
         content = content.replace('{bot-mention}',
                                   '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=content,
                                   channel=channel,
                                   server=channel.server)
         self.assertTrue(
             self.piper._matches(msg),
             'Match failed for %s, id=%s' % (content, msg.channel.id))
         self.loop.run_until_complete(self.piper._action(msg))
         pipe_msg = find_by_channel_id(dest_id, self.bot.message_history)
         self.assertIsNotNone(
             pipe_msg, 'Piped message not found for %s, id=%s' %
             (content, msg.channel.id))
         self.assertEqual(content, pipe_msg.content,
                          'Piped message not equal for %s' % content)
     # remove pipe
     self.piper.public_namespace.pipes.remove(test_pipe)
Ejemplo n.º 5
0
 def test_modify(self):
     # set up pipe
     maintainer_id = '2' * 18
     owner_id = '1' * 18
     new_channel = '5' * 18
     test_pipe = pipe_class.Pipe(name='test pipe',
                                 root_channel=root_id,
                                 channels=[dest_id],
                                 owner=owner_id,
                                 maintainers=[maintainer_id])
     self.piper.public_namespace.pipes.append(test_pipe)
     # test authorize
     author = testlib.TestMember(user_id=owner_id)
     channel = testlib.TestChannel(channel_id=new_channel)
     for content in modify_messages:
         content = content.replace('{bot-mention}',
                                   '<@!' + self.bot.user.id + '>')
         if '{channel-mention}' in content:
             content = content.replace('{channel-mention}',
                                       '<#' + new_channel + '>')
             channel.id = '0' * 18
         msg = testlib.TestMessage(content=content,
                                   author=author,
                                   channel=channel)
         self.assertTrue(self.pipe_modify._matches(msg),
                         'Match failed for %s' % content)
         self.loop.run_until_complete(self.pipe_modify._action(msg))
         # print(self.bot.last_message)
         self.assertIn(new_channel, test_pipe.channels,
                       'Correct maintainer not added for %s' % content)
         test_pipe.channels.remove(new_channel)
         channel.id = new_channel
     # remove pipe
     self.piper.public_namespace.pipes.remove(test_pipe)
Ejemplo n.º 6
0
    def test_todo(self):
        # test adding
        # print("Adding...")
        for msg_content in test_add_messages:
            msg_content = msg_content.replace('{bot-mention}',
                                              '<@!' + self.bot.user.id + '>')
            msg = testlib.TestMessage(content=msg_content)
            self.assertTrue(self.todo_cmd._matches(msg),
                            "Match failed for %s " % msg_content)
            self.assertIsNone(
                self.loop.run_until_complete(self.todo_cmd._action(msg)),
                "Action failed for %s " % msg_content)
            self.assertIsNotNone(self.bot.last_embed,
                                 "Missing embed for %s" % msg_content)
            self.bot.last_embed = None

        # test listing
        # print("Listing...")
        for msg_content in test_list_messages:
            msg_content = msg_content.replace('{bot-mention}',
                                              '<@!' + self.bot.user.id + '>')
            msg = testlib.TestMessage(content=msg_content)
            self.assertTrue(self.todo_cmd._matches(msg),
                            "Match failed for %s " % msg_content)
            self.assertIsNone(
                self.loop.run_until_complete(self.todo_cmd._action(msg)),
                "Action failed for %s " % msg_content)
            self.assertIsNotNone(self.bot.last_embed,
                                 "Missing embed for %s" % msg_content)
            self.bot.last_embed = None

        # test removing
        # print("Removing...")
        for msg_content in test_rm_messages:
            msg_content = msg_content.replace('{bot-mention}',
                                              '<@!' + self.bot.user.id + '>')
            msg = testlib.TestMessage(content=msg_content)
            self.assertTrue(self.todo_cmd._matches(msg),
                            "Match failed for %s " % msg_content)
            self.assertIsNone(
                self.loop.run_until_complete(self.todo_cmd._action(msg)),
                "Action failed for %s " % msg_content)
            self.assertIsNotNone(self.bot.last_embed,
                                 "Missing embed for %s" % msg_content)
            # print(self.bot.last_embed)
            self.bot.last_embed = None
Ejemplo n.º 7
0
 def test_list(self):
     for msg_content in list_messages:
         msg_content = msg_content.replace('{bot-mention}',
                                           '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=msg_content)
         self.assertTrue(self.help_cmd._matches(msg),
                         "Match failed for %s" % msg_content)
         self.assertIsNone(
             self.loop.run_until_complete(
                 self.help_cmd._action(msg, self.bot)),
             "Action failed for %s" % msg_content)
         self.assertIsNotNone(self.bot.last_embed,
                              "Missing embed for %s" % msg_content)
         self.bot.last_embed = None
Ejemplo n.º 8
0
 def test_cardlife_add(self):
     self.assertIn('claddstatus', self.bot.commands)
     cl = self.bot.commands['claddstatus']
     for msg_content in test_messages:
         msg_content = msg_content.replace('{bot-mention}',
                                           '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=msg_content)
         self.assertTrue(cl._matches(msg),
                         "Match failed for %s" % msg_content)
         self.assertIsNone(self.loop.run_until_complete(cl._action(msg)),
                           "Action failed for %s" % msg_content)
         #NOTE: credentials for CardLife API are incorrect so response will not be an embed
         self.assertIsNotNone(self.bot.last_embed,
                              "Missing embed for %s" % msg_content)
         self.bot.last_embed = None
Ejemplo n.º 9
0
 def test_cardlife_info(self):
     self.assertIn('clinfo', self.bot.commands)
     cl = self.bot.commands['clinfo']
     for msg_content in test_messages:
         msg_content = msg_content.replace('{bot-mention}',
                                           '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=msg_content)
         self.assertTrue(cl._matches(msg),
                         "Match failed for %s" % msg_content)
         self.loop.run_until_complete(cl._action(msg))
         #NOTE: credentials for CardLife API are incorrect so response will not be an embed
         self.assertGreaterEqual(len(self.bot.message_history), 1,
                                 "Missing message for %s" % msg_content)
         last_msg = self.bot.message_history.pop()
         self.assertIsNotNone(last_msg.content or last_msg.embed,
                              "Missing message for %s" % msg_content)
         self.bot.last_message = None
Ejemplo n.º 10
0
 def test_create(self):
     channel = testlib.TestChannel(channel_id=root_id)
     for content in create_messages:
         content = content.replace('{bot-mention}',
                                   '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=content, channel=channel)
         self.assertTrue(self.pipe_create.matches(msg),
                         'Match failed for %s' % content)
         self.loop.run_until_complete(self.pipe_create._action(msg))
         self.assertNotEqual(self.piper.public_namespace.pipes, list())
         test_pipe = find_pipe_by_root(root_id,
                                       self.piper.public_namespace.pipes)
         self.assertIsNotNone(
             test_pipe, 'Piped message not found for %s, id=%s' %
             (content, msg.channel.id))
         # print(test_pipe.name)
         # remove test pipe
         self.piper.public_namespace.pipes.remove(test_pipe)
Ejemplo n.º 11
0
 def test_delete(self):
     maintainer_id = '2' * 18
     owner_id = '1' * 18
     for content in delete_messages:
         # create and add test pipe
         test_pipe = pipe_class.Pipe(name='test pipe',
                                     root_channel=root_id,
                                     channels=[dest_id],
                                     owner=owner_id)
         self.piper.public_namespace.pipes.append(test_pipe)
         # create discord test vars
         author = testlib.TestMember(user_id=owner_id)
         content = content.replace('{bot-mention}',
                                   '<@!' + self.bot.user.id + '>')
         msg = testlib.TestMessage(content=content, author=author)
         # test matches()
         self.assertTrue(self.pipe_delete._matches(msg))
         # test action()
         self.loop.run_until_complete(self.pipe_delete._action(msg))
         self.assertNotIn(test_pipe, self.piper.public_namespace.pipes,
                          'Test pipe not deleted for %s' % content)