diff --git a/CHANGES.rst b/CHANGES.rst index 7e80a44..3aea77f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +Release 0.8 (dev) +----------------- + +- Add ``EMBED_VIDEO_TIMEOUT`` to settings. + + Release 0.7 (Dec. 21, 2013) --------------------------- @@ -13,9 +19,9 @@ Release 0.7 (Dec. 21, 2013) Release 0.6 (Oct. 04, 2013) --------------------------- -- Ability to overwrite embed code of backend +- Ability to overwrite embed code of backend -- Caching backends properties +- Caching backends properties - PyPy compatibility @@ -31,14 +37,14 @@ Release 0.5 (Sep. 03, 2013) - Added example project -- Fixed template tag embed +- Fixed template tag embed - Fixed raising UnknownIdException in YouTube detecting. Release 0.4 (Aug. 22, 2013) ----------------------------- +--------------------------- - Documentation was rewrited and moved to http://django-embed-video.rtfd.org/ . @@ -54,14 +60,14 @@ Release 0.4 (Aug. 22, 2013) Release 0.3 (Aug. 20, 2013) ----------------------------- +--------------------------- - Security fix: faked urls are treated as invalid. See `this page `_ - for more details. + for more details. - Fixes: - + - allow of empty video field. - requirements in setup.py @@ -73,18 +79,18 @@ Release 0.3 (Aug. 20, 2013) - ``backend`` variable in ``video`` template tag. Usage:: - + {% video item.video as my_video %} Backend: {{ my_video.backend }} {% endvideo %} -Release 0.2 (June 25, 2013) ----------------------------- +Release 0.2 (June 25, 2013) +--------------------------- - Support of SoundCloud Release 0.1 (June 1, 2013) ----------------------------- +-------------------------- - Initial release diff --git a/docs/api/embed_video.settings.rst b/docs/api/embed_video.settings.rst index 6b26f82..d071e55 100644 --- a/docs/api/embed_video.settings.rst +++ b/docs/api/embed_video.settings.rst @@ -1,5 +1,5 @@ Settings -=========== +======== .. setting:: EMBED_VIDEO_BACKENDS @@ -8,8 +8,8 @@ EMBED_VIDEO_BACKENDS List of backends to use. -Default:: - +Default:: + EMBED_VIDEO_BACKENDS = ( 'embed_video.backends.YoutubeBackend', 'embed_video.backends.VimeoBackend', @@ -17,3 +17,11 @@ Default:: ) +.. setting:: EMBED_VIDEO_TIMEOUT + +EMBED_VIDEO_TIMEOUT +------------------- + +Sets timeout for ``GET`` requests to remote servers. + +Default: ``10`` diff --git a/embed_video/backends.py b/embed_video/backends.py index 6ec51c8..951195a 100644 --- a/embed_video/backends.py +++ b/embed_video/backends.py @@ -11,7 +11,7 @@ except ImportError: from django.utils.functional import cached_property from .utils import import_by_path -from .settings import EMBED_VIDEO_BACKENDS +from .settings import EMBED_VIDEO_BACKENDS, EMBED_VIDEO_TIMEOUT class VideoDoesntExistException(Exception): @@ -202,7 +202,8 @@ class VimeoBackend(VideoBackend): def get_info(self): try: response = requests.get( - self.pattern_info.format(code=self.code, protocol=self.protocol) + self.pattern_info.format(code=self.code, protocol=self.protocol), + timeout=EMBED_VIDEO_TIMEOUT ) return json.loads(response.text)[0] except ValueError: @@ -235,7 +236,9 @@ class SoundCloudBackend(VideoBackend): 'format': 'json', 'url': self._url, } - r = requests.get(self.base_url, data=params) + r = requests.get(self.base_url, data=params, + timeout=EMBED_VIDEO_TIMEOUT) + return json.loads(r.text) def get_thumbnail_url(self): diff --git a/embed_video/settings.py b/embed_video/settings.py index ea7c0d9..36eae7e 100644 --- a/embed_video/settings.py +++ b/embed_video/settings.py @@ -6,3 +6,5 @@ EMBED_VIDEO_BACKENDS = getattr(settings, 'EMBED_VIDEO_BACKENDS', ( 'embed_video.backends.VimeoBackend', 'embed_video.backends.SoundCloudBackend', )) + +EMBED_VIDEO_TIMEOUT = getattr(settings, 'EMBED_VIDEO_TIMEOUT', 10) diff --git a/embed_video/tests/tests_backend.py b/embed_video/tests/tests_backend.py index 5056ea1..d6b8b47 100644 --- a/embed_video/tests/tests_backend.py +++ b/embed_video/tests/tests_backend.py @@ -1,4 +1,6 @@ from unittest import TestCase +from mock import patch +import requests from ..backends import detect_backend, YoutubeBackend, VimeoBackend, \ SoundCloudBackend, UnknownBackendException, \ @@ -87,6 +89,11 @@ class VimeoBackendTestCase(BackendTestMixin, TestCase): self.assertEqual(backend.get_thumbnail_url(), 'http://b.vimeocdn.com/ts/446/150/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) + class SoundCloudBackendTestCase(BackendTestMixin, TestCase): urls = ( @@ -127,3 +134,8 @@ class SoundCloudBackendTestCase(BackendTestMixin, TestCase): self.assertEqual(self.foo.get_embed_code(100, 200), '') + + @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) diff --git a/embed_video/tests/tests_tags.py b/embed_video/tests/tests_tags.py index 365c871..efe3d97 100644 --- a/embed_video/tests/tests_tags.py +++ b/embed_video/tests/tests_tags.py @@ -153,5 +153,3 @@ class EmbedVideoNodeTestCase(TestCase): backend = VideoNode.get_backend('http://www.youtube.com/watch?v=jsrRJyHBvzw', context) self.assertFalse(backend.is_secure) - -