Skip to content

Commit

Permalink
Closes #7.
Browse files Browse the repository at this point in the history
Return back raising UnknownIdException in Youtube backend to fix form validation.
  • Loading branch information
yetty committed Sep 3, 2013
1 parent e0236bf commit a31f4b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
_*
!__init__.py
9 changes: 7 additions & 2 deletions embed_video/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class VideoDoesntExistException(Exception):
pass


class UnknownBackendException(Exception):
pass

Expand Down Expand Up @@ -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'
Expand All @@ -171,7 +172,11 @@ def get_code(self):

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

Expand Down
9 changes: 8 additions & 1 deletion embed_video/tests/tests_backend.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -91,3 +92,9 @@ def test_code_soundcloud(self):
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')

0 comments on commit a31f4b9

Please sign in to comment.