def setUp(self):
     self.queue = MessagingQueue()
     connection = ConnectionHandler('Twitch.TV', 'irc.twitch.tv', 6667)
     self.bgt_channel = Channel('botgotsthis', connection, -math.inf)
     self.bgt_channel.isMod = False
     self.mgt_channel = Channel('megotsthis', connection, -math.inf)
     self.mgt_channel.isMod = True
     self.mbt_channel = Channel('mebotsthis', connection, -math.inf)
     self.mbt_channel.isMod = False
    async def setUp(self):
        self.connection = connection.ConnectionHandler(
            'Kappa', 'irc.twitch.tv', 6667)
        self.channel = Channel('botgotsthis', self.connection)
        self.whisper = WhisperMessage('botgotsthis', 'Kappa')

        patcher = patch('bot.config', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_config = patcher.start()
        self.mock_config.botnick = 'botgotsthis'

        patcher = patch('bot.utils.now', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_now = patcher.start()
        self.now = datetime(2000, 1, 1, 0, 0, 0)
        self.mock_now.return_value = self.now

        patcher = patch('bot.coroutine.join.disconnected')
        self.addCleanup(patcher.stop)
        self.mock_disconnected = patcher.start()

        with patch('asyncio.open_connection') as mock_connection,\
                patch('sys.stdout', new_callable=StringIO),\
                patch.object(connection.ConnectionHandler, 'login'):
            self.mock_transport = Mock(spec=asyncio.Transport)
            self.mock_reader = Mock(asyncio.StreamReader)
            self.mock_writer = Mock(asyncio.StreamWriter)
            self.mock_writer.transport = self.mock_transport
            mock_connection.return_value = self.mock_reader, self.mock_writer
            await self.connection.connect()
Example #3
0
 def test_joinChannel_existing_channel(self, mock_globals):
     mock_globals.cluster = Mock(spec=connection.ConnectionHandler)
     mock_globals.channels = {
         'botgotsthis': Channel('botgotsthis', mock_globals.cluster, 1)
     }
     self.assertIs(utils.joinChannel('botgotsthis', 0), False)
     self.assertIn('botgotsthis', mock_globals.channels)
     self.assertEqual(mock_globals.channels['botgotsthis'].joinPriority, 0)
    def setUp(self):
        self.connection = connection.ConnectionHandler(
            'Kappa', 'irc.twitch.tv', 6667)
        self.channel = Channel('botgotsthis', self.connection)
        self.whisper = WhisperMessage('botgotsthis', 'Kappa')

        self.mock_transport = Mock(spec=asyncio.Transport)
        self.mock_reader = Mock(asyncio.StreamReader)
        self.mock_writer = Mock(asyncio.StreamWriter)
        self.mock_writer.transort = self.mock_transport
Example #5
0
 def test_getLowestPriority(self):
     channels = {
         'botgotsthis': Channel('botgotsthis', self.connection, -math.inf),
         'megotsthis': Channel('megotsthis', self.connection, 0),
         'mebotsthis': Channel('mebotsthis', self.connection, math.inf)
         }
     notJoined = set(channels.keys())
     channel = bot.coroutine.join._get_join_with_lowest_priority(channels,
                                                                 notJoined)
     self.assertEqual(channel, 'botgotsthis')
     notJoined.discard(channel)
     channel = bot.coroutine.join._get_join_with_lowest_priority(channels,
                                                                 notJoined)
     self.assertEqual(channel, 'megotsthis')
     notJoined.discard(channel)
     channel = bot.coroutine.join._get_join_with_lowest_priority(channels,
                                                                 notJoined)
     self.assertEqual(channel, 'mebotsthis')
     notJoined.discard(channel)
     self.assertIsNone(
         bot.coroutine.join._get_join_with_lowest_priority(channels,
                                                           notJoined))
Example #6
0
    def setUp(self):
        self.connection = ConnectionHandler('Twitch', 'irc.twitch.tv', 6667)
        self.channel = Channel('botgotsthis', self.connection)
        self.connection._channels[self.channel.channel] = self.channel

        patcher = patch('bot.globals', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_globals = patcher.start()
        self.mock_globals.cluster = self.connection

        patcher = patch('bot.coroutine.join._joinTimes')
        self.addCleanup(patcher.stop)
        patcher.start()
        bot.coroutine.join._joinTimes = deque()

        patcher = patch('bot.coroutine.join._channelJoined')
        self.addCleanup(patcher.stop)
        patcher.start()
        bot.coroutine.join._channelJoined = set()
 def setUp(self):
     self.connection = connection.ConnectionHandler(
         'Kappa', 'irc.twitch.tv', 6667)
     self.channel = Channel('botgotsthis', self.connection)
     self.whisper = WhisperMessage('botgotsthis', 'Kappa')
Example #8
0
class TestChannel(unittest.TestCase):
    def setUp(self):
        self.connection = Mock(spec=ConnectionHandler)
        self.connection.messaging = Mock(spec=MessagingQueue)
        self.channel = Channel('botgotsthis', self.connection)

    def test_constructor_name_none(self):
        self.assertRaises(TypeError, Channel, None, self.connection)

    def test_constructor_name_bytes(self):
        self.assertRaises(TypeError, Channel, b'', self.connection)

    def test_constructor_socket_none(self):
        self.assertRaises(TypeError, Channel, 'botgotsthis', None)

    def test_constructor_name_empty(self):
        self.assertRaises(ValueError, Channel, '', self.connection)

    def test_channel(self):
        self.assertEqual(self.channel.channel, 'botgotsthis')

    def test_ircChannel(self):
        self.assertEqual(self.channel.ircChannel, '#botgotsthis')

    def test_socket(self):
        self.assertIs(self.channel.connection, self.connection)

    def test_isMod(self):
        self.assertIs(self.channel.isMod, False)

    def test_isMod_true(self):
        self.channel.isMod = True
        self.assertIs(self.channel.isMod, True)

    def test_isMod_int(self):
        self.channel.isMod = 1
        self.assertIs(self.channel.isMod, True)

    def test_isSubscriber(self):
        self.assertIs(self.channel.isSubscriber, False)

    def test_isSubscriber_true(self):
        self.channel.isSubscriber = True
        self.assertIs(self.channel.isSubscriber, True)

    def test_isSubscriber_int(self):
        self.channel.isSubscriber = 1
        self.assertIs(self.channel.isSubscriber, True)

    def test_ircUsers(self):
        self.assertIsInstance(self.channel.ircUsers, MutableSet)
        self.assertFalse(self.channel.ircUsers)
        self.channel.ircUsers.add('botgotsthis')
        self.assertIn('botgotsthis', self.channel.ircUsers)

    def test_ircUsers_set(self):
        with self.assertRaises(AttributeError):
            self.channel.ircUsers = set()

    def test_ircOps(self):
        self.assertIsInstance(self.channel.ircOps, MutableSet)
        self.assertFalse(self.channel.ircOps)
        self.channel.ircOps.add('botgotsthis')
        self.assertIn('botgotsthis', self.channel.ircOps)

    def test_ircOps_set(self):
        with self.assertRaises(AttributeError):
            self.channel.ircOps = set()

    def test_joinPriority(self):
        self.assertEqual(self.channel.joinPriority, math.inf)

    def test_joinPriority_set(self):
        self.channel.joinPriority = 0
        self.assertEqual(self.channel.joinPriority, 0)

    def test_joinPriority_set_str(self):
        self.channel.joinPriority = '-15'
        self.assertEqual(self.channel.joinPriority, -15)

    def test_joinPriority_set_list(self):
        with self.assertRaises(TypeError):
            self.channel.joinPriority = []

    def test_sessionData(self):
        self.assertIsInstance(self.channel.sessionData, MutableMapping)
        self.assertFalse(self.channel.sessionData)
        self.channel.sessionData['Kappa'] = 'PogChamp'
        self.assertIn('Kappa', self.channel.sessionData)
        self.assertEqual(self.channel.sessionData['Kappa'], 'PogChamp')

    def test_sessionData_set(self):
        with self.assertRaises(AttributeError):
            self.channel.sessionData = {}

    def test_streamingSince(self):
        self.assertIsNone(self.channel.streamingSince)

    def test_streamingSince_set_none(self):
        self.channel.streamingSince = None
        self.assertIsNone(self.channel.streamingSince)

    def test_streamingSince_set_datetime(self):
        timestamp = datetime(2000, 1, 1)
        self.channel.streamingSince = timestamp
        self.assertEqual(self.channel.streamingSince, timestamp)

    def test_streamingSince_set_list(self):
        with self.assertRaises(TypeError):
            self.channel.streamingSince = []

    def test_isStreaming(self):
        self.assertIs(self.channel.isStreaming, False)

    def test_isStreaming_true(self):
        timestamp = datetime(2000, 1, 1)
        self.channel.streamingSince = timestamp
        self.assertIs(self.channel.isStreaming, True)

    def test_twitchCache(self):
        self.assertEqual(self.channel.twitchCache, datetime.min)

    def test_twitchCache_set_none(self):
        with self.assertRaises(TypeError):
            self.channel.twitchCache = None

    def test_twitchCache_set(self):
        timestamp = datetime(2000, 1, 1)
        self.channel.twitchCache = timestamp
        self.assertEqual(self.channel.twitchCache, timestamp)

    def test_twitchStatus(self):
        self.assertEqual(self.channel.twitchStatus, '')

    def test_twitchStatus_set_none(self):
        self.channel.twitchStatus = None
        self.assertIsNone(self.channel.twitchStatus)

    def test_twitchStatus_set_bytes(self):
        with self.assertRaises(TypeError):
            self.channel.twitchStatus = b''

    def test_twitchStatus_set(self):
        self.channel.twitchStatus = 'Kappa'
        self.assertEqual(self.channel.twitchStatus, 'Kappa')

    def test_twitchGame(self):
        self.assertEqual(self.channel.twitchGame, '')

    def test_twitchGame_set_none(self):
        self.channel.twitchGame = None
        self.assertIsNone(self.channel.twitchGame)

    def test_twitchGame_set_bytes(self):
        with self.assertRaises(TypeError):
            self.channel.twitchGame = b''

    def test_twitchGame_set(self):
        self.channel.twitchGame = 'Kappa'
        self.assertEqual(self.channel.twitchGame, 'Kappa')

    def test_serverCheck(self):
        self.assertEqual(self.channel.serverCheck, datetime.min)

    def test_serverCheck_set_none(self):
        with self.assertRaises(TypeError):
            self.channel.serverCheck = None

    def test_serverCheck_set(self):
        timestamp = datetime(2000, 1, 1)
        self.channel.serverCheck = timestamp
        self.assertEqual(self.channel.serverCheck, timestamp)

    def test_onJoin(self):
        self.channel.ircUsers.add('botgotsthis')
        self.channel.ircOps.add('botgotsthis')
        self.channel.onJoin()
        self.assertFalse(self.channel.ircUsers)
        self.assertFalse(self.channel.ircOps)

    def test_part(self):
        self.channel.part()
        self.connection.part_channel.assert_called_once_with(self.channel)
        self.connection.messaging.clearChat.assert_called_once_with(
            self.channel)

    def test_clear(self):
        self.channel.clear()
        self.connection.messaging.clearChat.assert_called_once_with(
            self.channel)

    def test_send(self):
        self.channel.send('Kappa')
        self.connection.messaging.sendChat.assert_called_once_with(
            self.channel, 'Kappa', 1)

    def test_send_iterable_priority(self):
        messages = [
            'Kappa', 'Keepo', 'KappaHD', 'KappaPride', 'KappaRoss',
            'KappaClaus'
        ]
        self.channel.send(messages, 0)
        self.connection.messaging.sendChat.assert_called_once_with(
            self.channel, messages, 0)
Example #9
0
 def setUp(self):
     self.connection = Mock(spec=ConnectionHandler)
     self.connection.messaging = Mock(spec=MessagingQueue)
     self.channel = Channel('botgotsthis', self.connection)