def setUp(self): super(ReadLinksTestCase, self).setUp() self.line_start = ":[email protected] PRIVMSG #psywerx " self.plugin = ReadLinks(bot=self.bot) self.say = self.plugin.bot.say self.video_response = {'seconds': '34227', 'rating': 'no rating', 'views': '385293', 'service': 'youtube', 'title': 'ASP 2014 J-Bay Open English Day 10'}
def __init__(self, bot): self.bot = bot # reference back to asynchat handler self.joined_channel = False self.usertrim = re.compile('[!+@]') self.bot.known_users = {} # dict of known users present in the channel self.plugins = [ PsywerxHistory(bot=bot), PsywerxKarma(bot=bot), PsywerxGroups(bot=bot), NSFWImageDetectorPlugin(bot=bot), ReadLinks(bot=bot), Uptime(bot=bot), ]
class ReadLinksTestCase(BasePluginTestCase): def setUp(self): super(ReadLinksTestCase, self).setUp() self.line_start = ":[email protected] PRIVMSG #psywerx " self.plugin = ReadLinks(bot=self.bot) self.say = self.plugin.bot.say self.video_response = {'seconds': '34227', 'rating': 'no rating', 'views': '385293', 'service': 'youtube', 'title': 'ASP 2014 J-Bay Open English Day 10'} def handle_message(self, line): self.plugin.handle_message('channel', 'nick', line, self.line_start + line) def test_sanity(self): self.handle_message('No tweet') self.assertFalse(self.plugin.bot.say.called) def _test_helper(self, msg, response): self.handle_message(msg) self.assertTrue(self.say.called) assert response in self.say.call_args[0][0].split('\n')[0] @patch("plugins.read_links.ReadLinks._get_name_text") def test_tweet_in_message(self, name_text): name_text.return_value = ("Smotko", '_') tweet = 'https://twitter.com/Smotko/status/469540345366450177' response = "@Smotko on Twitter says" self._test_helper(tweet, response) @patch("plugins.read_links.ReadLinks._get_name_text") def test_unicode(self, name_text): name_text.return_value = ("Smotko", u'☺') tweet = 'https://twitter.com/Smotko/status/501844653583659010' self._test_helper(tweet, 'Smotko') @patch("plugins.read_links.ReadLinks._get_youtube_info") def test_youtube_no_average(self, yt_info): yt_info.return_value = self.video_response msg = 'https://www.youtube.com/watch?v=jc8zZ9PbYVM' response = 'ASP 2014' self._test_helper(msg, response) @patch("plugins.read_links.ReadLinks._get_vimeo_info") def test_vimeo(self, vimeo_info): vimeo_info.return_value = self.video_response msg = ':O http://vimeo.com/102825514' response = 'ASP 2014' self._test_helper(msg, response) def test_all_video_responses(self): for vr in VIDEO_RESPONSES: self.bot.say(vr % self.video_response, "channel") assert 'ASP 2014' in self.say.call_args[0][0].split('\n')[0] def test_all_web_responses(self): for wr in WEB_RESPONSES: self.bot.say(wr % {'title': 'test___'}, "channel") assert 'test___' in self.say.call_args[0][0].split('\n')[0] # TODO: mock out the actual request def test_web(self): msg = 'This is a silly website http://smotko.si/' response = 'Smotko\'s Blog' self._test_helper(msg, response) def test_web_no_title(self): msg = 'This is a silly image https://i.imgur.com/ndsBKWn.jpg' self.handle_message(msg) self.assertFalse(self.say.called) def test_web_title_with_new_lines(self): msg = 'This page breaks http://www.theamountoffucksigive.com' self._test_helper(msg, 'amount')
class ReadLinksTestCase(BasePluginTestCase): def setUp(self): super(ReadLinksTestCase, self).setUp() self.line_start = ":[email protected] PRIVMSG #psywerx " self.plugin = ReadLinks(bot=self.bot) self.say = self.plugin.bot.say self.video_response = { 'seconds': '34227', 'rating': 'no rating', 'views': '385293', 'service': 'youtube', 'title': 'ASP 2014 J-Bay Open English Day 10' } def handle_message(self, line): self.plugin.handle_message('channel', 'nick', line, self.line_start + line) def test_sanity(self): self.handle_message('No tweet') self.assertFalse(self.plugin.bot.say.called) def _test_helper(self, msg, response): self.handle_message(msg) self.assertTrue(self.say.called) assert response in self.say.call_args[0][0].split('\n')[0] @patch("plugins.read_links.ReadLinks._get_name_text") def test_tweet_in_message(self, name_text): name_text.return_value = ("Smotko", '_') tweet = 'https://twitter.com/Smotko/status/469540345366450177' response = "@Smotko on Twitter says" self._test_helper(tweet, response) @patch("plugins.read_links.ReadLinks._get_name_text") def test_unicode(self, name_text): name_text.return_value = ("Smotko", u'☺') tweet = 'https://twitter.com/Smotko/status/501844653583659010' self._test_helper(tweet, 'Smotko') @patch("plugins.read_links.ReadLinks._get_youtube_info") def test_youtube_no_average(self, yt_info): yt_info.return_value = self.video_response msg = 'https://www.youtube.com/watch?v=jc8zZ9PbYVM' response = 'ASP 2014' self._test_helper(msg, response) @patch("plugins.read_links.ReadLinks._get_vimeo_info") def test_vimeo(self, vimeo_info): vimeo_info.return_value = self.video_response msg = ':O http://vimeo.com/102825514' response = 'ASP 2014' self._test_helper(msg, response) def test_all_video_responses(self): for vr in VIDEO_RESPONSES: self.bot.say(vr % self.video_response, "channel") assert 'ASP 2014' in self.say.call_args[0][0].split('\n')[0] def test_all_web_responses(self): for wr in WEB_RESPONSES: self.bot.say(wr % {'title': 'test___'}, "channel") assert 'test___' in self.say.call_args[0][0].split('\n')[0] # TODO: mock out the actual request def test_web(self): msg = 'This is a silly website http://smotko.si/' response = 'Smotko\'s Blog' self._test_helper(msg, response) def test_web_no_title(self): msg = 'This is a silly image https://i.imgur.com/ndsBKWn.jpg' self.handle_message(msg) self.assertFalse(self.say.called) def test_web_title_with_new_lines(self): msg = 'This page breaks http://www.theamountoffucksigive.com' self._test_helper(msg, 'amount')