summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-03-26 16:17:06 +0100
committerClaude Paroz <claude@2xlibre.net>2016-03-28 19:46:03 +0200
commit859fc64338f760508f9618c100ad92b925802b18 (patch)
tree48948db21cdf691ac27a3f56033a5a3e01800d7d
parent1c8c0837c61a9e9eb2129df29f75be92e47e926c (diff)
Cleaned class inheritances in staticfiles tests
Thanks Tim Graham for precious inputs.
-rw-r--r--tests/staticfiles_tests/cases.py15
-rw-r--r--tests/staticfiles_tests/settings.py1
-rw-r--r--tests/staticfiles_tests/test_finders.py8
-rw-r--r--tests/staticfiles_tests/test_management.py12
-rw-r--r--tests/staticfiles_tests/test_storage.py40
-rw-r--r--tests/staticfiles_tests/test_views.py7
6 files changed, 33 insertions, 50 deletions
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py
index 941c45274a..abc4f1e81b 100644
--- a/tests/staticfiles_tests/cases.py
+++ b/tests/staticfiles_tests/cases.py
@@ -16,7 +16,7 @@ from django.utils.encoding import force_text
from .settings import TEST_SETTINGS
-class BaseStaticFilesTestCase(object):
+class BaseStaticFilesMixin(object):
"""
Test case with a couple utility assertions.
"""
@@ -52,11 +52,12 @@ class BaseStaticFilesTestCase(object):
@override_settings(**TEST_SETTINGS)
-class StaticFilesTestCase(BaseStaticFilesTestCase, SimpleTestCase):
+class StaticFilesTestCase(BaseStaticFilesMixin, SimpleTestCase):
pass
-class BaseCollectionTestCase(BaseStaticFilesTestCase):
+@override_settings(**TEST_SETTINGS)
+class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase):
"""
Tests shared by all file finding features (collectstatic,
findstatic, and static serve view).
@@ -66,7 +67,7 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
all these tests.
"""
def setUp(self):
- super(BaseCollectionTestCase, self).setUp()
+ super(CollectionTestCase, self).setUp()
temp_dir = tempfile.mkdtemp()
# Override the STATIC_ROOT for all tests from setUp to tearDown
# rather than as a context manager
@@ -78,7 +79,7 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
def tearDown(self):
self.patched_settings.disable()
- super(BaseCollectionTestCase, self).tearDown()
+ super(CollectionTestCase, self).tearDown()
def run_collectstatic(self, **kwargs):
call_command('collectstatic', interactive=False, verbosity=0,
@@ -91,10 +92,6 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
return f.read()
-class CollectionTestCase(BaseCollectionTestCase, StaticFilesTestCase):
- pass
-
-
class TestDefaults(object):
"""
A few standard test cases.
diff --git a/tests/staticfiles_tests/settings.py b/tests/staticfiles_tests/settings.py
index ea20a84c6f..caf42b2505 100644
--- a/tests/staticfiles_tests/settings.py
+++ b/tests/staticfiles_tests/settings.py
@@ -7,7 +7,6 @@ from django.utils._os import upath
TEST_ROOT = os.path.dirname(upath(__file__))
TEST_SETTINGS = {
- 'DEBUG': True,
'MEDIA_URL': '/media/',
'STATIC_URL': '/static/',
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
diff --git a/tests/staticfiles_tests/test_finders.py b/tests/staticfiles_tests/test_finders.py
index 0aa95e06c3..7355113ad6 100644
--- a/tests/staticfiles_tests/test_finders.py
+++ b/tests/staticfiles_tests/test_finders.py
@@ -11,7 +11,7 @@ from .cases import StaticFilesTestCase
from .settings import TEST_ROOT
-class FinderTestCase(object):
+class TestFinders(object):
"""
Base finder test mixin.
@@ -32,7 +32,7 @@ class FinderTestCase(object):
self.assertEqual(found, dst)
-class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
+class TestFileSystemFinder(TestFinders, StaticFilesTestCase):
"""
Test FileSystemFinder.
"""
@@ -44,7 +44,7 @@ class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
self.find_all = (os.path.join('test', 'file.txt'), [test_file_path])
-class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
+class TestAppDirectoriesFinder(TestFinders, StaticFilesTestCase):
"""
Test AppDirectoriesFinder.
"""
@@ -56,7 +56,7 @@ class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path])
-class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase):
+class TestDefaultStorageFinder(TestFinders, StaticFilesTestCase):
"""
Test DefaultStorageFinder.
"""
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index fa47f12b49..f0c6384df7 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -34,7 +34,7 @@ class TestNoFilesCreated(object):
self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
-class TestFindStatic(CollectionTestCase, TestDefaults):
+class TestFindStatic(TestDefaults, CollectionTestCase):
"""
Test ``findstatic`` management command.
"""
@@ -134,7 +134,7 @@ class TestCollectionHelpSubcommand(AdminScriptTestCase):
self.assertNoOutput(err)
-class TestCollection(CollectionTestCase, TestDefaults):
+class TestCollection(TestDefaults, CollectionTestCase):
"""
Test ``collectstatic`` management command.
"""
@@ -176,7 +176,7 @@ class TestCollectionClear(CollectionTestCase):
self.assertFileNotFound('cleared.txt')
-class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults):
+class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
"""
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
``collectstatic`` management command.
@@ -195,7 +195,7 @@ class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults):
self.assertFileContains('test/CVS', 'should be ignored')
-class TestCollectionDryRun(CollectionTestCase, TestNoFilesCreated):
+class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
"""
Test ``--dry-run`` option for ``collectstatic`` management command.
"""
@@ -316,7 +316,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
-class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
+class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase):
"""
Tests for #15035
"""
@@ -324,7 +324,7 @@ class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
@unittest.skipUnless(symlinks_supported(), "Must be able to symlink to run this test.")
-class TestCollectionLinks(CollectionTestCase, TestDefaults):
+class TestCollectionLinks(TestDefaults, CollectionTestCase):
"""
Test ``--link`` option for ``collectstatic`` management command.
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index b52d0ef597..bd636c4a8c 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -12,14 +12,12 @@ from django.contrib.staticfiles.management.commands.collectstatic import \
Command as CollectstaticCommand
from django.core.cache.backends.base import BaseCache
from django.core.management import call_command
-from django.test import SimpleTestCase, override_settings
+from django.test import override_settings
from django.utils import six
from django.utils.encoding import force_text
-from .cases import (
- BaseCollectionTestCase, BaseStaticFilesTestCase, StaticFilesTestCase,
-)
-from .settings import TEST_ROOT, TEST_SETTINGS
+from .cases import CollectionTestCase
+from .settings import TEST_ROOT
def hashed_file_path(test, path):
@@ -199,14 +197,10 @@ class TestHashedFiles(object):
self.assertEqual("Post-processing 'faulty.css' failed!\n\n", err.getvalue())
-# we set DEBUG to False here since the template tag wouldn't work otherwise
-@override_settings(**dict(
- TEST_SETTINGS,
+@override_settings(
STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
- DEBUG=False,
-))
-class TestCollectionCachedStorage(TestHashedFiles, BaseCollectionTestCase,
- BaseStaticFilesTestCase, SimpleTestCase):
+)
+class TestCollectionCachedStorage(TestHashedFiles, CollectionTestCase):
"""
Tests for the Cache busting storage
"""
@@ -243,14 +237,10 @@ class TestCollectionCachedStorage(TestHashedFiles, BaseCollectionTestCase,
self.assertEqual(cache_key, 'staticfiles:821ea71ef36f95b3922a77f7364670e7')
-# we set DEBUG to False here since the template tag wouldn't work otherwise
-@override_settings(**dict(
- TEST_SETTINGS,
+@override_settings(
STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage',
- DEBUG=False,
-))
-class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
- BaseStaticFilesTestCase, SimpleTestCase):
+)
+class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
"""
Tests for the Cache busting storage
"""
@@ -321,14 +311,10 @@ class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
self.assertNotIn(cleared_file_name, manifest_content)
-# we set DEBUG to False here since the template tag wouldn't work otherwise
-@override_settings(**dict(
- TEST_SETTINGS,
+@override_settings(
STATICFILES_STORAGE='staticfiles_tests.storage.SimpleCachedStaticFilesStorage',
- DEBUG=False,
-))
-class TestCollectionSimpleCachedStorage(BaseCollectionTestCase,
- BaseStaticFilesTestCase, SimpleTestCase):
+)
+class TestCollectionSimpleCachedStorage(CollectionTestCase):
"""
Tests for the Cache busting storage
"""
@@ -364,7 +350,7 @@ class CustomStaticFilesStorage(storage.StaticFilesStorage):
@unittest.skipIf(sys.platform.startswith('win'), "Windows only partially supports chmod.")
-class TestStaticFilePermissions(BaseCollectionTestCase, StaticFilesTestCase):
+class TestStaticFilePermissions(CollectionTestCase):
command_params = {
'interactive': False,
diff --git a/tests/staticfiles_tests/test_views.py b/tests/staticfiles_tests/test_views.py
index e9b484b3f7..6d9096784f 100644
--- a/tests/staticfiles_tests/test_views.py
+++ b/tests/staticfiles_tests/test_views.py
@@ -33,14 +33,15 @@ class TestServeDisabled(TestServeStatic):
self.assertFileNotFound('test.txt')
-class TestServeStaticWithDefaultURL(TestServeStatic, TestDefaults):
+@override_settings(DEBUG=True)
+class TestServeStaticWithDefaultURL(TestDefaults, TestServeStatic):
"""
Test static asset serving view with manually configured URLconf.
"""
-@override_settings(ROOT_URLCONF='staticfiles_tests.urls.helper')
-class TestServeStaticWithURLHelper(TestServeStatic, TestDefaults):
+@override_settings(DEBUG=True, ROOT_URLCONF='staticfiles_tests.urls.helper')
+class TestServeStaticWithURLHelper(TestDefaults, TestServeStatic):
"""
Test static asset serving view with staticfiles_urlpatterns helper.
"""