예제 #1
0
def pre_irc_client():
    # Use fixture JSON for API client setup
    http = apiclient.http.HttpMock(
        fixture_file('google-discovery-youtube-v3.json'),
        {'status': '200'})
    with patch.object(Youtube, 'http', wraps=http):
        yield
예제 #2
0
 def test_ids(self):
     for vid_id, status, fixture, expected in json_test_cases:
         http = HttpMock(fixture_file(fixture), {'status': status})
         with self.subTest(vid_id=vid_id), patch.object(self.youtube, 'http', wraps=http):
             if expected is YoutubeError:
                 self.assertRaises(YoutubeError, self.youtube._yt, urlparse.urlparse(vid_id))
             else:
                 self.assertEqual(self.youtube._yt(urlparse.urlparse(vid_id)), expected)
예제 #3
0
 def test_ids(self, bot_helper, vid_id, status, fixture, expected):
     http = apiclient.http.HttpMock(fixture_file(fixture), {'status': status})
     with patch.object(bot_helper['youtube'], 'http', wraps=http):
         if expected is YoutubeError:
             with pytest.raises(YoutubeError):
                 bot_helper['youtube']._yt(urlparse.urlparse(vid_id))
         else:
             assert bot_helper['youtube']._yt(urlparse.urlparse(vid_id)) == expected
예제 #4
0
    def setUp(self):
        # Use fixture JSON for API client setup
        http = HttpMock(fixture_file('google-discovery-youtube-v3.json'),
                        {'status': '200'})
        with patch.object(Youtube, 'http', wraps=http):
            super().setUp()

        # Make sure URLs don't try to fall back to the default handler
        self.linkinfo.register_exclude(lambda url: url.netloc in {"m.youtube.com",
                                                                  "youtu.be",
                                                                  "www.youtube.com"})
예제 #5
0
 def test_integration(self, bot_helper, vid_id, status, fixture, response, url):
     http = apiclient.http.HttpMock(fixture_file(fixture), {'status': status})
     with patch.object(bot_helper['youtube'], 'http', wraps=http):
         url = url.format(vid_id)
         result = bot_helper['linkinfo'].get_link_info(url)
         if response is None or response is YoutubeError:
             assert result.is_error
         else:
             for key in response:
                 if key == "link":
                     continue
                 assert response[key] in result.text
예제 #6
0
 def test_integration(self):
     url_types = {"https://www.youtube.com/watch?v={}",
                  "http://m.youtube.com/details?v={}",
                  "https://www.youtube.com/v/{}",
                  "http://www.youtube.com/watch?v={}&feature=youtube_gdata_player",
                  "http://youtu.be/{}"}
     for vid_id, status, fixture, response in json_test_cases:
         for url in url_types:
             http = HttpMock(fixture_file(fixture), {'status': status})
             with self.subTest(vid_id=vid_id, url=url), patch.object(self.youtube, 'http', wraps=http):
                 url = url.format(vid_id)
                 result = self.linkinfo.get_link_info(url)
                 if response is None or response is YoutubeError:
                     self.assertTrue(result.is_error)
                 else:
                     for key in response:
                         if key == "link":
                             continue
                         self.assertIn(response[key], result.text)
예제 #7
0
 def setUp(self):
     # Use fixture JSON for API client setup
     http = HttpMock(fixture_file('google-discovery-youtube-v3.json'),
                     {'status': '200'})
     with patch.object(Youtube, 'http', wraps=http):
         super().setUp()