summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Wahl <gwahl@fusionbox.com>2015-04-23 14:25:40 -0600
committerGavin Wahl <gwahl@fusionbox.com>2015-04-23 14:25:40 -0600
commit9093679d3552db9f7360f0841d9d34cf97ef1ae0 (patch)
treeebfae5b13de3950727922f8a2cc63a6660c05c6e
parenta91323b135f26b42eb826984968aa7dcfa8716ab (diff)
downloaddjango-pyscss-9093679d3552db9f7360f0841d9d34cf97ef1ae0.tar.gz
Files are not always available from storage despite DEBUG=False
For example, in tests. So instead of switching on DEBUG, we first try to find a file from the finders, and then fall back to storage if that doesn't work.
-rw-r--r--django_pyscss/utils.py13
-rw-r--r--setup.py1
-rw-r--r--tests/test_scss.py8
3 files changed, 13 insertions, 9 deletions
diff --git a/django_pyscss/utils.py b/django_pyscss/utils.py
index 1f9e4b4..e4222c0 100644
--- a/django_pyscss/utils.py
+++ b/django_pyscss/utils.py
@@ -1,7 +1,6 @@
import fnmatch
import os
-from django.conf import settings
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
@@ -40,8 +39,10 @@ def get_file_from_finders(filename):
def get_file_and_storage(filename):
- # TODO: the switch probably shouldn't be on DEBUG
- if settings.DEBUG:
- return get_file_from_finders(filename)
- else:
- return get_file_from_storage(filename)
+ name, storage = get_file_from_finders(filename)
+ # get_file_from_finders could fail in production if code is a deployed as a
+ # package without it's package_data. In that case, we'd assume that
+ # collectstatic had been run and we can get the file from storage.
+ if storage is None:
+ name, storage = get_file_from_storage(filename)
+ return name, storage
diff --git a/setup.py b/setup.py
index d1b6846..a266788 100644
--- a/setup.py
+++ b/setup.py
@@ -23,6 +23,7 @@ tests_require = [
'Pillow',
'django-compressor>=1.3',
'django-discover-runner',
+ 'mock',
]
diff --git a/tests/test_scss.py b/tests/test_scss.py
index e8095f7..21bcdc8 100644
--- a/tests/test_scss.py
+++ b/tests/test_scss.py
@@ -1,8 +1,8 @@
import os
import re
+import mock
from django.test import TestCase
-from django.test.utils import override_settings
from django.conf import settings
from scss.errors import SassImportError
@@ -99,12 +99,14 @@ class ImportTestMixin(CompilerTestMixin):
self.assertEqual(clean_css(actual), clean_css(PATH_CONFLICT_CONTENTS))
-@override_settings(DEBUG=True)
class FindersImportTest(ImportTestMixin, NoCollectStaticTestCase):
pass
-@override_settings(DEBUG=False)
+# Emulate the condition were collectstatic was run but the source files are no
+# longer available.
+@mock.patch('django_pyscss.utils.get_file_from_finders',
+ new=mock.MagicMock(return_value=(None, None)))
class StorageImportTest(ImportTestMixin, CollectStaticTestCase):
pass