Exemple #1
0
 async def test_add_quote(self):
     self.assertEqual(
         await database.addQuote('megotsthis', 'botgotsthis', 'FrankerZ'),
         2)
     self.assertCountEqual(await self.rows('SELECT * FROM quotes'),
                           [(1, 'megotsthis', 'Kappa'),
                            (2, 'megotsthis', 'FrankerZ'),
                            ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_tags'),
                           [(1, 'Keepo'),
                            ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_history'),
                           [(1, 2, TypeMatch(datetime), 'megotsthis',
                             'FrankerZ', 'botgotsthis')])
Exemple #2
0
 async def test_copy_quote_no_tags(self):
     await self.execute('''DELETE FROM quotes_tags''')
     self.assertEqual(
         await database.copyQuote('megotsthis', 'mebotsthis', 'botgotsthis',
                                  1),
         2)
     self.assertCountEqual(await self.rows('SELECT * FROM quotes'),
                           [(1, 'megotsthis', 'Kappa'),
                            (2, 'mebotsthis', 'Kappa'),
                            ])
     self.assertEqual(await self.rows('SELECT * FROM quotes_tags'), [])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_history'),
                           [(1, 2, TypeMatch(datetime), 'mebotsthis',
                             'Kappa', 'botgotsthis')])
Exemple #3
0
 async def test_update_quote(self):
     self.assertEqual(
         await database.updateQuote('megotsthis', 'botgotsthis', 1,
                                    'FrankerZ'),
         True)
     self.assertCountEqual(await self.rows('SELECT * FROM quotes'),
                           [(1, 'megotsthis', 'FrankerZ'),
                            ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_tags'),
                           [(1, 'Keepo'),
                            ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_history'),
                           [(1, 1, TypeMatch(datetime), 'megotsthis',
                             'FrankerZ', 'botgotsthis')])
 async def test_copy_quote(self):
     self.assertEqual(
         await database.copyQuote('megotsthis', 'mebotsthis', 'botgotsthis',
                                  1), 2)
     self.assertCountEqual(await self.rows('SELECT * FROM quotes'), [
         (1, 'megotsthis', 'Kappa', self.doc_kappa),
         (2, 'mebotsthis', 'Kappa', self.doc_kappa),
     ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_tags'), [
         (1, 'Keepo'),
         (2, 'Keepo'),
     ])
     self.assertCountEqual(await self.rows('SELECT * FROM quotes_history'),
                           [(1, 2, TypeMatch(datetime), 'mebotsthis',
                             'Kappa', 'botgotsthis')])
 async def test_plain_field_plain(self):
     self.mock_split.return_value = [
         CustomFieldParts('Kappa ', 'field', 'format', 'prefix', 'suffix',
                          'param', 'default', 'original'),
         CustomFieldParts(' Kappa', None, None, None, None, None, None,
                          None)
     ]
     self.assertEqual(
         await library.create_messages(self.command, self.args),
         ['Kappa default Kappa'])
     self.data.hasFeature.assert_called_once_with('botgotsthis',
                                                  'textconvert')
     self.mock_split.assert_called_once_with('Kappa KappaRoss KappaPride')
     self.mock_convert.assert_called_once_with(TypeMatch(CustomFieldArgs))
     self.mock_format.assert_called_once_with('default', 'format', False)
Exemple #6
0
    async def test_delete_commanddisplay(self):
        now = datetime(2000, 1, 1)
        await self.execute(
            '''
INSERT INTO custom_commands VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
            ('botgotsthis', '', 'kappa', None, 'Kappa', 'botgotsthis', now,
             'botgotsthis', now))
        self.assertIs(
            await self.database.deleteCustomCommand('botgotsthis', '', 'Kappa',
                                                    'botgotsthis'), True)
        self.assertIsNone(await self.row('SELECT * FROM custom_commands'))
        self.assertEqual(
            await self.row('SELECT * FROM custom_commands_history'),
            (1, 'botgotsthis', '', 'kappa', 'Kappa', 'delete', None,
             'botgotsthis', TypeMatch(datetime)))
Exemple #7
0
    async def test_replace_existing(self):
        now = datetime(2000, 1, 1)
        await self.execute(
            '''
INSERT INTO custom_commands VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
            ('botgotsthis', '', 'kappa', None, 'Kappa', 'botgotsthis', now,
             'botgotsthis', now))
        self.assertIs(
            await
            self.database.replaceCustomCommand('botgotsthis', '', 'kappa',
                                               'KappaHD', 'botgotsthis'), True)
        self.assertEqual(
            await self.rows('SELECT * FROM custom_commands_history'),
            [(1, 'botgotsthis', '', 'kappa', None, 'replace', 'KappaHD',
              'botgotsthis', TypeMatch(datetime))])
 async def test_no_dns(self):
     self.data.twitch_num_followers.return_value = 0
     message = Message('twitch.tv')
     self.mock_session.get.side_effect = aiohttp.ClientConnectorError
     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.assertFalse(self.mock_except.called)
 async def test_field_field(self):
     self.mock_split.return_value = [
         CustomFieldParts('', 'field', 'format', 'prefix', 'suffix',
                          'param', 'default1', 'original'),
         CustomFieldParts('', 'field', 'format', 'prefix', 'suffix',
                          'param', 'default2', 'original'),
     ]
     self.assertEqual(
         await library.create_messages(self.command, self.args),
         ['default1default2'])
     self.data.hasFeature.assert_called_once_with('botgotsthis',
                                                  'textconvert')
     self.mock_split.assert_called_once_with('Kappa KappaRoss KappaPride')
     self.mock_convert.assert_has_calls([call(TypeMatch(CustomFieldArgs))] *
                                        2)
     self.assertEqual(self.mock_format.call_args_list, [
         call('default1', 'format', False),
         call('default2', 'format', False)
     ])
 async def test_same_domain(self):
     self.data.twitch_num_followers.return_value = 0
     message = Message('twitch.tv')
     self.mock_response.url = yarl.URL('http://twitch.tv')
     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.mock_compare.assert_called_once_with('http://twitch.tv',
                                               'http://twitch.tv',
                                               chat=self.channel,
                                               nick='megotsthis',
                                               timestamp=self.now)
     self.assertFalse(self.mock_handle.called)
     self.assertFalse(self.mock_except.called)
 async def test(self):
     self.assertIs(await library.leave('megotsthis', self.send), True)
     self.send.assert_called_once_with(StrContains('megotsthis', 'Bye'))
     self.mock_sleep.assert_called_once_with(TypeMatch(float))
     self.mock_part.assert_called_once_with('megotsthis')
Exemple #12
0
 async def test_record(self):
     await self.database.recordTimeout('botgotsthis', 'botgotsthis', None,
                                       'tests', None, None, None, None)
     self.assertEqual(await self.row('SELECT * FROM timeout_logs'),
                      (1, TypeMatch(datetime), 'botgotsthis', 'botgotsthis',
                       None, 'tests', None, None, None, None))
 async def test(self):
     self.assertIs(await exit.exit(self.send), True)
     self.assertIs(self.mock_globals.running, False)
     self.send.assert_called_once_with(StrContains('Goodbye'))
     self.mock_part.assert_called_once_with('botgotsthis')
     self.mock_sleep.assert_called_once_with(TypeMatch(float))
 async def test_remove_existing(self):
     self.assertIs(await self.database.removeBotManager('megotsthis'), True)
     self.assertIsNone(await self.row('SELECT * FROM bot_managers'))
     self.assertEqual(await self.row('SELECT * FROM bot_managers_log'),
                      (1, 'megotsthis', TypeMatch(datetime), 'remove'))
 async def test_add(self):
     self.assertIs(await self.database.addBotManager('mebotsthis'), True)
     self.assertEqual(await self.rows('SELECT * FROM bot_managers'),
                      [('megotsthis', ), ('mebotsthis', )])
     self.assertEqual(await self.row('SELECT * FROM bot_managers_log'),
                      (1, 'mebotsthis', TypeMatch(datetime), 'add'))