Beispiel #1
0
 async def test_no_quote(self):
     self.mock_getId.return_value = None
     self.args = self.args._replace(message=Message('!quotes id'))
     self.assertIs(await library.processQuoteTags(self.args, 0, ['Kappa']),
                   True)
     self.assertFalse(self.mock_listTags.called)
     self.assertFalse(self.mock_adder.called)
     self.assertFalse(self.mock_deleter.called)
     self.channel.send.assert_called_once_with(
         StrContains('0', 'not', 'found'))
Beispiel #2
0
 async def test_2(self):
     self.permissionSet['broadcaster'] = True
     self.permissions.broadcaster = True
     self.permissions.globalModerator = True
     message = Message('!rpyramid 2')
     args = self.args._replace(message=message)
     self.assertIs(await pyramid.commandRandomPyramid(args), True)
     self.channel.send.assert_called_once_with(
         IterableMatch(':)', ':) FrankerZ', ':)'), -1)
     self.assertFalse(self.mock_cooldown.called)
Beispiel #3
0
 async def test_moderator_cooldown(self):
     self.mock_cooldown.return_value = True
     self.permissionSet['moderator'] = True
     self.features.append('modpyramid')
     message = Message('!rpyramid')
     args = self.args._replace(message=message)
     self.assertIs(await pyramid.commandRandomPyramid(args), False)
     self.assertFalse(self.channel.send.called)
     self.mock_cooldown.assert_called_once_with(args, timedelta(seconds=30),
                                                'modPyramid')
Beispiel #4
0
    def setUp(self):
        self.args = CustomFieldArgs('', None, None, None, None, Message(''),
                                    Mock(spec=Channel), 'botgotsthis',
                                    Mock(spec=ChatPermissionSet),
                                    datetime(2000, 1, 1))

        patcher = patch('lib.items.custom', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_list = patcher.start()
        self.mock_list.fields.return_value = []
Beispiel #5
0
 async def test_except(self):
     self.mock_listTags.side_effect = pyodbc.Error
     self.args = self.args._replace(message=Message('!quotes tag 0 Kappa'))
     with self.assertRaises(pyodbc.Error):
         await library.processQuoteTags(self.args, 0, ['Kappa'])
     self.assertTrue(self.mock_listTags.called)
     self.assertFalse(self.mock_adder.called)
     self.assertFalse(self.mock_deleter.called)
     self.channel.send.assert_called_once_with(
         StrContains('tags', 'not', 'updated'))
Beispiel #6
0
 async def test_raw_game(self, mock_update, mock_token):
     mock_update.return_value = True
     self.permissionSet['broadcaster'] = True
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!setgame Pokemon'))
     self.assertIs(await channel.commandRawGame(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis', game='Pokemon')
     self.channel.send.assert_called_once_with(
         StrContains('Game', 'Pokemon'))
Beispiel #7
0
 async def test_game(self, mock_update, mock_token):
     mock_update.return_value = True
     self.permissionSet['broadcaster'] = True
     self.data.getFullGameTitle.return_value = None
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!game Kappa'))
     self.assertIs(await channel.commandGame(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis', game='Kappa')
     self.channel.send.assert_called_once_with(StrContains('Game', 'Kappa'))
    def setUp(self):
        self.channel = Mock(spec=Channel)
        self.channel.channel = 'botgotsthis'
        self.channel.ircChannel = '#botgotsthis'
        self.message = Message('')
        self.now = datetime(2000, 1, 1)

        patcher = patch('bot.utils.logIrcMessage', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_log = patcher.start()
Beispiel #9
0
 async def test_remove(self):
     self.mock_remove.return_value = True
     self.assertIs(
         await library.feature(self.data, 'botgotsthis',
                               Message('!feature feature no'), self.send),
         True)
     self.assertFalse(self.send.called)
     self.mock_remove.assert_called_once_with(self.data, 'botgotsthis',
                                              'feature', self.send)
     self.assertFalse(self.mock_add.called)
Beispiel #10
0
 async def test(self):
     self.assertIs(
         await library.auto_join('botgotsthis', self.send,
                                 Message('!autojoin')), True)
     self.database.isChannelBannedReason.assert_called_once_with(
         'botgotsthis')
     self.mock_add.assert_called_once_with(self.database, 'botgotsthis',
                                           self.send)
     self.assertFalse(self.mock_delete.called)
     self.send.assert_not_called()
Beispiel #11
0
 async def test_bad_param(self):
     self.mock_response.return_value = parser.Unknown
     self.assertIs(
         await library.feature(self.data, 'botgotsthis',
                               Message('!feature feature Kappa'),
                               self.send), True)
     self.send.assert_called_once_with(StrContains('parameter', 'kappa'))
     self.assertTrue(self.mock_response.called)
     self.assertFalse(self.mock_add.called)
     self.assertFalse(self.mock_remove.called)
Beispiel #12
0
 async def test_not_existing_feature(self):
     self.assertIs(
         await library.feature(self.data, 'botgotsthis',
                               Message('!feature does_not_exist'),
                               self.send), True)
     self.send.assert_called_once_with(
         StrContains('feature', 'does_not_exist'))
     self.assertFalse(self.mock_response.called)
     self.assertFalse(self.mock_add.called)
     self.assertFalse(self.mock_remove.called)
Beispiel #13
0
 async def test_status_fail(self, mock_update, mock_token):
     mock_update.return_value = False
     self.permissionSet['broadcaster'] = True
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!status'))
     self.assertIs(await channel.commandStatus(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis', status='')
     self.channel.send.assert_called_once_with(StrContains(
         'Status', 'fail'))
Beispiel #14
0
 async def test_number(self):
     self.mock_listTags.return_value = []
     self.args = self.args._replace(message=Message('!quotes tag 0 0abc'))
     self.assertIs(await library.processQuoteTags(self.args, 0, ['0abc']),
                   True)
     self.assertTrue(self.mock_listTags.called)
     self.assertFalse(self.mock_adder.called)
     self.assertFalse(self.mock_deleter.called)
     self.channel.send.assert_called_once_with(
         StrContains('tags', 'use', '0abc'))
Beispiel #15
0
 async def test_community_fail(self, mock_update, mock_token):
     self.data.twitch_get_community_name.return_value = 'Speedrunning'
     mock_update.return_value = None
     self.permissionSet['broadcaster'] = True
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!community'))
     self.assertIs(await channel.commandCommunity(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis', [])
     self.channel.send.assert_called_once_with(
         StrContains('Community', 'fail'))
Beispiel #16
0
 async def test_community(self, mock_update, mock_token):
     self.data.twitch_get_community_name.return_value = 'Speedrunning'
     mock_update.return_value = ['6e940c4a-c42f-47d2-af83-0a2c7e47c421']
     self.permissionSet['broadcaster'] = True
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!community speedrunning'))
     self.assertIs(await channel.commandCommunity(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis', ['speedrunning'])
     self.channel.send.assert_called_once_with(
         StrContains('Community', 'Speedrunning'))
Beispiel #17
0
 def setUp(self):
     self.now = datetime(2000, 1, 1)
     self.tags = IrcMessageTags()
     self.channel = Mock(spec=Channel)
     self.channel.channel = 'botgotsthis'
     self.data = Mock(spec=CacheStore)
     self.database = Mock(spec=DatabaseMain)
     self.permissions = MagicMock(spec=ChatPermissionSet)
     self.args = ChatCommandArgs(self.data,
                                 self.channel, self.tags, 'botgotsthis',
                                 Message(''), self.permissions, self.now)
 async def test_setfaq_not_moderator(self, mock_faq, mock_gamefaq):
     self.permissionSet['moderator'] = False
     self.channel.twitchGame = 'Kappa'
     mock_faq.return_value = False
     mock_gamefaq.return_value = False
     message = Message('!setfaq Kappa')
     args = self.args._replace(message=message)
     self.assertIs(await channel.commandSetFaq(args), False)
     self.assertFalse(mock_faq.called)
     self.assertFalse(mock_gamefaq.called)
     self.assertFalse(self.channel.send.called)
Beispiel #19
0
 async def test_broadcaster_limit(self):
     self.mock_choice.side_effect = [0, 5, 3, 1, 7] * 10
     self.mock_config.messageLimit = 1000
     self.permissionSet['broadcaster'] = True
     self.permissions.broadcaster = True
     message = Message('!rpyramid 50')
     args = self.args._replace(message=message)
     self.assertIs(await pyramid.commandRandomPyramid(args), True)
     self.channel.send.assert_called_once_with(
         IterableMatch(*([StrContains()] * (20 + 20 - 1))), -1)
     self.assertFalse(self.mock_cooldown.called)
Beispiel #20
0
 async def test_feature(self, mock_feature):
     self.assertIs(await channel.commandFeature(self.args), False)
     self.assertFalse(mock_feature.called)
     mock_feature.return_value = True
     self.permissions.inOwnerChannel = True
     self.permissionSet['broadcaster'] = True
     message = Message('!feature feature')
     args = self.args._replace(message=message)
     self.assertIs(await channel.commandFeature(args), True)
     mock_feature.assert_called_once_with(self.data, 'botgotsthis', message,
                                          self.channel.send)
 async def test_setfaq(self, mock_faq, mock_gamefaq):
     self.permissionSet['moderator'] = True
     self.channel.twitchGame = 'Kappa'
     mock_faq.return_value = True
     mock_gamefaq.return_value = False
     message = Message('!setfaq Kappa')
     args = self.args._replace(message=message)
     self.assertIs(await channel.commandSetFaq(args), True)
     mock_faq.assert_called_once_with(self.channel.channel, 'Kappa')
     self.assertFalse(mock_gamefaq.called)
     self.channel.send.assert_called_once_with(StrContains('FAQ', 'Kappa'))
Beispiel #22
0
 async def test_moderator(self):
     self.permissionSet['moderator'] = True
     self.features.append('modpyramid')
     message = Message('!rpyramid')
     args = self.args._replace(message=message)
     self.assertIs(await pyramid.commandRandomPyramid(args), True)
     self.channel.send.assert_called_once_with(
         IterableMatch(':)', ':) FrankerZ', ':) FrankerZ PogChamp',
                       ':) FrankerZ', ':)'), -1)
     self.mock_cooldown.assert_called_once_with(args, timedelta(seconds=30),
                                                'modPyramid')
 async def test_wall_repeat_rows_limit(self):
     self.mock_config.messageLimit = 25
     self.permissions.broadcaster = True
     self.permissionSet['broadcaster'] = True
     self.mock_process.return_value = True
     message = Message('!wall Kappa 10 10')
     args = self.args._replace(message=message)
     self.assertIs(await wall.commandWall(args), True)
     self.mock_process.assert_called_once_with(args,
                                               'Kappa Kappa Kappa Kappa',
                                               10)
Beispiel #24
0
    def setUp(self):
        super().setUp()
        self.message = Message('!commmand test !someCommand')
        self.args = self.args._replace(message=self.message)
        self.broadcaster = '#global'

        patcher = patch(library.__name__ + '.parse_action_message',
                        autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_input = patcher.start()
        self.mock_input.return_value = None
Beispiel #25
0
 async def test_process_name_list_empty(self):
     self.args = self.args._replace(
         message=Message('!autorepeat name=kappa list'))
     self.data.listAutoRepeat.return_value = AsyncIterator([])
     self.assertIs(await channel.process_auto_repeat(self.args, 1), True)
     self.data.listAutoRepeat.assert_called_once_with(
         self.channel.channel)
     self.assertFalse(self.data.removeAutoRepeat.called)
     self.assertFalse(self.data.setAutoRepeat.called)
     self.channel.send.assert_called_once_with(
         StrContains('No', 'Auto Repeats'))
Beispiel #26
0
 async def test_game_fail(self, mock_update, mock_token):
     mock_update.return_value = False
     self.features.append('gamestatusbroadcaster')
     self.permissionSet['broadcaster'] = True
     self.data.getFullGameTitle.return_value = None
     mock_token.return_value = 'oauth:'
     args = self.args._replace(message=Message('!game Pokemon Pokepark'))
     self.assertIs(await channel.commandGame(args), True)
     mock_token.assert_called_once_with('botgotsthis')
     mock_update.assert_called_once_with('botgotsthis',
                                         game='Pokémon Poképark')
     self.channel.send.assert_called_once_with(StrContains('Game', 'fail'))
 async def test_manage_bot(self, mock_manage_bot):
     self.assertIs(await owner.commandManageBot(self.args), False)
     self.assertFalse(mock_manage_bot.called)
     mock_manage_bot.return_value = True
     self.permissions.inOwnerChannel = True
     self.permissionSet['manager'] = True
     message = Message('!managebot listchats')
     args = self.args._replace(message=message)
     self.assertIs(await owner.commandManageBot(args), True)
     mock_manage_bot.assert_called_once_with(
         self.data, self.permissions, self.channel.send,
         'botgotsthis', message)
 async def test_followers(self):
     self.data.twitch_num_followers.return_value = 1
     message = Message('twitch.tv')
     await block_url.check_domain_redirect(self.channel, 'botgotsthis',
                                           message, self.now)
     self.data.twitch_num_followers.assert_called_once_with('botgotsthis')
     self.assertFalse(self.mock_log.called)
     self.assertFalse(self.mock_except.called)
     self.assertFalse(self.mock_clientsession.called)
     self.assertFalse(self.mock_session.get.called)
     self.assertFalse(self.mock_compare.called)
     self.assertFalse(self.mock_handle.called)
Beispiel #29
0
 async def test(self):
     self.mock_listTags.return_value = ['Kappa']
     self.args = self.args._replace(
         message=Message('!quotes tag 0 Kappa FrankerZ'))
     self.assertIs(
         await library.processQuoteTags(self.args, 0,
                                        ['Kappa', 'FrankerZ']), True)
     self.assertTrue(self.mock_listTags.called)
     self.mock_adder.asset_called_once_with(self.database, 0, ['FrankerZ'])
     self.mock_deleter.asset_called_once_with(self.database, 0, ['Kappa'])
     self.channel.send.assert_called_once_with(
         StrContains('0', 'tags', 'updated'))
Beispiel #30
0
 async def test_purge_reason(self, mock_database):
     database = MagicMock(spec=DatabaseTimeout)
     mock_database.return_value = database
     database.__aenter__.return_value = database
     self.permissionSet['moderator'] = True
     self.permissionSet['chatModerator'] = True
     args = self.args._replace(message=Message('!purge MeGotsThis Kappa'))
     self.assertIs(await purge.commandPurge(args), True)
     self.channel.send.assert_called_once_with(
         '.timeout MeGotsThis 1 Kappa')
     database.recordTimeout.assert_called_once_with(
         'botgotsthis', 'megotsthis', 'botgotsthis', 'purge', None, 1,
         '!purge MeGotsThis Kappa', 'Kappa')