mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-03-16 21:30:23 +00:00
Closes #7.
Return back raising UnknownIdException in Youtube backend to fix form validation.
This commit is contained in:
parent
e0236bf280
commit
a31f4b976b
3 changed files with 16 additions and 3 deletions
1
docs/.gitignore
vendored
1
docs/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
_*
|
||||
!__init__.py
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ if EMBED_VIDEO_CACHE:
|
|||
class VideoDoesntExistException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnknownBackendException(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -160,7 +161,7 @@ class YoutubeBackend(VideoBackend):
|
|||
(\S*[^\w\-\s])?
|
||||
(?P<code>[\w\-]{11})[a-z0-9;:@?&%=+/\$_.-]* # match and extract
|
||||
''',
|
||||
re.I|re.X
|
||||
re.I | re.X
|
||||
)
|
||||
|
||||
pattern_url = 'http://www.youtube.com/embed/%s?wmode=opaque'
|
||||
|
|
@ -171,7 +172,11 @@ class YoutubeBackend(VideoBackend):
|
|||
|
||||
if not code:
|
||||
parse_data = urlparse.urlparse(self._url)
|
||||
code = urlparse.parse_qs(parse_data.query)['v'][0]
|
||||
|
||||
try:
|
||||
code = urlparse.parse_qs(parse_data.query)['v'][0]
|
||||
except KeyError:
|
||||
raise UnknownIdException
|
||||
|
||||
return code
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from ..backends import detect_backend, YoutubeBackend, VimeoBackend, \
|
||||
SoundCloudBackend, UnknownBackendException, VideoDoesntExistException
|
||||
SoundCloudBackend, UnknownBackendException, \
|
||||
VideoDoesntExistException, UnknownIdException
|
||||
|
||||
|
||||
class BackendsTestCase(TestCase):
|
||||
|
|
@ -91,3 +92,9 @@ class BackendsTestCase(TestCase):
|
|||
def test_vimeo_get_info_exception(self):
|
||||
self.assertRaises(VideoDoesntExistException, VimeoBackend,
|
||||
'http://vimeo.com/123')
|
||||
|
||||
def test_youtube_keyerror(self):
|
||||
""" Test for issue #7 """
|
||||
self.assertRaises(UnknownIdException, YoutubeBackend,
|
||||
'http://youtube.com/watch?id=5')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue