Skip to content

Commit 62e432c

Browse files
committed
Merge pull request #13 from josernestodavila/test_exceptions_raised
Test Exceptions Raised.
2 parents 3c488e2 + 984c2d7 commit 62e432c

File tree

10 files changed

+41
-24
lines changed

10 files changed

+41
-24
lines changed

.coverage

2.88 KB
Binary file not shown.

magicembed/providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def render_thumbnail(self):
7575
def _call_api(self):
7676
try:
7777
data = json.loads(urllib.urlopen(self.api_url).read())
78-
except ImproperlyConfigured:
78+
except IOError:
7979
raise ImproperlyConfigured("Please set the Embedly api key correctly")
8080
return data
8181

84 Bytes
Loading

magicembed/tests/coverage/errors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<body>
4545

4646
<div id="content-header">
47-
<h1>Test Coverage Report: error packages and modules</h1><p>Generated: Mon 2015-09-07 14:04 CST</p></div>
47+
<h1>Test Coverage Report: error packages and modules</h1><p>Generated: Sat 2015-10-10 18:15 CST</p></div>
4848
<div id="result-list">
4949
<p> <code>django_coverage.utils.module_tools.find_or_load_module</code> had
5050
problems importing these packages and modules:

magicembed/tests/coverage/excludes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<body>
4545

4646
<div id="content-header">
47-
<h1>Test Coverage Report: excluded packages and modules</h1><p>Generated: Mon 2015-09-07 14:04 CST</p></div>
47+
<h1>Test Coverage Report: excluded packages and modules</h1><p>Generated: Sat 2015-10-10 18:15 CST</p></div>
4848
<div id="result-list">
4949
<p> These packages and modules were excluded from the coverage analysis in
5050
<code>django.conf.settings.COVERAGE_MODULE_EXCLUDES</code> or they do

magicembed/tests/coverage/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

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

@@ -139,9 +139,9 @@ <h1>Test Coverage Report</h1>
139139
<tr>
140140
<td class="module-name">Total</td>
141141
<td>72</td>
142-
<td>57</td>
142+
<td>60</td>
143143
<td>10</td>
144-
<td>91.9%</td>
144+
<td>96.8%</td>
145145
</tr>
146146
</tfoot>
147147
<tbody>
@@ -156,9 +156,9 @@ <h1>Test Coverage Report</h1>
156156
<tr>
157157
<td class="module-name"><a href="modules/magicembed.providers.html">magicembed.providers</a></td>
158158
<td>59</td>
159-
<td>48</td>
159+
<td>51</td>
160160
<td>6</td>
161-
<td class="normal">90.6%</td>
161+
<td class="normal">96.2%</td>
162162
</tr>
163163

164164
<tr>

magicembed/tests/coverage/modules/magicembed.__init__.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ <h1>
129129
1 total statements,
130130
<span class="normal">100.0% covered</span>
131131
</h1>
132-
<p>Generated: Mon 2015-09-07 14:04 CST</p>
133-
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/__init__.py</p>
132+
<p>Generated: Sat 2015-10-10 18:15 CST</p>
133+
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/__init__.py</p>
134134
<p>
135135
Stats:
136136
<span class="executed">0 executed</span>,

magicembed/tests/coverage/modules/magicembed.providers.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@
128128
<h1>
129129
<span id="module-name">magicembed.providers</span>:
130130
59 total statements,
131-
<span class="normal">90.6% covered</span>
131+
<span class="normal">96.2% covered</span>
132132
</h1>
133-
<p>Generated: Mon 2015-09-07 14:04 CST</p>
134-
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/providers.py</p>
133+
<p>Generated: Sat 2015-10-10 18:15 CST</p>
134+
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/providers.py</p>
135135
<p>
136136
Stats:
137-
<span class="executed">48 executed</span>,
138-
<span class="missed">5 missed</span>,
137+
<span class="executed">51 executed</span>,
138+
<span class="missed">2 missed</span>,
139139
<span class="excluded">6 excluded</span>,
140140
<span class="ignored">31 ignored</span>
141141
</p>
@@ -209,7 +209,7 @@ <h1>
209209
<li class="executed"><code> if key is not None:</code></li>
210210
<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>
211211
<li class="ignored"><code> else:</code></li>
212-
<li class="missed"><code> raise ImproperlyConfigured("If you want to use this please set the Embedly api key")</code></li>
212+
<li class="executed"><code> raise ImproperlyConfigured("If you want to use this please set the Embedly api key")</code></li>
213213
<li class="ignored"><code></code></li>
214214
<li class="executed"><code> def render_video(self):</code></li>
215215
<li class="executed"><code> return self._call_api()['html']</code></li>
@@ -220,8 +220,8 @@ <h1>
220220
<li class="executed"><code> def _call_api(self):</code></li>
221221
<li class="executed"><code> try:</code></li>
222222
<li class="executed"><code> data = json.loads(urllib.urlopen(self.api_url).read())</code></li>
223-
<li class="missed"><code> except ImproperlyConfigured:</code></li>
224-
<li class="missed"><code> raise ImproperlyConfigured("Please set the Embedly api key correctly")</code></li>
223+
<li class="executed"><code> except IOError:</code></li>
224+
<li class="executed"><code> raise ImproperlyConfigured("Please set the Embedly api key correctly")</code></li>
225225
<li class="executed"><code> return data</code></li>
226226
<li class="ignored"><code></code></li>
227227
<li class="ignored"><code></code></li>

magicembed/tests/coverage/modules/magicembed.templatetags.magicembed_tags.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ <h1>
129129
12 total statements,
130130
<span class="normal">100.0% covered</span>
131131
</h1>
132-
<p>Generated: Mon 2015-09-07 14:04 CST</p>
133-
<p>Source file: /home/jdavila/workspace/django/django-magicembed/magicembed/templatetags/magicembed_tags.py</p>
132+
<p>Generated: Sat 2015-10-10 18:15 CST</p>
133+
<p>Source file: /home/jdavila/workspace/django/Proyectos/django-magicembed/magicembed/templatetags/magicembed_tags.py</p>
134134
<p>
135135
Stats:
136136
<span class="executed">9 executed</span>,

magicembed/tests/test.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# -*- coding: utf-8 -*-
2-
import unittest
3-
42
from mock import MagicMock, patch
53

4+
from django.core.exceptions import ImproperlyConfigured
65
from django.template import Template, Context
6+
from django.test import TestCase
7+
8+
try:
9+
from django.test import override_settings
10+
except ImportError:
11+
from django.test.utils import override_settings
712

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

1015

11-
class ProvidersTest(unittest.TestCase):
16+
class ProvidersTest(TestCase):
1217
def testYoutube(self):
1318
video = 'http://www.youtube.com/watch?v=693m7iCh-TE'
1419
yt = Youtube(video, (640, 510))
@@ -46,6 +51,18 @@ def testEmbedly(self, urllib_mock):
4651
with patch('magicembed.providers.json.loads', api_call_mock):
4752
self.assertEqual(blip.render_thumbnail(), thumbnail)
4853

54+
@override_settings(EMBEDLY_KEY=None)
55+
def test_Embedly_without_api_key(self):
56+
with self.assertRaises(ImproperlyConfigured):
57+
Embedly('https://vine.co/v/eHHOtXV5lxT')
58+
59+
def test_call_Embedly_api_without_key(self):
60+
blip = Embedly('https://vine.co/v/eHHOtXV5lxT', (600, 400))
61+
62+
with self.settings(EMBEDLY_KEY=None):
63+
with self.assertRaises(ImproperlyConfigured):
64+
blip.render_thumbnail()
65+
4966
def test_return_provider(self):
5067
yt = 'http://www.youtube.com/watch?v=693m7iCh-TE'
5168
vimeo = 'http://vimeo.com/21443752'
@@ -56,7 +73,7 @@ def test_return_provider(self):
5673
self.assertTrue(isinstance(get_provider(blip), Embedly))
5774

5875

59-
class TemplateTagsTest(unittest.TestCase):
76+
class TemplateTagsTest(TestCase):
6077

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

0 commit comments

Comments
 (0)