示例#1
0
 def test_instagram_oembed_only_accepts_new_url_patterns(self):
     finder = InstagramOEmbedFinder()
     self.assertTrue(
         finder.accept(
             "https://www.instagram.com/p/CHeRxmnDSYe/?utm_source=ig_embed")
     )
     self.assertFalse(
         finder.accept(
             "https://instagr.am/p/CHeRxmnDSYe/?utm_source=ig_embed"))
示例#2
0
 def test_instagram_oembed_return_values(self, urlopen):
     urlopen.return_value = self.dummy_response
     result = InstagramOEmbedFinder(
         app_id='123',
         app_secret='abc').find_embed("https://instagr.am/p/CHeRxmnDSYe/")
     self.assertEqual(
         result, {
             'type': 'something',
             'title': 'test_title',
             'author_name': 'test_author',
             'provider_name': 'Instagram',
             'thumbnail_url': 'test_thumbail_url',
             'width': 'test_width',
             'height': 'test_height',
             'html':
             '<blockquote class="instagram-media">Content</blockquote>'
         })
     # check that a request was made with the expected URL / authentication
     request = urlopen.call_args[0][0]
     # check that a request was made with the expected URL / authentication
     request = urlopen.call_args[0][0]
     self.assertEqual(
         request.get_full_url(),
         "https://graph.facebook.com/v9.0/instagram_oembed?url=https%3A%2F%2Finstagr.am%2Fp%2FCHeRxmnDSYe%2F&format=json"
     )
     self.assertEqual(request.get_header('Authorization'), "Bearer 123|abc")
示例#3
0
 def test_instagram_oembed_return_values(self, urlopen):
     urlopen.return_value = self.dummy_response
     result = InstagramOEmbedFinder(
         app_id="123",
         app_secret="abc").find_embed("https://instagr.am/p/CHeRxmnDSYe/")
     self.assertEqual(
         result,
         {
             "type": "something",
             "title": "test_title",
             "author_name": "test_author",
             "provider_name": "Instagram",
             "thumbnail_url": "test_thumbail_url",
             "width": "test_width",
             "height": "test_height",
             "html":
             '<blockquote class="instagram-media">Content</blockquote>',
         },
     )
     # check that a request was made with the expected URL / authentication
     request = urlopen.call_args[0][0]
     self.assertEqual(
         request.get_full_url(),
         "https://graph.facebook.com/v11.0/instagram_oembed?url=https%3A%2F%2Finstagr.am%2Fp%2FCHeRxmnDSYe%2F&format=json",
     )
     self.assertEqual(request.get_header("Authorization"), "Bearer 123|abc")
示例#4
0
 def test_instagram_failed_request(self):
     config = {"side_effect": URLError(reason="Testing error handling")}
     with patch.object(urllib.request, "urlopen", **config):
         self.assertRaises(
             EmbedNotFoundException,
             InstagramOEmbedFinder().find_embed,
             "https://instagr.am/p/CHeRxmnDSYe/",
         )
示例#5
0
 def test_instagram_request_not_found(self):
     err = HTTPError("https://instagr.am/p/badrequest/",
                     code=404,
                     msg='Not Found',
                     hdrs={},
                     fp=None)
     config = {'side_effect': err}
     with patch.object(urllib.request, 'urlopen', **config):
         self.assertRaises(EmbedNotFoundException,
                           InstagramOEmbedFinder().find_embed,
                           "https://instagr.am/p/CHeRxmnDSYe/")
示例#6
0
 def test_instagram_request_denied_401(self):
     err = HTTPError("https://instagr.am/p/CHeRxmnDSYe/",
                     code=401,
                     msg='invalid credentials',
                     hdrs={},
                     fp=None)
     config = {'side_effect': err}
     with patch.object(urllib.request, 'urlopen', **config):
         self.assertRaises(AccessDeniedInstagramOEmbedException,
                           InstagramOEmbedFinder().find_embed,
                           "https://instagr.am/p/CHeRxmnDSYe/")