Beispiel #1
0
 def test_facebook_oembed_return_values(self, urlopen):
     urlopen.return_value = self.dummy_response
     result = FacebookOEmbedFinder(
         app_id="123",
         app_secret="abc").find_embed("https://fb.watch/ABC123eew/")
     self.assertEqual(
         result,
         {
             "type": "something",
             "title": "test_title",
             "author_name": "test_author",
             "provider_name": "Facebook",
             "thumbnail_url": None,
             "width": "test_width",
             "height": "test_height",
             "html":
             '<blockquote class="facebook-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/oembed_video?url=https%3A%2F%2Ffb.watch%2FABC123eew%2F&format=json",
     )
     self.assertEqual(request.get_header("Authorization"), "Bearer 123|abc")
Beispiel #2
0
 def test_facebook_failed_request(self):
     config = {"side_effect": URLError(reason="Testing error handling")}
     with patch.object(urllib.request, "urlopen", **config):
         self.assertRaises(
             EmbedNotFoundException,
             FacebookOEmbedFinder().find_embed,
             "https://fb.watch/ABC123eew/",
         )
Beispiel #3
0
 def test_facebook_request_not_found(self):
     err = HTTPError("https://fb.watch/ABC123eew/",
                     code=404,
                     msg='Not Found',
                     hdrs={},
                     fp=None)
     config = {'side_effect': err}
     with patch.object(urllib.request, 'urlopen', **config):
         self.assertRaises(EmbedNotFoundException,
                           FacebookOEmbedFinder().find_embed,
                           "https://fb.watch/ABC123eew/")
Beispiel #4
0
 def test_facebook_request_denied_401(self):
     err = HTTPError("https://fb.watch/ABC123eew/",
                     code=401,
                     msg='invalid credentials',
                     hdrs={},
                     fp=None)
     config = {'side_effect': err}
     with patch.object(urllib.request, 'urlopen', **config):
         self.assertRaises(AccessDeniedFacebookOEmbedException,
                           FacebookOEmbedFinder().find_embed,
                           "https://fb.watch/ABC123eew/")
Beispiel #5
0
 def test_facebook_oembed_return_values(self, urlopen):
     urlopen.return_value = self.dummy_response
     result = FacebookOEmbedFinder(app_id='123', app_secret='abc').find_embed("https://fb.watch/ABC123eew/")
     self.assertEqual(result, {
         'type': 'something',
         'title': 'test_title',
         'author_name': 'test_author',
         'provider_name': 'Facebook',
         'thumbnail_url': None,
         'width': 'test_width',
         'height': 'test_height',
         'html': '<blockquote class="facebook-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/v9.0/oembed_video?url=https%3A%2F%2Ffb.watch%2FABC123eew%2F&format=json"
     )
     self.assertEqual(request.get_header('Authorization'), "Bearer 123|abc")
Beispiel #6
0
 def test_facebook_oembed_accepts_various_url_patterns(self):
     finder = FacebookOEmbedFinder()
     self.assertTrue(
         finder.accept(
             "https://www.facebook.com/testuser/posts/10157389310497085"))
     self.assertTrue(finder.accept("https://fb.watch/ABC123eew/"))