Skip to content

Commit 3028a36

Browse files
author
Stephen Burrows
committed
Updated tests to account for configurable css loaders
1 parent 448b226 commit 3028a36

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

django_inlinecss/tests/test_css_loaders.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
"""
22
Test CSS loaders
33
"""
4+
from __future__ import absolute_import
5+
from __future__ import division
6+
from __future__ import print_function
7+
from __future__ import unicode_literals
8+
9+
from django.conf import settings
410
from django.test import TestCase
11+
from django.test import override_settings
512

6-
from django_inlinecss.css_loaders import StaticFinderCSSLoader, StaticPathCSSLoader
13+
from django_inlinecss.css_loaders import StaticfilesFinderCSSLoader
14+
from django_inlinecss.css_loaders import StaticfilesStorageCSSLoader
715

816

9-
class StaticFinderCSSLoaderTestCase(TestCase):
17+
@override_settings(STATICFILES_DIRS=[settings.STATIC_ROOT], STATIC_ROOT='')
18+
class StaticfilesFinderCSSLoaderTestCase(TestCase):
1019
def setUp(self):
11-
self.loader = StaticFinderCSSLoader()
12-
super(StaticFinderCSSLoaderTestCase, self).setUp()
20+
self.loader = StaticfilesFinderCSSLoader()
21+
super(StaticfilesFinderCSSLoaderTestCase, self).setUp()
1322

14-
def test_debug_mode_uses_staticfiles_finder(self):
23+
def test_loads_existing_css_file(self):
1524
css = self.loader.load('bar.css')
1625
self.assertIn('div.bar {', css)
1726

18-
def test_load_file_does_not_exists(self):
27+
def test_load_file_does_not_exist(self):
1928
with self.assertRaises(IOError) as e:
2029
self.loader.load('missing.css')
2130

22-
self.assertEqual(e.exception.strerror, 'No such file or directory')
31+
self.assertEqual(str(e.exception), 'missing.css does not exist')
2332

2433

25-
class StaticPathCSSLoaderTestCase(TestCase):
34+
class StaticfilesStorageCSSLoaderTestCase(TestCase):
2635
def setUp(self):
27-
self.loader = StaticPathCSSLoader()
28-
super(StaticPathCSSLoaderTestCase, self).setUp()
36+
self.loader = StaticfilesStorageCSSLoader()
37+
super(StaticfilesStorageCSSLoaderTestCase, self).setUp()
2938

30-
def test_load_existing_css_file(self):
39+
def test_loads_existing_css_file(self):
3140
css = self.loader.load('bar.css')
3241
self.assertIn('div.bar {', css)
3342

34-
def test_load_file_does_not_exists(self):
43+
def test_load_file_does_not_exist(self):
3544
with self.assertRaises(IOError) as e:
3645
self.loader.load('missing.css')
3746

django_inlinecss/tests/test_templatetags.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,26 @@ def test_comments_are_ignored(self):
150150
r'This is the "bar" div.\s+<!-- comment three -->\s+')
151151

152152

153-
class DebugModeStaticfilesTests(TestCase):
154-
@override_settings(DEBUG=True)
155-
@patch('django.contrib.staticfiles.finders.find')
156-
def test_debug_mode_uses_staticfiles_finder(self, find):
153+
class GetLoaderStaticfilesTests(TestCase):
154+
@patch('django.contrib.staticfiles.storage.staticfiles_storage.path')
155+
def test_default_uses_staticfiles_storage(self, path):
157156
full_path = os.path.join(
158157
settings.STATIC_ROOT,
159158
'foobar.css',
160159
)
161-
find.return_value = full_path
160+
path.return_value = full_path
162161
template = get_template('single_staticfiles_css.html')
163162
template.render({})
164-
find.assert_called_once_with("foobar.css")
163+
path.assert_called_once_with("foobar.css")
165164

166-
@patch('django.contrib.staticfiles.storage.staticfiles_storage.path')
167-
def test_non_debug_mode_uses_staticfiles_storage(self, path):
165+
@override_settings(INLINECSS_CSS_LOADER='django_inlinecss.css_loaders.StaticfilesFinderCSSLoader')
166+
@patch('django.contrib.staticfiles.finders.find')
167+
def test_override_uses_staticfiles_finder(self, find):
168168
full_path = os.path.join(
169169
settings.STATIC_ROOT,
170170
'foobar.css',
171171
)
172-
path.return_value = full_path
172+
find.return_value = full_path
173173
template = get_template('single_staticfiles_css.html')
174174
template.render({})
175-
path.assert_called_once_with("foobar.css")
175+
find.assert_called_once_with("foobar.css")

0 commit comments

Comments
 (0)