-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
432 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
<iframe width="{{ width }}" height="{{ height }}" src="{{ backend.url }}" | ||
frameborder="0" allowfullscreen></iframe> | ||
<iframe width="{{ width }}" height="{{ height }}" src="{{ backend.url }}" frameborder="0" allowfullscreen></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from unittest import TestCase | ||
|
||
from embed_video.backends import detect_backend, UnknownBackendException, \ | ||
VideoBackend | ||
|
||
|
||
class BackendTestMixin(object): | ||
urls = [] | ||
instance = None | ||
|
||
def test_detect(self): | ||
for url in self.urls: | ||
backend = detect_backend(url[0]) | ||
self.assertIsInstance(backend, self.instance) | ||
|
||
def test_code(self): | ||
for url in self.urls: | ||
backend = self.instance(url[0]) | ||
self.assertEqual(backend.code, url[1]) | ||
|
||
|
||
class VideoBackendTestCase(TestCase): | ||
unknown_backend_urls = ( | ||
'http://myurl.com/?video=http://www.youtube.com/watch?v=jsrRJyHBvzw', | ||
'http://myurl.com/?video=www.youtube.com/watch?v=jsrRJyHBvzw', | ||
'http://youtube.com.myurl.com/watch?v=jsrRJyHBvzw', | ||
'http://vimeo.com.myurl.com/72304002', | ||
) | ||
|
||
def test_detect_bad_urls(self): | ||
for url in self.unknown_backend_urls: | ||
self.assertRaises(UnknownBackendException, detect_backend, url) | ||
|
||
def test_not_implemented_get_info(self): | ||
backend = VideoBackend('http://www.example.com') | ||
self.assertRaises(NotImplementedError, backend.get_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import requests | ||
from mock import patch | ||
from unittest import TestCase | ||
|
||
from . import BackendTestMixin | ||
from embed_video.backends import SoundCloudBackend, VideoDoesntExistException | ||
|
||
|
||
class SoundCloudBackendTestCase(BackendTestMixin, TestCase): | ||
urls = ( | ||
('https://soundcloud.com/community/soundcloud-case-study-wildlife', '82244706'), | ||
('https://soundcloud.com/matej-roman/jaromir-nohavica-karel-plihal-mikymauz', '7834701'), | ||
('https://soundcloud.com/beny97/sets/jaromir-nohavica-prazska', '960591'), | ||
('https://soundcloud.com/corbel-keep/norah-jones-come-away-with', '22485933'), | ||
) | ||
|
||
instance = SoundCloudBackend | ||
|
||
def setUp(self): | ||
class FooBackend(SoundCloudBackend): | ||
url = 'foobar' | ||
|
||
def get_info(self): | ||
return { | ||
'width': 123, | ||
'height': 321, | ||
'thumbnail_url': 'xyz', | ||
'html': u'\u003Ciframe width=\"100%\" height=\"400\" ' | ||
u'scrolling=\"no\" frameborder=\"no\" ' | ||
u'src=\"{0}\"\u003E\u003C/iframe\u003E'.format(self.url) | ||
} | ||
|
||
self.foo = FooBackend('abcd') | ||
|
||
def test_width(self): | ||
self.assertEqual(self.foo.width, 123) | ||
|
||
def test_height(self): | ||
self.assertEqual(self.foo.height, 321) | ||
|
||
def test_get_thumbnail_url(self): | ||
self.assertEqual(self.foo.get_thumbnail_url(), 'xyz') | ||
|
||
def test_get_url(self): | ||
self.assertEqual(self.foo.get_url(), self.foo.url) | ||
|
||
@patch('embed_video.backends.EMBED_VIDEO_TIMEOUT', 0.000001) | ||
def test_timeout_in_get_info(self): | ||
backend = SoundCloudBackend('https://soundcloud.com/community/soundcloud-case-study-wildlife') | ||
self.assertRaises(requests.Timeout, backend.get_info) | ||
|
||
def test_invalid_url(self): | ||
""" Check if bug #21 is fixed. """ | ||
backend = SoundCloudBackend('https://soundcloud.com/xyz/foo') | ||
self.assertRaises(VideoDoesntExistException, backend.get_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import requests | ||
from mock import patch | ||
from unittest import TestCase | ||
|
||
from . import BackendTestMixin | ||
from embed_video.backends import VimeoBackend, VideoDoesntExistException | ||
|
||
|
||
class VimeoBackendTestCase(BackendTestMixin, TestCase): | ||
urls = ( | ||
('http://vimeo.com/72304002', '72304002'), | ||
('https://vimeo.com/72304002', '72304002'), | ||
('http://www.vimeo.com/72304002', '72304002'), | ||
('https://www.vimeo.com/72304002', '72304002'), | ||
('http://player.vimeo.com/video/72304002', '72304002'), | ||
('https://player.vimeo.com/video/72304002', '72304002'), | ||
) | ||
|
||
instance = VimeoBackend | ||
|
||
def test_vimeo_get_info_exception(self): | ||
with self.assertRaises(VideoDoesntExistException): | ||
backend = VimeoBackend('http://vimeo.com/123') | ||
backend.get_info() | ||
|
||
def test_get_thumbnail_url(self): | ||
backend = VimeoBackend('http://vimeo.com/72304002') | ||
self.assertEqual(backend.get_thumbnail_url(), | ||
'http://i.vimeocdn.com/video/446150690_640.jpg') | ||
|
||
@patch('embed_video.backends.EMBED_VIDEO_TIMEOUT', 0.000001) | ||
def test_timeout_in_get_info(self): | ||
backend = VimeoBackend('http://vimeo.com/72304002') | ||
self.assertRaises(requests.Timeout, backend.get_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest import TestCase | ||
|
||
from . import BackendTestMixin | ||
from embed_video.backends import YoutubeBackend, UnknownIdException | ||
|
||
|
||
class YoutubeBackendTestCase(BackendTestMixin, TestCase): | ||
urls = ( | ||
('http://youtu.be/jsrRJyHBvzw', 'jsrRJyHBvzw'), | ||
('http://youtu.be/n17B_uFF4cA', 'n17B_uFF4cA'), | ||
('http://youtu.be/t-ZRX8984sc', 't-ZRX8984sc'), | ||
('https://youtu.be/t-ZRX8984sc', 't-ZRX8984sc'), | ||
('http://youtube.com/watch?v=jsrRJyHBvzw', 'jsrRJyHBvzw'), | ||
('https://youtube.com/watch?v=jsrRJyHBvzw', 'jsrRJyHBvzw'), | ||
('http://www.youtube.com/v/0zM3nApSvMg?rel=0', '0zM3nApSvMg'), | ||
('https://www.youtube.com/v/0zM3nApSvMg?rel=0', '0zM3nApSvMg'), | ||
('http://www.youtube.com/embed/0zM3nApSvMg?rel=0', '0zM3nApSvMg'), | ||
('https://www.youtube.com/embed/0zM3nApSvMg?rel=0', '0zM3nApSvMg'), | ||
('http://www.youtube.com/watch?v=jsrRJyHBvzw', 'jsrRJyHBvzw'), | ||
('https://www.youtube.com/watch?v=t-ZRX8984sc', 't-ZRX8984sc'), | ||
('http://www.youtube.com/watch?v=iwGFalTRHDA&feature=related', 'iwGFalTRHDA'), | ||
('https://www.youtube.com/watch?v=iwGFalTRHDA&feature=related', 'iwGFalTRHDA'), | ||
('http://www.youtube.com/watch?feature=player_embedded&v=2NpZbaAIXag', '2NpZbaAIXag'), | ||
('https://www.youtube.com/watch?feature=player_embedded&v=2NpZbaAIXag', '2NpZbaAIXag'), | ||
('https://www.youtube.com/watch?v=XPk521voaOE&feature=youtube_gdata_player', 'XPk521voaOE'), | ||
('http://www.youtube.com/watch?v=6xu00J3-g2s&list=PLb5n6wzDlPakFKvJ69rJ9AJW24Aaaki2z', '6xu00J3-g2s'), | ||
('https://m.youtube.com/#/watch?v=IAooXLAPoBQ', 'IAooXLAPoBQ'), | ||
('https://m.youtube.com/watch?v=IAooXLAPoBQ', 'IAooXLAPoBQ'), | ||
('http://www.youtube.com/edit?video_id=eBea01qmnOE', 'eBea01qmnOE') | ||
) | ||
|
||
instance = YoutubeBackend | ||
|
||
def test_youtube_keyerror(self): | ||
""" Test for issue #7 """ | ||
backend = self.instance('http://youtube.com/watch?id=5') | ||
self.assertRaises(UnknownIdException, backend.get_code) | ||
|
||
def test_thumbnail(self): | ||
for url in self.urls: | ||
backend = self.instance(url[0]) | ||
self.assertIn(url[1], backend.thumbnail) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.