Cleaned class inheritances in staticfiles tests
Thanks Tim Graham for precious inputs.
This commit is contained in:
parent
1c8c0837c6
commit
859fc64338
|
@ -16,7 +16,7 @@ from django.utils.encoding import force_text
|
||||||
from .settings import TEST_SETTINGS
|
from .settings import TEST_SETTINGS
|
||||||
|
|
||||||
|
|
||||||
class BaseStaticFilesTestCase(object):
|
class BaseStaticFilesMixin(object):
|
||||||
"""
|
"""
|
||||||
Test case with a couple utility assertions.
|
Test case with a couple utility assertions.
|
||||||
"""
|
"""
|
||||||
|
@ -52,11 +52,12 @@ class BaseStaticFilesTestCase(object):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(**TEST_SETTINGS)
|
@override_settings(**TEST_SETTINGS)
|
||||||
class StaticFilesTestCase(BaseStaticFilesTestCase, SimpleTestCase):
|
class StaticFilesTestCase(BaseStaticFilesMixin, SimpleTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BaseCollectionTestCase(BaseStaticFilesTestCase):
|
@override_settings(**TEST_SETTINGS)
|
||||||
|
class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
Tests shared by all file finding features (collectstatic,
|
Tests shared by all file finding features (collectstatic,
|
||||||
findstatic, and static serve view).
|
findstatic, and static serve view).
|
||||||
|
@ -66,7 +67,7 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
|
||||||
all these tests.
|
all these tests.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseCollectionTestCase, self).setUp()
|
super(CollectionTestCase, self).setUp()
|
||||||
temp_dir = tempfile.mkdtemp()
|
temp_dir = tempfile.mkdtemp()
|
||||||
# Override the STATIC_ROOT for all tests from setUp to tearDown
|
# Override the STATIC_ROOT for all tests from setUp to tearDown
|
||||||
# rather than as a context manager
|
# rather than as a context manager
|
||||||
|
@ -78,7 +79,7 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.patched_settings.disable()
|
self.patched_settings.disable()
|
||||||
super(BaseCollectionTestCase, self).tearDown()
|
super(CollectionTestCase, self).tearDown()
|
||||||
|
|
||||||
def run_collectstatic(self, **kwargs):
|
def run_collectstatic(self, **kwargs):
|
||||||
call_command('collectstatic', interactive=False, verbosity=0,
|
call_command('collectstatic', interactive=False, verbosity=0,
|
||||||
|
@ -91,10 +92,6 @@ class BaseCollectionTestCase(BaseStaticFilesTestCase):
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
class CollectionTestCase(BaseCollectionTestCase, StaticFilesTestCase):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestDefaults(object):
|
class TestDefaults(object):
|
||||||
"""
|
"""
|
||||||
A few standard test cases.
|
A few standard test cases.
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.utils._os import upath
|
||||||
TEST_ROOT = os.path.dirname(upath(__file__))
|
TEST_ROOT = os.path.dirname(upath(__file__))
|
||||||
|
|
||||||
TEST_SETTINGS = {
|
TEST_SETTINGS = {
|
||||||
'DEBUG': True,
|
|
||||||
'MEDIA_URL': '/media/',
|
'MEDIA_URL': '/media/',
|
||||||
'STATIC_URL': '/static/',
|
'STATIC_URL': '/static/',
|
||||||
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
||||||
|
|
|
@ -11,7 +11,7 @@ from .cases import StaticFilesTestCase
|
||||||
from .settings import TEST_ROOT
|
from .settings import TEST_ROOT
|
||||||
|
|
||||||
|
|
||||||
class FinderTestCase(object):
|
class TestFinders(object):
|
||||||
"""
|
"""
|
||||||
Base finder test mixin.
|
Base finder test mixin.
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class FinderTestCase(object):
|
||||||
self.assertEqual(found, dst)
|
self.assertEqual(found, dst)
|
||||||
|
|
||||||
|
|
||||||
class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
|
class TestFileSystemFinder(TestFinders, StaticFilesTestCase):
|
||||||
"""
|
"""
|
||||||
Test FileSystemFinder.
|
Test FileSystemFinder.
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +44,7 @@ class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
|
||||||
self.find_all = (os.path.join('test', 'file.txt'), [test_file_path])
|
self.find_all = (os.path.join('test', 'file.txt'), [test_file_path])
|
||||||
|
|
||||||
|
|
||||||
class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
|
class TestAppDirectoriesFinder(TestFinders, StaticFilesTestCase):
|
||||||
"""
|
"""
|
||||||
Test AppDirectoriesFinder.
|
Test AppDirectoriesFinder.
|
||||||
"""
|
"""
|
||||||
|
@ -56,7 +56,7 @@ class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
|
||||||
self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path])
|
self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path])
|
||||||
|
|
||||||
|
|
||||||
class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase):
|
class TestDefaultStorageFinder(TestFinders, StaticFilesTestCase):
|
||||||
"""
|
"""
|
||||||
Test DefaultStorageFinder.
|
Test DefaultStorageFinder.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TestNoFilesCreated(object):
|
||||||
self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
|
self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
|
||||||
|
|
||||||
|
|
||||||
class TestFindStatic(CollectionTestCase, TestDefaults):
|
class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Test ``findstatic`` management command.
|
Test ``findstatic`` management command.
|
||||||
"""
|
"""
|
||||||
|
@ -134,7 +134,7 @@ class TestCollectionHelpSubcommand(AdminScriptTestCase):
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
|
|
||||||
|
|
||||||
class TestCollection(CollectionTestCase, TestDefaults):
|
class TestCollection(TestDefaults, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Test ``collectstatic`` management command.
|
Test ``collectstatic`` management command.
|
||||||
"""
|
"""
|
||||||
|
@ -176,7 +176,7 @@ class TestCollectionClear(CollectionTestCase):
|
||||||
self.assertFileNotFound('cleared.txt')
|
self.assertFileNotFound('cleared.txt')
|
||||||
|
|
||||||
|
|
||||||
class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults):
|
class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
|
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
|
||||||
``collectstatic`` management command.
|
``collectstatic`` management command.
|
||||||
|
@ -195,7 +195,7 @@ class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults):
|
||||||
self.assertFileContains('test/CVS', 'should be ignored')
|
self.assertFileContains('test/CVS', 'should be ignored')
|
||||||
|
|
||||||
|
|
||||||
class TestCollectionDryRun(CollectionTestCase, TestNoFilesCreated):
|
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Test ``--dry-run`` option for ``collectstatic`` management command.
|
Test ``--dry-run`` option for ``collectstatic`` management command.
|
||||||
"""
|
"""
|
||||||
|
@ -316,7 +316,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
|
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
|
||||||
class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
|
class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
Tests for #15035
|
Tests for #15035
|
||||||
"""
|
"""
|
||||||
|
@ -324,7 +324,7 @@ class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(symlinks_supported(), "Must be able to symlink to run this test.")
|
@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.
|
Test ``--link`` option for ``collectstatic`` management command.
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,12 @@ from django.contrib.staticfiles.management.commands.collectstatic import \
|
||||||
Command as CollectstaticCommand
|
Command as CollectstaticCommand
|
||||||
from django.core.cache.backends.base import BaseCache
|
from django.core.cache.backends.base import BaseCache
|
||||||
from django.core.management import call_command
|
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 import six
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
from .cases import (
|
from .cases import CollectionTestCase
|
||||||
BaseCollectionTestCase, BaseStaticFilesTestCase, StaticFilesTestCase,
|
from .settings import TEST_ROOT
|
||||||
)
|
|
||||||
from .settings import TEST_ROOT, TEST_SETTINGS
|
|
||||||
|
|
||||||
|
|
||||||
def hashed_file_path(test, path):
|
def hashed_file_path(test, path):
|
||||||
|
@ -199,14 +197,10 @@ class TestHashedFiles(object):
|
||||||
self.assertEqual("Post-processing 'faulty.css' failed!\n\n", err.getvalue())
|
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(
|
||||||
@override_settings(**dict(
|
|
||||||
TEST_SETTINGS,
|
|
||||||
STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
|
STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
|
||||||
DEBUG=False,
|
)
|
||||||
))
|
class TestCollectionCachedStorage(TestHashedFiles, CollectionTestCase):
|
||||||
class TestCollectionCachedStorage(TestHashedFiles, BaseCollectionTestCase,
|
|
||||||
BaseStaticFilesTestCase, SimpleTestCase):
|
|
||||||
"""
|
"""
|
||||||
Tests for the Cache busting storage
|
Tests for the Cache busting storage
|
||||||
"""
|
"""
|
||||||
|
@ -243,14 +237,10 @@ class TestCollectionCachedStorage(TestHashedFiles, BaseCollectionTestCase,
|
||||||
self.assertEqual(cache_key, 'staticfiles:821ea71ef36f95b3922a77f7364670e7')
|
self.assertEqual(cache_key, 'staticfiles:821ea71ef36f95b3922a77f7364670e7')
|
||||||
|
|
||||||
|
|
||||||
# we set DEBUG to False here since the template tag wouldn't work otherwise
|
@override_settings(
|
||||||
@override_settings(**dict(
|
|
||||||
TEST_SETTINGS,
|
|
||||||
STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage',
|
STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage',
|
||||||
DEBUG=False,
|
)
|
||||||
))
|
class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
|
||||||
class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
|
|
||||||
BaseStaticFilesTestCase, SimpleTestCase):
|
|
||||||
"""
|
"""
|
||||||
Tests for the Cache busting storage
|
Tests for the Cache busting storage
|
||||||
"""
|
"""
|
||||||
|
@ -321,14 +311,10 @@ class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
|
||||||
self.assertNotIn(cleared_file_name, manifest_content)
|
self.assertNotIn(cleared_file_name, manifest_content)
|
||||||
|
|
||||||
|
|
||||||
# we set DEBUG to False here since the template tag wouldn't work otherwise
|
@override_settings(
|
||||||
@override_settings(**dict(
|
|
||||||
TEST_SETTINGS,
|
|
||||||
STATICFILES_STORAGE='staticfiles_tests.storage.SimpleCachedStaticFilesStorage',
|
STATICFILES_STORAGE='staticfiles_tests.storage.SimpleCachedStaticFilesStorage',
|
||||||
DEBUG=False,
|
)
|
||||||
))
|
class TestCollectionSimpleCachedStorage(CollectionTestCase):
|
||||||
class TestCollectionSimpleCachedStorage(BaseCollectionTestCase,
|
|
||||||
BaseStaticFilesTestCase, SimpleTestCase):
|
|
||||||
"""
|
"""
|
||||||
Tests for the Cache busting storage
|
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.")
|
@unittest.skipIf(sys.platform.startswith('win'), "Windows only partially supports chmod.")
|
||||||
class TestStaticFilePermissions(BaseCollectionTestCase, StaticFilesTestCase):
|
class TestStaticFilePermissions(CollectionTestCase):
|
||||||
|
|
||||||
command_params = {
|
command_params = {
|
||||||
'interactive': False,
|
'interactive': False,
|
||||||
|
|
|
@ -33,14 +33,15 @@ class TestServeDisabled(TestServeStatic):
|
||||||
self.assertFileNotFound('test.txt')
|
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.
|
Test static asset serving view with manually configured URLconf.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='staticfiles_tests.urls.helper')
|
@override_settings(DEBUG=True, ROOT_URLCONF='staticfiles_tests.urls.helper')
|
||||||
class TestServeStaticWithURLHelper(TestServeStatic, TestDefaults):
|
class TestServeStaticWithURLHelper(TestDefaults, TestServeStatic):
|
||||||
"""
|
"""
|
||||||
Test static asset serving view with staticfiles_urlpatterns helper.
|
Test static asset serving view with staticfiles_urlpatterns helper.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue