11# -*- coding: utf-8 -*-
2- import unittest
3-
42from mock import MagicMock , patch
53
4+ from django .core .exceptions import ImproperlyConfigured
65from 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
813from 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