def test_prioirity_top_two_2(self):
     msg1 = ChatMessage(self.bgt_channel, 'BudBlast')
     msg2 = ChatMessage(self.bgt_channel, 'BudStar')
     self.queue._chatQueues[0].append(msg1)
     self.queue._chatQueues[2].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
 def test_prioirity_top_two_1(self):
     msg1 = ChatMessage(self.bgt_channel, 'CorgiDerp')
     msg2 = ChatMessage(self.bgt_channel, 'OhMyDog')
     self.queue._chatQueues[0].append(msg1)
     self.queue._chatQueues[1].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
 def test_double(self):
     msg1 = ChatMessage(self.bgt_channel, 'PJSalt')
     msg2 = ChatMessage(self.mgt_channel, 'PJSugar')
     self.queue._chatQueues[0].append(msg1)
     self.queue._chatQueues[0].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
 def test_prioirity_top_two_3(self):
     msg1 = ChatMessage(self.bgt_channel, 'Kippa')
     msg2 = ChatMessage(self.bgt_channel, 'Keepo')
     self.queue._chatQueues[1].append(msg1)
     self.queue._chatQueues[2].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
 def test_prioirity_nonmod_mod(self):
     msg1 = ChatMessage(self.bgt_channel, 'KAPOW')
     msg2 = ChatMessage(self.mbt_channel, 'FunRun')
     self.queue._chatQueues[0].append(msg1)
     self.queue._chatQueues[1].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
 def test_clearChat_multiple(self):
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, '0'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, '1'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, '2'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, '3'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, '4'))
     self.queue.clearChat(self.bgt_channel)
     self.assertFalse(any(self.queue._chatQueues))
 def test_nonmod_semifull(self):
     self.queue._chatSent.extend(self.now for i in range(1))
     msg1 = ChatMessage(self.bgt_channel, 'KAPOW')
     msg2 = ChatMessage(self.mbt_channel, 'FunRun')
     self.queue._chatQueues[1].append(msg1)
     self.queue._chatQueues[1].append(msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg2)
     self.assertIs(self.queue._getChatMessage(self.now), msg1)
 def test_full(self):
     self.queue._chatSent.extend(self.now for i in range(5))
     self.queue._whisperSent.extend(self.now for i in range(5))
     self.queue._chatQueues[0].append(
         ChatMessage(self.bgt_channel, 'PogChamp'))
     self.queue._chatQueues[1].append(
         ChatMessage(self.mgt_channel, 'Kreygasm'))
     self.queue._chatQueues[2].append(ChatMessage(self.mbt_channel,
                                                  'Kappa'))
     self.assertIsNone(self.queue._getChatMessage(self.now))
     self.assertFalse(self.queue._lowQueueRecent)
     self.assertFalse(self.queue._publicTime)
 def test_flush_writes_exception(
         self, mock_queue_write, mock_popWhisper, mock_popChat, mock_log,
         mock_globals):
     mock_globals.groupChannel = self.channel
     mock_popWhisper.side_effect = [
         WhisperMessage('botgotsthis', 'Kappa\n'),
         WhisperMessage('megotsthis', 'KappaPride\n'),
         None]
     mock_popChat.side_effect = [
         ChatMessage(self.channel, 'KappaRoss\n'),
         ChatMessage(self.channel, 'KappaClaus\n'),
         None]
     self.connection.flush_writes()
     self.assertFalse(mock_queue_write.called)
     self.assertTrue(mock_log.call_count, 4)
 def test_lowest_priority(self):
     msg = ChatMessage(self.bgt_channel, 'ResidentSleeper')
     self.queue._chatQueues[-1].append(msg)
     self.assertIs(self.queue._getChatMessage(self.now), msg)
     self.assertEqual(self.queue._publicTime[msg.channel.channel],
                      self.queue._publicTime.default_factory())
     self.assertIn(msg.channel.channel, self.queue._lowQueueRecent)
 def test_single_mod(self):
     msg = ChatMessage(self.mgt_channel, 'Kreygasm')
     self.queue._chatQueues[0].append(msg)
     self.assertIs(self.queue._getChatMessage(self.now), msg)
     self.assertFalse(self.queue._lowQueueRecent)
     self.assertEqual(self.queue._publicTime[msg.channel.channel],
                      self.queue._publicTime.default_factory())
     self.assertIsNone(self.queue._getChatMessage(self.now))
 def test_popChat(self, mock_getChatMessage, mock_now):
     msg = ChatMessage(self.bgt_channel,
                       'TBTacoLeft TBCheesePull TBTacoRight')
     mock_getChatMessage.return_value = msg
     now = datetime(2000, 1, 1, 0, 0, 0)
     mock_now.return_value = now
     self.assertIs(self.queue.popChat(), msg)
     self.assertEqual(self.queue._chatSent, [now])
 def test_lowest_priority_multiple(self):
     msgs1 = [ChatMessage(self.bgt_channel, 'KappaRoss') for _ in range(2)]
     msgs2 = [ChatMessage(self.mgt_channel, 'KappaPride') for _ in range(2)]
     self.queue._chatQueues[-1].append(msgs1[0])
     self.queue._chatQueues[-1].extend(msgs2)
     self.queue._chatQueues[-1].append(msgs1[1])
     self.assertIs(self.queue._getChatMessage(self.now), msgs1[0])
     self.assertEqual(list(self.queue._lowQueueRecent),
                      [self.bgt_channel.channel])
     self.assertIs(self.queue._getChatMessage(self.now), msgs2[0])
     self.assertEqual(list(self.queue._lowQueueRecent),
                      [self.bgt_channel.channel, self.mgt_channel.channel])
     self.assertIs(self.queue._getChatMessage(self.now), msgs1[1])
     self.assertEqual(list(self.queue._lowQueueRecent),
                      [self.mgt_channel.channel, self.bgt_channel.channel])
     self.assertIs(self.queue._getChatMessage(self.now), msgs2[1])
     self.assertEqual(list(self.queue._lowQueueRecent),
                      [self.bgt_channel.channel, self.mgt_channel.channel])
 def test_flush_writes(self, mock_queue_write, mock_popWhisper,
                       mock_popChat, mock_globals):
     mock_globals.groupChannel = self.channel
     mock_popWhisper.side_effect = [
         WhisperMessage('botgotsthis', 'Kappa'),
         WhisperMessage('megotsthis', 'KappaPride'),
         None]
     mock_popChat.side_effect = [
         ChatMessage(self.channel, 'KappaRoss'),
         ChatMessage(self.channel, 'KappaClaus'),
         None]
     self.connection.flush_writes()
     self.assertEqual(mock_queue_write.call_count, 4)
     self.assertTrue(len([m for m in mock_queue_write.call_args_list
                          if m[0][1].command == 'PRIVMSG']), 4)
     self.assertTrue(len([m for m in mock_queue_write.call_args_list
                          if 'channel' in m[1]
                          and m[1]['channel'] is self.channel]), 2)
     self.assertTrue(len([m for m in mock_queue_write.call_args_list
                          if 'whisper' in m[1]
                          and m[1]['whisper'].nick in ['megotsthis',
                                                       'botgotsthis']]), 2)
 def test_single_notmod(self):
     msg = ChatMessage(self.mbt_channel, 'BionicBunion')
     self.queue._chatQueues[0].append(msg)
     self.assertIs(self.queue._getChatMessage(self.now), msg)
     self.assertFalse(self.queue._lowQueueRecent)
     self.assertEqual(self.queue._publicTime[msg.channel.channel], self.now)
 def test_clearChat_single(self):
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel,
                                                  'Kappa'))
     self.queue.clearChat(self.bgt_channel)
     self.assertFalse(any(self.queue._chatQueues))
 def test_clearAllChat(self):
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'a'))
     self.queue._chatQueues[0].append(ChatMessage(self.mgt_channel, 'b'))
     self.queue._chatQueues[0].append(ChatMessage(self.mbt_channel, 'c'))
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'd'))
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'e'))
     self.queue._chatQueues[1].append(ChatMessage(self.mgt_channel, 'f'))
     self.queue._chatQueues[1].append(ChatMessage(self.mbt_channel, 'g'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'h'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'i'))
     self.queue._chatQueues[1].append(ChatMessage(self.mbt_channel, 'j'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'k'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'l'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'm'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'n'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'o'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'p'))
     self.queue.clearAllChat()
     self.assertFalse(any(self.queue._chatQueues))
 def test_clearChat_mixing(self):
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'a'))
     self.queue._chatQueues[0].append(ChatMessage(self.mgt_channel, 'b'))
     self.queue._chatQueues[0].append(ChatMessage(self.mbt_channel, 'c'))
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'd'))
     self.queue._chatQueues[0].append(ChatMessage(self.bgt_channel, 'e'))
     self.queue._chatQueues[1].append(ChatMessage(self.mgt_channel, 'f'))
     self.queue._chatQueues[1].append(ChatMessage(self.mbt_channel, 'g'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'h'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'i'))
     self.queue._chatQueues[1].append(ChatMessage(self.mbt_channel, 'j'))
     self.queue._chatQueues[1].append(ChatMessage(self.bgt_channel, 'k'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'l'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'm'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'n'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'o'))
     self.queue._chatQueues[2].append(ChatMessage(self.bgt_channel, 'p'))
     self.queue.clearChat(self.bgt_channel)
     self.assertEqual(len(self.queue._chatQueues[0]), 2)
     self.assertEqual(len(self.queue._chatQueues[1]), 3)
     self.assertFalse(self.queue._chatQueues[2])
     self.assertIs(self.queue._chatQueues[0][0].channel, self.mgt_channel)
     self.assertIs(self.queue._chatQueues[0][1].channel, self.mbt_channel)
     self.assertIs(self.queue._chatQueues[1][0].channel, self.mgt_channel)
     self.assertIs(self.queue._chatQueues[1][1].channel, self.mbt_channel)
     self.assertIs(self.queue._chatQueues[1][2].channel, self.mbt_channel)
 def test_lowest_priority_nonmod(self):
     msg = ChatMessage(self.mbt_channel, 'OneHand')
     self.queue._chatQueues[-1].append(msg)
     self.assertIs(self.queue._getChatMessage(self.now), msg)
     self.assertFalse(self.queue._lowQueueRecent)
     self.assertEqual(self.queue._publicTime[msg.channel.channel], self.now)