Fix OEmbed endpoints

pull/3800/merge
Mitchel Cabuloy 2017-09-08 04:14:56 +08:00 zatwierdzone przez Matt Westcott
rodzic 92b4f68c67
commit 83e6a551fe
4 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ Changelog
* Fix: Migration for addition of `Page.draft_title` field is now reversible (Venelin Stoykov)
* Fix: Fixed failure on application startup when `ManifestStaticFilesStorage` is in use and `collectstatic` has not yet been run (Matt Westcott)
* Fix: Fixed handling of Vimeo and other oEmbed providers with a format parameter in the endpoint URL (Mitchel Cabuloy)
1.12.1 (30.08.2017)

Wyświetl plik

@ -15,3 +15,4 @@ Bug fixes
* Migration for addition of ``Page.draft_title`` field is now reversible (Venelin Stoykov)
* Fixed failure on application startup when ``ManifestStaticFilesStorage`` is in use and ``collectstatic`` has not yet been run (Matt Westcott)
* Fixed handling of Vimeo and other oEmbed providers with a format parameter in the endpoint URL (Mitchel Cabuloy)

Wyświetl plik

@ -26,11 +26,12 @@ class OEmbedFinder(EmbedFinder):
for provider in providers or all_providers:
patterns = []
endpoint = provider['endpoint'].replace('{format}', 'json')
for url in provider['urls']:
url = url.replace('{format}', 'json')
patterns.append(re.compile(url))
self._endpoints[provider['endpoint']] = patterns
self._endpoints[endpoint] = patterns
if options:
self.options = self.options.copy()

Wyświetl plik

@ -447,6 +447,17 @@ class TestOembed(TestCase):
finder = OEmbedFinder(providers=[oembed_providers.twitter])
self.assertFalse(finder.accept("http://www.youtube.com/watch/"))
@patch('django.utils.six.moves.urllib.request.urlopen')
@patch('json.loads')
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.full_url.split('?')[0], "http://www.vimeo.com/api/oembed.json")
class TestEmbedTag(TestCase):
@patch('wagtail.wagtailembeds.embeds.get_embed')