def test_oembed_return_values(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = { 'type': 'something', 'url': 'http://www.example.com', 'title': 'test_title', 'author_name': 'test_author', 'provider_name': 'test_provider_name', 'thumbnail_url': 'test_thumbail_url', 'width': 'test_width', 'height': 'test_height', 'html': 'test_html' } result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual( result, { 'type': 'something', 'title': 'test_title', 'author_name': 'test_author', 'provider_name': 'test_provider_name', 'thumbnail_url': 'test_thumbail_url', 'width': 'test_width', 'height': 'test_height', 'html': 'test_html' })
def test_oembed_cache_until_as_string(self, loads, urlopen, now): urlopen.return_value = self.dummy_response loads.return_value = { "type": "something", "url": "http://www.example.com", "title": "test_title", "author_name": "test_author", "provider_name": "test_provider_name", "thumbnail_url": "test_thumbail_url", "width": "test_width", "height": "test_height", "html": "test_html", "cache_age": "3600", } now.return_value = make_aware(datetime.datetime(2001, 2, 3)) result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual( result, { "type": "something", "title": "test_title", "author_name": "test_author", "provider_name": "test_provider_name", "thumbnail_url": "test_thumbail_url", "width": "test_width", "height": "test_height", "html": "test_html", "cache_until": make_aware(datetime.datetime(2001, 2, 3, hour=1)), }, )
def test_oembed_non_json_response(self, urlopen): urlopen.return_value = self.dummy_response self.assertRaises( EmbedNotFoundException, OEmbedFinder().find_embed, "https://www.youtube.com/watch?v=ReblZ7o7lu4", )
def test_oembed_return_values(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = { "type": "something", "url": "http://www.example.com", "title": "test_title", "author_name": "test_author", "provider_name": "test_provider_name", "thumbnail_url": "test_thumbail_url", "width": "test_width", "height": "test_height", "html": "test_html", } result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual( result, { "type": "something", "title": "test_title", "author_name": "test_author", "provider_name": "test_provider_name", "thumbnail_url": "test_thumbail_url", "width": "test_width", "height": "test_height", "html": "test_html", }, )
def test_oembed_cache_until(self, loads, urlopen, now): urlopen.return_value = self.dummy_response loads.return_value = { 'type': 'something', 'url': 'http://www.example.com', 'title': 'test_title', 'author_name': 'test_author', 'provider_name': 'test_provider_name', 'thumbnail_url': 'test_thumbail_url', 'width': 'test_width', 'height': 'test_height', 'html': 'test_html', 'cache_age': 3600 } now.return_value = make_aware(datetime.datetime(2001, 2, 3)) result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual( result, { 'type': 'something', 'title': 'test_title', 'author_name': 'test_author', 'provider_name': 'test_provider_name', 'thumbnail_url': 'test_thumbail_url', 'width': 'test_width', 'height': 'test_height', 'html': 'test_html', 'cache_until': make_aware(datetime.datetime(2001, 2, 3, hour=1)) })
def test_endpoint_with_format_param(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = {'type': 'video', 'url': 'http://www.example.com'} result = OEmbedFinder().find_embed("https://vimeo.com/217403396") self.assertEqual(result['type'], 'video') request = urlopen.call_args[0][0] self.assertEqual(request.get_full_url().split('?')[0], "https://www.vimeo.com/api/oembed.json")
def test_oembed_photo_request(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = {'type': 'photo', 'url': 'http://www.example.com'} result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual(result['type'], 'photo') self.assertEqual(result['html'], '<img src="http://www.example.com" alt="">') loads.assert_called_with("foo")
def test_oembed_photo_request(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = {"type": "photo", "url": "http://www.example.com"} result = OEmbedFinder().find_embed("http://www.youtube.com/watch/") self.assertEqual(result["type"], "photo") self.assertEqual(result["html"], '<img src="http://www.example.com" alt="">') loads.assert_called_with("foo")
def test_oembed_invalid_request(self): config = {"side_effect": URLError("foo")} with patch.object(urllib.request, "urlopen", **config): self.assertRaises( EmbedNotFoundException, OEmbedFinder().find_embed, "http://www.youtube.com/watch/", )
def test_endpoint_with_format_param(self, loads, urlopen): urlopen.return_value = self.dummy_response loads.return_value = {"type": "video", "url": "http://www.example.com"} result = OEmbedFinder().find_embed("https://vimeo.com/217403396") self.assertEqual(result["type"], "video") request = urlopen.call_args[0][0] self.assertEqual( request.get_full_url().split("?")[0], "https://www.vimeo.com/api/oembed.json", )
def test_oembed_doesnt_accept_unknown_provider(self): finder = OEmbedFinder(providers=[oembed_providers.twitter]) self.assertFalse(finder.accept("http://www.youtube.com/watch/"))
def test_oembed_accepts_known_provider(self): finder = OEmbedFinder(providers=[oembed_providers.youtube]) self.assertTrue(finder.accept("http://www.youtube.com/watch/"))
def test_oembed_invalid_provider(self): self.assertRaises(EmbedNotFoundException, OEmbedFinder().find_embed, "foo")