コード例 #1
0
 async def test_many(self, mock_messages):
     self.database.listBannedChannels.return_value = AsyncIterator(
         ['botgotsthis', 'megotsthis'])
     mock_messages.return_value = ''
     self.assertIs(await banned.list_banned_channels(self.send), True)
     mock_messages.assert_called_once_with(['botgotsthis', 'megotsthis'],
                                           StrContains('Banned'))
     self.send.assert_called_once_with('')
コード例 #2
0
 def test_logException(self, mock_now, mock_config, mock_logging,
                       mock_stderr):
     mock_now.return_value = datetime(2000, 1, 1)
     mock_config.development = True
     mock_config.exceptionLog = 'exception'
     try:
         raise Exception()
     except Exception:
         utils.logException()
     mock_logging.log.assert_called_once_with(
         StrContains('exception'),
         StrContains('2000', '01', 'Exception', __file__,
                     'test_logException', 'raise Exception'))
     self.assertEqual(
         mock_stderr.getvalue(),
         StrContains('2000', '1', 'Exception', __file__,
                     'test_logException', 'raise Exception'))
コード例 #3
0
 async def test(self):
     self.database.discardAutoJoin.return_value = True
     self.assertIs(
         await library.auto_join_delete(self.database, 'botgotsthis',
                                        self.send), True)
     self.database.discardAutoJoin.assert_called_once_with('botgotsthis')
     self.send.assert_called_once_with(StrContains('botgotsthis',
                                                   'disable'))
コード例 #4
0
 async def test_level_permission_wrong(self):
     self.mock_input.return_value = CommandActionTokens(
         'test', self.broadcaster, 'Kappa', 'Kappa', '')
     self.assertIs(
         await channel.process_command(self.args, self.broadcaster), True)
     self.mock_input.assert_called_once_with(self.message, self.broadcaster)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Invalid level'))
コード例 #5
0
 async def test_no_quote(self):
     self.mock_getter.return_value = None
     self.args = self.args._replace(
         message=Message('!quotes copy 0 megotsthis'))
     self.assertIs(await library.handleCopyQuote(self.args), True)
     self.assertFalse(self.mock_copier.called)
     self.channel.send.assert_called_once_with(
         StrContains('not', 'megotsthis', 'enabled'))
コード例 #6
0
 async def test_2_default(self):
     self.assertIs(
         await chat.set_timeout_level(self.data, 'botgotsthis', self.send,
                                      Message('!settimeoutlevel-2')), True)
     self.data.setChatProperty.assert_called_once_with(
         'botgotsthis', 'timeoutLength1', None)
     self.send.assert_called_once_with(
         StrContains('timeout', '2nd', 'default'))
コード例 #7
0
 async def test_except(self):
     self.mock_deleter.side_effect = pyodbc.Error
     self.args = self.args._replace(message=Message('!quotes delete 0'))
     with self.assertRaises(pyodbc.Error):
         await library.handleDeleteQuote(self.args)
     self.assertTrue(self.mock_deleter.called)
     self.channel.send.assert_called_once_with(StrContains(
         'not', 'deleted'))
コード例 #8
0
 async def test_exception(self):
     self.data.twitch_num_followers.return_value = 0
     message = Message('twitch.tv')
     self.mock_session.get.side_effect = Exception
     await block_url.check_domain_redirect(self.channel, 'megotsthis',
                                           message, self.now)
     self.data.twitch_num_followers.assert_called_once_with('megotsthis')
     self.mock_log.assert_called_once_with(
         StrContains('botgotsthis', 'blockurl'),
         StrContains('megotsthis', str(message)), self.now)
     self.assertTrue(self.mock_clientsession.called)
     self.mock_session.get.assert_called_once_with('http://twitch.tv',
                                                   headers=TypeMatch(dict))
     self.assertFalse(self.mock_handle.called)
     self.assertFalse(self.mock_compare.called)
     self.mock_except.assert_called_once_with(StrContains(str(message)),
                                              TypeMatch(datetime))
コード例 #9
0
 async def test_not_existing(self):
     self.database.setAutoJoinPriority.return_value = False
     self.assertIs(
         await autojoin.auto_join_priority('botgotsthis', 0, self.send),
         True)
     self.database.setAutoJoinPriority.assert_called_once_with(
         'botgotsthis', 0)
     self.send.assert_called_once_with(StrContains('botgotsthis', 'never'))
コード例 #10
0
 async def test(self):
     self.data.hasFeature.return_value = False
     self.assertIs(
         await library.feature_add(self.data, 'botgotsthis', 'feature',
                                   self.send), True)
     self.send.assert_called_once_with(StrContains('Feature', 'enable'))
     self.data.hasFeature.assert_called_once_with('botgotsthis', 'feature')
     self.data.addFeature.assert_called_once_with('botgotsthis', 'feature')
コード例 #11
0
 async def test_feature_none(self):
     self.assertIs(
         await library.feature(self.data, 'botgotsthis',
                               Message('!feature none'), self.send), True)
     self.send.assert_called_once_with(StrContains('feature', 'none'))
     self.assertFalse(self.mock_response.called)
     self.assertFalse(self.mock_add.called)
     self.assertFalse(self.mock_remove.called)
コード例 #12
0
 async def test_bad_param(self):
     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.assertFalse(self.mock_add.called)
     self.assertFalse(self.mock_remove.called)
コード例 #13
0
 async def test_uptime_isstreaming(self, mock_server_time):
     self.channel.isStreaming = True
     self.channel.streamingSince = self.now
     mock_server_time.return_value = self.now
     self.assertIs(await channel.commandUptime(self.args), True)
     mock_server_time.assert_called_once_with()
     self.channel.send.assert_called_once_with(
         StrContains('Uptime', str(timedelta())))
コード例 #14
0
 async def test_banned(self):
     self.database.isChannelBannedReason.return_value = ''
     self.assertIs(await library.come('botgotsthis', self.send), True)
     self.send.assert_called_once_with(StrContains('botgotsthis', 'banned'))
     self.database.isChannelBannedReason.assert_called_once_with(
         'botgotsthis')
     self.assertFalse(self.database.getAutoJoinsPriority.called)
     self.assertFalse(self.mock_join.called)
コード例 #15
0
 async def test_raw_game_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('!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', 'fail'))
コード例 #16
0
 async def test_empty(self):
     self.mock_listTags.return_value = []
     self.args = self.args._replace(message=Message('!quotes tag 0 Kappa'))
     self.assertIs(await library.processQuoteTags(self.args, 0, []), 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('No', 'valid', 'tags'))
コード例 #17
0
 async def test_append_command(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.appendCustomCommand.return_value = True
     self.assertIs(await channel.append_command(self.args, input), True)
     self.data.appendCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'PogChamp', 'botgotsthis')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'append', 'success'))
コード例 #18
0
 async def test_faq_faq_gamefaq(self, mock_faq, mock_gamefaq):
     self.permissions.moderator = False
     self.channel.twitchGame = 'Kappa'
     mock_faq.return_value = 'Kappa'
     mock_gamefaq.return_value = 'FrankerZ'
     self.assertIs(await channel.commandFaq(self.args), True)
     mock_faq.assert_called_once_with(self.channel.channel)
     self.assertFalse(mock_gamefaq.called)
     self.channel.send.assert_called_once_with(StrContains('FAQ', 'Kappa'))
コード例 #19
0
 async def test_existing(self):
     self.data.hasFeature.return_value = False
     self.assertIs(
         await library.feature_remove(self.data, 'botgotsthis', 'feature',
                                      self.send), True)
     self.send.assert_called_once_with(
         StrContains('Feature', 'not', 'enable'))
     self.data.hasFeature.assert_called_once_with('botgotsthis', 'feature')
     self.assertFalse(self.data.removeFeature.called)
コード例 #20
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_add.called)
     self.assertFalse(self.mock_remove.called)
コード例 #21
0
 async def test_broadcaster_limit(self):
     self.mock_config.messageLimit = 10000
     self.permissions.broadcaster = True
     self.assertIs(await pyramid.process_pyramid(self.args, 'Kappa ', 100),
                   True)
     self.channel.send.assert_called_once_with(
         IterableMatch(*([StrContains()] * (20 + 20 - 1))), -1)
     self.assertFalse(self.mock_cooldown.called)
     self.assertFalse(self.mock_timeout.called)
コード例 #22
0
 async def test_level_command_unknown_level(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp DansGame')
     self.data.levelCustomCommand.return_value = True
     self.assertIs(await channel.level_command(self.args, input), True)
     self.assertFalse(self.data.levelCustomCommand.called)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'PogChamp DansGame', 'invalid',
                     'permission'))
コード例 #23
0
 async def test_1(self):
     self.assertIs(
         await chat.set_timeout_level(self.data, 'botgotsthis', self.send,
                                      Message('!settimeoutlevel-1 1')),
         True)
     self.data.setChatProperty.assert_called_once_with(
         'botgotsthis', 'timeoutLength0', '1')
     self.send.assert_called_once_with(
         StrContains('timeout', '1st', '1 second'))
コード例 #24
0
 async def test_level_command_dberror(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'moderator')
     self.data.levelCustomCommand.return_value = False
     self.assertIs(await channel.level_command(self.args, input), True)
     self.data.levelCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'botgotsthis', 'moderator')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'change', 'not', 'success'))
コード例 #25
0
 async def test_manager(self):
     self.database.isBotManager.return_value = True
     self.assertIs(
         await manager.insert_manager('megotsthis', self.database,
                                      self.send), True)
     self.database.isBotManager.assert_called_once_with('megotsthis')
     self.assertFalse(self.database.addBotManager.called)
     self.send.assert_called_once_with(
         StrContains('megotsthis', 'already', 'manager'))
コード例 #26
0
 async def test_delete_command_dberror(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.deleteCustomCommand.return_value = False
     self.assertIs(await channel.delete_command(self.args, input), True)
     self.data.deleteCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'botgotsthis')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'remove', 'not', 'success'))
コード例 #27
0
 async def test_moderator_limit(self):
     self.mock_cooldown.return_value = False
     self.assertIs(await wall.process_wall(self.args, 'Kappa', 100), True)
     self.channel.send.assert_called_once_with(
         IterableMatch(*([StrContains()] * (10))), -1)
     self.assertFalse(self.mock_timeout.called)
     self.mock_cooldown.assert_called_once_with(self.args,
                                                timedelta(seconds=30),
                                                'modWall')
コード例 #28
0
 async def test_not_manager(self):
     self.database.isBotManager.return_value = False
     self.assertIs(
         await manager.delete_manager('megotsthis', self.database,
                                      self.send), True)
     self.database.isBotManager.assert_called_once_with('megotsthis')
     self.assertFalse(self.database.removeBotManager.called)
     self.send.assert_called_once_with(
         StrContains('megotsthis', 'not', 'manager'))
コード例 #29
0
 async def test_process_list_empty(self):
     self.args = self.args._replace(message=Message('!autorepeat 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'))
コード例 #30
0
 async def test_banned_delete(self):
     self.database.isChannelBannedReason.return_value = ''
     self.assertIs(
         await library.auto_join('botgotsthis', self.send,
                                 Message('!autojoin delete')), True)
     self.database.isChannelBannedReason.assert_called_once_with(
         'botgotsthis')
     self.assertFalse(self.mock_add.called)
     self.assertFalse(self.mock_delete.called)
     self.send.assert_called_once_with(StrContains('banned', 'botgotsthis'))