Files
odoo_source/addons/website_slides/tests/test_from_url.py
T
Julien Castiaux cfa1e101e2 [FIX] website_slides: get video id from youtube url
The regexp used to get the youtube video id from its url is broken in
multiple ways.

If the video ID starts with the letter 'v' in the short (youtu.be) url
then the url is considered invalid. i.e. https://youtu.be/vmhB-pt7EfA

If the query option `v=<video id>` is not the first option of the query
in the regular url (youtube.com/watch) then the url is also considered
invalid. i.e. https://www.youtube.com/watch?feature=youtu.be&v=vmhB-pt7EfA

The problem has been solved by replacing the over-engineered regexp by
the dedicated parsing tools of `urllib.parse`.

opw-2006330

closes odoo/odoo#34036

Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2019-06-17 09:35:37 +00:00

31 lines
1.2 KiB
Python

import odoo.tests
class TestFromURL(odoo.tests.TransactionCase):
def test_youtube_urls(self):
urls = {
'W0JQcpGLSFw': [
'https://youtu.be/W0JQcpGLSFw',
'https://www.youtube.com/watch?v=W0JQcpGLSFw',
'https://www.youtube.com/watch?v=W0JQcpGLSFw&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx',
],
'vmhB-pt7EfA': [ # id starts with v, it is important
'https://youtu.be/vmhB-pt7EfA',
'https://www.youtube.com/watch?feature=youtu.be&v=vmhB-pt7EfA',
'https://www.youtube.com/watch?v=vmhB-pt7EfA&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx&index=7',
],
'hlhLv0GN1hA': [
'https://www.youtube.com/v/hlhLv0GN1hA',
'https://www.youtube.com/embed/hlhLv0GN1hA',
'https://m.youtube.com/watch?v=hlhLv0GN1hA'
],
}
model = self.env['slide.slide']
for id, urls in urls.items():
for url in urls:
with self.subTest(url=url, id=id):
document = model._find_document_data_from_url(url)
self.assertEqual(document[0], 'youtube')
self.assertEqual(document[1], id)