def test_sending_messages_quickly(self): tags = IrcMessageTags(IrcMessageTags.parseTags('msg-id=msg_ratelimit')) notice.parse( tags, self.channel, None, 'Your message was not sent because you are sending messages too ' 'quickly.') self.assertIs(self.channel.isMod, False) self.assertFalse(self.channel.clear.called)
def setUp(self): self.tags = IrcMessageTags( IrcMessageTags.parseTags( 'display-name=BotGotsThis;id=0;subscriber=0;turbo=0;mod=1;' 'user-type=mod;badges=broadcaster/1;color=#FFFFFF;emotes=;' 'room-id=2;user-id=1')) self.channel = Mock(spec=Channel) self.channel.channel = 'megotsthis' self.now = datetime(2000, 1, 1)
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 = MagicMock(spec=DatabaseMain) self.database.__aenter__.return_value = self.database self.database.__aexit__.return_value = False self.permissionSet = { 'owner': False, 'inOwnerChannel': False, 'staff': False, 'admin': False, 'globalMod': False, 'broadcaster': False, 'moderator': False, 'subscriber': False, 'chatModerator': False, } self.permissions = MagicMock(spec=ChatPermissionSet) self.permissions.inOwnerChannel = False self.permissions.__getitem__.side_effect = \ lambda k: self.permissionSet[k] self.messages = ['Kappa'] self.args = CustomProcessArgs(self.data, self.channel, self.tags, 'botgotsthis', self.permissions, 'botgotsthis', '', 'kappa', self.messages) patcher = patch.object(DatabaseMain, 'acquire') self.addCleanup(patcher.stop) self.mock_database = patcher.start() self.mock_database.return_value = self.database
def test_set_item(self): tags = IrcMessageTags() self.assertEqual(len(tags), 0) tags['Kappa'] = True self.assertEqual(len(tags), 1) self.assertIn('Kappa', tags) self.assertIs(tags['Kappa'], True)
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.data.hasFeature.return_value = False self.database = Mock(spec=DatabaseMain) self.database.hasFeature.return_value = False self.permissions = MagicMock(spec=ChatPermissionSet) self.command = CustomCommand('Kappa KappaRoss KappaPride', '#global', '') self.args = ChatCommandArgs(self.data, self.channel, self.tags, 'botgotsthis', Message('Kappa'), self.permissions, self.now) patcher = patch(library.__name__ + '.split_message', autospec=True) self.addCleanup(patcher.stop) self.mock_split = patcher.start() patcher = patch(library.__name__ + '.convert_field') self.addCleanup(patcher.stop) self.mock_convert = patcher.start() self.mock_convert.side_effect = lambda args: args.default patcher = patch(library.__name__ + '.format', autospec=True) self.addCleanup(patcher.stop) self.mock_format = patcher.start() self.mock_format.side_effect = lambda string, format, has: string patcher = patch('lib.items.custom', autospec=True) self.addCleanup(patcher.stop) self.mock_list = patcher.start() self.mock_list.postProcess.return_value = []
def setUp(self): self.now = datetime(2000, 1, 1) self.tags = IrcMessageTags() self.data = Mock(spec=CacheStore) self.database = Mock(spec=DatabaseMain) self.permissions = MagicMock(spec=WhisperPermissionSet) self.args = WhisperCommandArgs(self.data, 'botgotsthis', Message(''), self.permissions, self.now)
def setUp(self): patcher = patch('bot.globals', autospec=True) self.addCleanup(patcher.stop) self.mock_globals = patcher.start() self.cache = datetime(2000, 1, 1) self.mock_globals.emoteset = [0] self.mock_globals.globalEmotesCache = self.cache self.tags = IrcMessageTags(IrcMessageTags.parseTags( 'badges=broadcaster/1;color=;display-name=BotGotsThis;' 'emote-sets=0;mod=0;subscriber=0;turbo=0;user-type=')) self.channel = Mock(spec=Channel) self.channel.isMod = False self.channel.isSubscriber = False patcher = patch('lib.ircmessage.userstate.handle_emote_set') self.addCleanup(patcher.stop) self.mock_handle_emote = patcher.start()
def test_mutable_mapping(self): tags = IrcMessageTags({'Kappa': 'KappaPride'}) self.assertEqual(tags.pop('Kappa'), 'KappaPride') self.assertEqual(len(tags), 0) self.assertRaises(KeyError, tags.pop, 'Kappa') self.assertEqual(tags.setdefault('Kappa', 'KappaHD'), 'KappaHD') self.assertEqual(tags.setdefault('Kappa', 'KappePride'), 'KappaHD') self.assertEqual(tags.popitem(), ('Kappa', 'KappaHD')) self.assertRaises(KeyError, tags.popitem) tags.update(BibleThump=True) self.assertEqual(len(tags), 1) self.assertIn('BibleThump', tags)
def setUp(self): self.tags = IrcMessageTags() self.database = MagicMock(spec=DatabaseMain) self.database.__aenter__.return_value = self.database self.database.__aexit__.return_value = False self.send = Mock(spec=send) patcher = patch('bot.utils.joinChannel', autospec=True) self.addCleanup(patcher.stop) self.mock_join = patcher.start() patcher = patch.object(DatabaseMain, 'acquire') self.addCleanup(patcher.stop) self.mock_database = patcher.start() self.mock_database.return_value = self.database
def setUp(self): self.tags = IrcMessageTags() self.tags['badges'] = '' self.tags['color'] = '' self.tags['display-name'] = 'BotGotsThis' self.tags['user-id'] = '1' self.tags['user-type'] = '' self.tags['message-id'] = '1' self.tags['thread-id'] = '1' self.user = '******' patcher = patch('bot.config') self.addCleanup(patcher.stop) self.mock_config = patcher.start() self.mock_config.owner = 'megotsthis'
def setUp(self): self.tags = IrcMessageTags() self.tags['badges'] = '' self.tags['color'] = '' self.tags['display-name'] = 'BotGotsThis' self.tags['mod'] = '0' self.tags['room-id'] = '1' self.tags['subscriber'] = '0' self.tags['user-id'] = '1' self.tags['user-type'] = '' self.user = '******' self.channel = Mock(spec=Channel) self.channel.channel = 'mebotsthis' self.channel.isMod = False patcher = patch('bot.config') self.addCleanup(patcher.stop) self.mock_config = patcher.start() self.mock_config.botnick = 'botgotsthis' self.mock_config.owner = 'megotsthis'
def setUp(self): self.now = datetime(2000, 1, 1) self.tags = IrcMessageTags() self.channel = Mock(spec=Channel) self.channel.channel = 'botgotsthis' self.channel.sessionData = {} self.data = Mock(spec=CacheStore) self.data.hasFeature.side_effect = lambda c, f: f in self.features self.database = MagicMock(spec=DatabaseMain) self.database.__aenter__.return_value = self.database self.database.__aexit__.return_value = False self.features = [] self.database.hasFeature.side_effect = lambda c, f: f in self.features self.permissionSet = { 'owner': False, 'manager': False, 'inOwnerChannel': False, 'staff': False, 'admin': False, 'globalMod': False, 'broadcaster': False, 'moderator': False, 'subscriber': False, 'permitted': False, 'chatModerator': False, 'bannable': True, } self.permissions = MagicMock(spec=ChatPermissionSet) self.permissions.inOwnerChannel = False self.permissions.__getitem__.side_effect = \ lambda k: self.permissionSet[k] self.args = ChatCommandArgs(self.data, self.channel, self.tags, 'botgotsthis', Message(''), self.permissions, self.now) patcher = patch.object(DatabaseMain, 'acquire') self.addCleanup(patcher.stop) self.mock_database = patcher.start() self.mock_database.return_value = self.database
def test_set_item_list(self): tags = IrcMessageTags() with self.assertRaises(TypeError): tags['Kappa'] = []
def setUp(self): self.tags = IrcMessageTags(IrcMessageTags.parseTags( 'turbo=1;display-name=BotGotsThis;badges=;emotes=;user-id=1;' 'message-id=1;thread-id=1;user-type=;color=#FFFFFF')) self.now = datetime(2000, 1, 1)
def test_delete_item(self): tags = IrcMessageTags({'Kappa': True}) self.assertEqual(len(tags), 1) del tags['Kappa'] self.assertEqual(len(tags), 0) self.assertNotIn('Kappa', tags)
def test_set_item_str(self): tags = IrcMessageTags() tags['Kappa'] = 'KappaHD' self.assertEqual(tags['Kappa'], 'KappaHD')
def test_set_item_false(self): tags = IrcMessageTags() with self.assertRaises(ValueError): tags['Kappa'] = False