diff --git a/.coverage b/.coverage
index b63c622..2cd2ed9 100644
Binary files a/.coverage and b/.coverage differ
diff --git a/AUTHORS b/AUTHORS
index 6e128e4..a8c9e8d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,6 +2,7 @@ Current or previous core committers
Adolfo Fitoria
Andres Reyes
+José Ernesto Dávila Pantoja
Oscar Cortez
* Your name could stand here :)
diff --git a/README.md b/README.md
index 9148e95..cbe139c 100644
--- a/README.md
+++ b/README.md
@@ -41,14 +41,15 @@ How to install it?
To get the latest stable release from PyPI
-.. code-block:: bash
- pip install django-magicembed
+```bash
+pip install django-magicembed
+```
To get the latest commit from GitHub
-.. code-block:: bash
-
- pip install -e git+git://github.com/kronoscode/django-magicembed.git#egg=magicembed
+```bash
+pip install -e git+git://github.com/kronoscode/django-magicembed.git#egg=magicembed
+```
If you have a requeriments list add this to your requeriments
@@ -58,21 +59,21 @@ If you have a requeriments list add this to your requeriments
3. add magicembed to **INSTALLED_APPS**
-.. code-block:: python
- INSTALLED_APPS = (
- ...,
- 'magicembed',
- )
-
+```python
+INSTALLED_APPS = (
+ ...,
+ 'magicembed',
+)
+```
How to use
---------------
Before your tags/filters are available in your templates, load them by using
-.. code-block:: html
-
- {% load magicembed_tags %}
+```html
+{% load magicembed_tags %}
+```
Now if you need to embed a video, add this template tag to video url
field
@@ -98,7 +99,7 @@ How to contrib
If you want to contribute to this project, please perform the following steps
-.. code-block:: bash
+```bash
# Fork this repository
# Clone your fork
@@ -110,6 +111,7 @@ If you want to contribute to this project, please perform the following steps
git add . && git commit
git push -u origin feature_branch
# Send us a pull request for your feature branch
+```
Licence
--------------
diff --git a/magicembed/__init__.py b/magicembed/__init__.py
index e6cb3ed..6e3f68c 100644
--- a/magicembed/__init__.py
+++ b/magicembed/__init__.py
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
-__version__ = '1.0.0' # pragma: no cover
+__version__ = '1.0.2' # pragma: no cover
diff --git a/magicembed/providers.py b/magicembed/providers.py
index efb6b52..b9a2529 100644
--- a/magicembed/providers.py
+++ b/magicembed/providers.py
@@ -5,9 +5,9 @@
from urlparse import parse_qs
+from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
-
class Provider(object):
def __init__(self, url, size=(640, 480)):
@@ -32,7 +32,7 @@ def __init__(self, url, size=(640, 480)):
self.video_id = parse_qs(qs[1])['v'][0]
def render_video(self):
- html = '''''' # noqa
+ html = '''''' # noqa
return html % (self.size[0], self.size[1], self.video_id)
def render_thumbnail(self, link_to='#'):
@@ -48,9 +48,8 @@ def __init__(self, url, size=(640, 480)):
self.api_url = 'http://vimeo.com/api/v2/video/%s.json' % self.video_id
def render_video(self):
- html = '''
Das Pop: The Game from Big Active on Vimeo.
''' # noqa - return html % (self.video_id, self.size[0], - self.size[1], self.video_id) + html = '''''' # noqa + return html % (self.size[0], self.size[1], self.video_id) def render_thumbnail(self, link_to="#"): api_response = json.loads(urllib.urlopen(self.api_url).read()) @@ -65,7 +64,7 @@ def __init__(self, url, size=(640, 480)): if key is not None: self.api_url = 'http://api.embed.ly/1/oembed?key=%s&url=%s&maxwidth=%s&format=json' % (key, url, size[0]) else: - raise ValueError("If you want to use this please set the Embedly api key") + raise ImproperlyConfigured("If you want to use this please set the Embedly api key") def render_video(self): return self._call_api()['html'] @@ -77,7 +76,7 @@ def _call_api(self): try: data = json.loads(urllib.urlopen(self.api_url).read()) except IOError: - raise IOError("Please set the Embedly api key correctly") + raise ImproperlyConfigured("Please set the Embedly api key correctly") return data diff --git a/magicembed/templatetags/magicembed_tags.py b/magicembed/templatetags/magicembed_tags.py index 1017bc1..b64ea1a 100644 --- a/magicembed/templatetags/magicembed_tags.py +++ b/magicembed/templatetags/magicembed_tags.py @@ -10,7 +10,7 @@ @register.filter(is_safe=True) def magicembed(value, arg=None): '''value is the url and arg the size tuple - ussage: {% http://myurl.com/|magicembed:"640x480" %}''' + usage: {% http://myurl.com/|magicembed:"640x480" %}''' arg = [int(item) for item in arg.split('x')] provider = get_provider(value, arg) @@ -20,6 +20,6 @@ def magicembed(value, arg=None): @register.filter def magicthumbnail(value): '''value is the url and arg the link_to another url - ussage: {% http://myurl.com/|magicthumbnail: '/some/url' %}''' + usage: {% http://myurl.com/|magicthumbnail: '/some/url' %}''' provider = get_provider(value) return provider.render_thumbnail() diff --git a/magicembed/tests/coverage/coverage_status.png b/magicembed/tests/coverage/coverage_status.png index f7edc5e..f1c9baf 100644 Binary files a/magicembed/tests/coverage/coverage_status.png and b/magicembed/tests/coverage/coverage_status.png differ diff --git a/magicembed/tests/coverage/errors.html b/magicembed/tests/coverage/errors.html index 1d0dfd2..00ffb9e 100644 --- a/magicembed/tests/coverage/errors.html +++ b/magicembed/tests/coverage/errors.html @@ -44,7 +44,7 @@Generated: Wed 2015-08-05 13:23 CST
Generated: Sat 2015-10-10 18:15 CST
django_coverage.utils.module_tools.find_or_load_module had
problems importing these packages and modules:
diff --git a/magicembed/tests/coverage/excludes.html b/magicembed/tests/coverage/excludes.html
index aac0527..8afc944 100644
--- a/magicembed/tests/coverage/excludes.html
+++ b/magicembed/tests/coverage/excludes.html
@@ -44,7 +44,7 @@
Generated: Wed 2015-08-05 13:23 CST
Generated: Sat 2015-10-10 18:15 CST
These packages and modules were excluded from the coverage analysis in
django.conf.settings.COVERAGE_MODULE_EXCLUDES or they do
diff --git a/magicembed/tests/coverage/index.html b/magicembed/tests/coverage/index.html
index 6a9db1d..310d2da 100644
--- a/magicembed/tests/coverage/index.html
+++ b/magicembed/tests/coverage/index.html
@@ -116,7 +116,7 @@
Generated: Wed 2015-08-05 13:23 CST
+Generated: Sat 2015-10-10 18:15 CST

Generated: Wed 2015-08-05 13:23 CST
-Source file: /Users/oscarmcm/Code/Django/django-magicembed/magicembed/__init__.py
+Generated: Sat 2015-10-10 18:15 CST
+Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/__init__.py
Stats: 0 executed, @@ -143,7 +143,7 @@
# -*- coding: utf-8 -*-__version__ = '1.0.0' # pragma: no cover__version__ = '1.0.2' # pragma: no coverGenerated: Wed 2015-08-05 13:23 CST
-Source file: /Users/oscarmcm/Code/Django/django-magicembed/magicembed/providers.py
+Generated: Sat 2015-10-10 18:15 CST
+Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/providers.py
Stats: - 48 executed, - 5 missed, - 5 excluded, - 33 ignored + 51 executed, + 2 missed, + 6 excluded, + 31 ignored
from urlparse import parse_qsfrom django.core.exceptions import ImproperlyConfiguredfrom django.conf import settingsclass Provider(object): def __init__(self, url, size=(640, 480)): self.video_id = parse_qs(qs[1])['v'][0] def render_video(self): html = '''<iframe title="YouTube video player" width="%d" height="%d" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>''' # noqa html = '''<iframe title="YouTube video player" width="%d" height="%d" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>''' # noqa return html % (self.size[0], self.size[1], self.video_id) def render_thumbnail(self, link_to='#'): self.api_url = 'http://vimeo.com/api/v2/video/%s.json' % self.video_id def render_video(self): html = '''<iframe src="http://player.vimeo.com/video/%s" width="%d" height="%d" frameborder="0"></iframe><p><a href="http://vimeo.com/%s">Das Pop: The Game</a> from <a href="http://vimeo.com/bigactive">Big Active</a> on <a href="http://vimeo.com">Vimeo</a>.</p>''' # noqa return html % (self.video_id, self.size[0], self.size[1], self.video_id) html = '''<iframe title="Vimeo video player" width="%d" height="%d" src="http://player.vimeo.com/video/%s" frameborder="0" allowfullscreen></iframe>''' # noqa return html % (self.size[0], self.size[1], self.video_id) def render_thumbnail(self, link_to="#"): api_response = json.loads(urllib.urlopen(self.api_url).read()) if key is not None: self.api_url = 'http://api.embed.ly/1/oembed?key=%s&url=%s&maxwidth=%s&format=json' % (key, url, size[0]) else: raise ValueError("If you want to use this please set the Embedly api key") raise ImproperlyConfigured("If you want to use this please set the Embedly api key") def render_video(self): return self._call_api()['html'] def _call_api(self): try: data = json.loads(urllib.urlopen(self.api_url).read()) except IOError: raise IOError("Please set the Embedly api key correctly") except IOError: raise ImproperlyConfigured("Please set the Embedly api key correctly") return dataGenerated: Wed 2015-08-05 13:23 CST
-Source file: /Users/oscarmcm/Code/Django/django-magicembed/magicembed/templatetags/magicembed_tags.py
+Generated: Sat 2015-10-10 18:15 CST
+Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/templatetags/magicembed_tags.py
Stats: - 0 executed, - 9 missed, + 9 executed, + 0 missed, 3 excluded, 13 ignored
@@ -148,25 +148,25 @@from magicembed.providers import get_providerregister = template.Library()register = template.Library()@register.filter(is_safe=True)def magicembed(value, arg=None):@register.filter(is_safe=True)def magicembed(value, arg=None): '''value is the url and arg the size tuple ussage: {% http://myurl.com/|magicembed:"640x480" %}''' arg = [int(item) for item in arg.split('x')] provider = get_provider(value, arg) arg = [int(item) for item in arg.split('x')] provider = get_provider(value, arg) return mark_safe(provider.render_video()) return mark_safe(provider.render_video())@register.filter@register.filterdef magicthumbnail(value): '''value is the url and arg the link_to another url ussage: {% http://myurl.com/|magicthumbnail: '/some/url' %}''' provider = get_provider(value) return provider.render_thumbnail() provider = get_provider(value) return provider.render_thumbnail()Das Pop: The Game from Big Active on Vimeo.
''' + embed = '''''' thumbnail = '''http://i.vimeocdn.com/video/137933005_200x150.jpg''' self.assertEqual(vimeo.render_video(), embed) - self.assertEqual(vimeo.render_thumbnail(), thumbnail) - def testEmbedly(self): + api_call_mock = MagicMock( + return_value=[{ "thumbnail_medium": thumbnail }]) + with patch('magicembed.providers.json.loads', api_call_mock): + self.assertEqual(vimeo.render_thumbnail(), thumbnail) + + @patch('magicembed.providers.urllib') + def testEmbedly(self, urllib_mock): blip = Embedly('https://vine.co/v/eHHOtXV5lxT', (600, 400)) embed = '' thumbnail = 'https://v.cdn.vine.co/r/videos/B3FA3B51771240096733128749056_39a5c18c0e0.2.1.15446276152990570361.mp4.jpg?versionId=nM.tB7FoIhn4z059SNsYgmz.2RmLKV4x' - self.assertNotEqual(blip.render_video(), embed) - self.assertEqual(blip.render_thumbnail(), thumbnail) + + with patch('magicembed.providers.Embedly._call_api', MagicMock()): + self.assertNotEqual(blip.render_video(), embed) + + api_call_mock = MagicMock( + return_value={ + "thumbnail_url": thumbnail + } + ) + with patch('magicembed.providers.json.loads', api_call_mock): + self.assertEqual(blip.render_thumbnail(), thumbnail) + + @override_settings(EMBEDLY_KEY=None) + def test_Embedly_without_api_key(self): + with self.assertRaises(ImproperlyConfigured): + Embedly('https://vine.co/v/eHHOtXV5lxT') + + def test_call_Embedly_api_without_key(self): + blip = Embedly('https://vine.co/v/eHHOtXV5lxT', (600, 400)) + + with self.settings(EMBEDLY_KEY=None): + with self.assertRaises(ImproperlyConfigured): + blip.render_thumbnail() def test_return_provider(self): yt = 'http://www.youtube.com/watch?v=693m7iCh-TE' @@ -37,5 +72,21 @@ def test_return_provider(self): self.assertTrue(isinstance(get_provider(vimeo), Vimeo)) self.assertTrue(isinstance(get_provider(blip), Embedly)) + +class TemplateTagsTest(TestCase): + + def test_magicembed_tag(self): + TEMPLATE = Template('''{% load magicembed_tags %} {{ 'http://vimeo.com/21443752/'|magicembed:"400x225" }}''') + rendered = TEMPLATE.render(Context({})) + self.assertIn("Vimeo video player", rendered, msg="title is not present.") + + def test_magicthumbnail_tag(self): + thumbnail = '''http://i.vimeocdn.com/video/137933005_200x150.jpg''' + TEMPLATE = Template('''{% load magicembed_tags %} {{ 'http://vimeo.com/21443752/'|magicthumbnail }}''') + + rendered = TEMPLATE.render(Context({})) + self.assertIn(thumbnail, rendered) + + if __name__ == '__main__': unittest.main() diff --git a/requirements.txt b/requirements.txt index 892b40b..d3e4ba5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ django -six -django-compat \ No newline at end of file diff --git a/setup.py b/setup.py index b5adc04..a466c1e 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def read(fname): return '' setup( - name="django-magicembed", + name="magicembed", version=app.__version__, description=read('DESCRIPTION'), long_description=read('README.rst'),