Skip to content

Commit

Permalink
Merge pull request #13 from josernestodavila/test_exceptions_raised
Browse files Browse the repository at this point in the history
Test Exceptions Raised.
  • Loading branch information
fitoria committed Oct 12, 2015
2 parents 3c488e2 + 984c2d7 commit 62e432c
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 24 deletions.
Binary file modified .coverage
Binary file not shown.
2 changes: 1 addition & 1 deletion magicembed/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def render_thumbnail(self):
def _call_api(self):
try:
data = json.loads(urllib.urlopen(self.api_url).read())
except ImproperlyConfigured:
except IOError:
raise ImproperlyConfigured("Please set the Embedly api key correctly")
return data

Expand Down
Binary file modified magicembed/tests/coverage/coverage_status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion magicembed/tests/coverage/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<body>

<div id="content-header">
<h1>Test Coverage Report: error packages and modules</h1><p>Generated: Mon 2015-09-07 14:04 CST</p></div>
<h1>Test Coverage Report: error packages and modules</h1><p>Generated: Sat 2015-10-10 18:15 CST</p></div>
<div id="result-list">
<p> <code>django_coverage.utils.module_tools.find_or_load_module</code> had
problems importing these packages and modules:
Expand Down
2 changes: 1 addition & 1 deletion magicembed/tests/coverage/excludes.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<body>

<div id="content-header">
<h1>Test Coverage Report: excluded packages and modules</h1><p>Generated: Mon 2015-09-07 14:04 CST</p></div>
<h1>Test Coverage Report: excluded packages and modules</h1><p>Generated: Sat 2015-10-10 18:15 CST</p></div>
<div id="result-list">
<p> These packages and modules were excluded from the coverage analysis in
<code>django.conf.settings.COVERAGE_MODULE_EXCLUDES</code> or they do
Expand Down
10 changes: 5 additions & 5 deletions magicembed/tests/coverage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

<div id="content-header">
<h1>Test Coverage Report</h1>
<p>Generated: Mon 2015-09-07 14:04 CST</p>
<p>Generated: Sat 2015-10-10 18:15 CST</p>
<p><img src="coverage_status.png"></p>
</div>

Expand All @@ -139,9 +139,9 @@ <h1>Test Coverage Report</h1>
<tr>
<td class="module-name">Total</td>
<td>72</td>
<td>57</td>
<td>60</td>
<td>10</td>
<td>91.9%</td>
<td>96.8%</td>
</tr>
</tfoot>
<tbody>
Expand All @@ -156,9 +156,9 @@ <h1>Test Coverage Report</h1>
<tr>
<td class="module-name"><a href="modules/magicembed.providers.html">magicembed.providers</a></td>
<td>59</td>
<td>48</td>
<td>51</td>
<td>6</td>
<td class="normal">90.6%</td>
<td class="normal">96.2%</td>
</tr>

<tr>
Expand Down
4 changes: 2 additions & 2 deletions magicembed/tests/coverage/modules/magicembed.__init__.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ <h1>
1 total statements,
<span class="normal">100.0% covered</span>
</h1>
<p>Generated: Mon 2015-09-07 14:04 CST</p>
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/__init__.py</p>
<p>Generated: Sat 2015-10-10 18:15 CST</p>
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/__init__.py</p>
<p>
Stats:
<span class="executed">0 executed</span>,
Expand Down
16 changes: 8 additions & 8 deletions magicembed/tests/coverage/modules/magicembed.providers.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@
<h1>
<span id="module-name">magicembed.providers</span>:
59 total statements,
<span class="normal">90.6% covered</span>
<span class="normal">96.2% covered</span>
</h1>
<p>Generated: Mon 2015-09-07 14:04 CST</p>
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/providers.py</p>
<p>Generated: Sat 2015-10-10 18:15 CST</p>
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/providers.py</p>
<p>
Stats:
<span class="executed">48 executed</span>,
<span class="missed">5 missed</span>,
<span class="executed">51 executed</span>,
<span class="missed">2 missed</span>,
<span class="excluded">6 excluded</span>,
<span class="ignored">31 ignored</span>
</p>
Expand Down Expand Up @@ -209,7 +209,7 @@ <h1>
<li class="executed"><code> if key is not None:</code></li>
<li class="executed"><code> self.api_url = 'http://api.embed.ly/1/oembed?key=%s&amp;url=%s&amp;maxwidth=%s&amp;format=json' % (key, url, size[0])</code></li>
<li class="ignored"><code> else:</code></li>
<li class="missed"><code> raise ImproperlyConfigured("If you want to use this please set the Embedly api key")</code></li>
<li class="executed"><code> raise ImproperlyConfigured("If you want to use this please set the Embedly api key")</code></li>
<li class="ignored"><code></code></li>
<li class="executed"><code> def render_video(self):</code></li>
<li class="executed"><code> return self._call_api()['html']</code></li>
Expand All @@ -220,8 +220,8 @@ <h1>
<li class="executed"><code> def _call_api(self):</code></li>
<li class="executed"><code> try:</code></li>
<li class="executed"><code> data = json.loads(urllib.urlopen(self.api_url).read())</code></li>
<li class="missed"><code> except ImproperlyConfigured:</code></li>
<li class="missed"><code> raise ImproperlyConfigured("Please set the Embedly api key correctly")</code></li>
<li class="executed"><code> except IOError:</code></li>
<li class="executed"><code> raise ImproperlyConfigured("Please set the Embedly api key correctly")</code></li>
<li class="executed"><code> return data</code></li>
<li class="ignored"><code></code></li>
<li class="ignored"><code></code></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ <h1>
12 total statements,
<span class="normal">100.0% covered</span>
</h1>
<p>Generated: Mon 2015-09-07 14:04 CST</p>
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/templatetags/magicembed_tags.py</p>
<p>Generated: Sat 2015-10-10 18:15 CST</p>
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/templatetags/magicembed_tags.py</p>
<p>
Stats:
<span class="executed">9 executed</span>,
Expand Down
25 changes: 21 additions & 4 deletions magicembed/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-
import unittest

from mock import MagicMock, patch

from django.core.exceptions import ImproperlyConfigured
from django.template import Template, Context
from django.test import TestCase

try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings

from magicembed.providers import (Youtube, Vimeo, Embedly, get_provider)


class ProvidersTest(unittest.TestCase):
class ProvidersTest(TestCase):
def testYoutube(self):
video = 'http://www.youtube.com/watch?v=693m7iCh-TE'
yt = Youtube(video, (640, 510))
Expand Down Expand Up @@ -46,6 +51,18 @@ def testEmbedly(self, urllib_mock):
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'
vimeo = 'http://vimeo.com/21443752'
Expand All @@ -56,7 +73,7 @@ def test_return_provider(self):
self.assertTrue(isinstance(get_provider(blip), Embedly))


class TemplateTagsTest(unittest.TestCase):
class TemplateTagsTest(TestCase):

def test_magicembed_tag(self):
TEMPLATE = Template('''{% load magicembed_tags %} {{ 'http://vimeo.com/21443752/'|magicembed:"400x225" }}''')
Expand Down

0 comments on commit 62e432c

Please sign in to comment.