瀏覽代碼

Cleaned class inheritances in staticfiles tests

Thanks Tim Graham for precious inputs.
Claude Paroz 9 年之前
父節點
當前提交
859fc64338

+ 6 - 9
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.

+ 0 - 1
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'),

+ 4 - 4
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.
     """

+ 6 - 6
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.
 

+ 13 - 27
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,

+ 4 - 3
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.
     """