summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/test_management.py
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-08 12:09:55 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-08 12:15:38 +0100
commit6a682b38e75d4c975b4c4493565a59f1bc14397c (patch)
tree0bd9cda550bea26238656d9f120d769e8b41bb9e /tests/staticfiles_tests/test_management.py
parente73ce08888e6f34d3f050377cfd2fbb733be94a9 (diff)
[4.0.x] Refs #33476 -- Reformatted code with Black.
Backport of 9c19aff7c7561e3a82978a272ecdaad40dda5c00 from main.
Diffstat (limited to 'tests/staticfiles_tests/test_management.py')
-rw-r--r--tests/staticfiles_tests/test_management.py269
1 files changed, 163 insertions, 106 deletions
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index 7ebac48239..afc8cc1637 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -11,9 +11,7 @@ from admin_scripts.tests import AdminScriptTestCase
from django.conf import settings
from django.contrib.staticfiles import storage
-from django.contrib.staticfiles.management.commands import (
- collectstatic, runserver,
-)
+from django.contrib.staticfiles.management.commands import collectstatic, runserver
from django.core.exceptions import ImproperlyConfigured
from django.core.management import CommandError, call_command
from django.core.management.base import SystemCheckError
@@ -29,7 +27,6 @@ from .storage import DummyStorage
class TestNoFilesCreated:
-
def test_no_files_created(self):
"""
Make sure no files were create in the destination directory.
@@ -38,17 +35,17 @@ class TestNoFilesCreated:
class TestRunserver(StaticFilesTestCase):
- @override_settings(MIDDLEWARE=['django.middleware.common.CommonMiddleware'])
+ @override_settings(MIDDLEWARE=["django.middleware.common.CommonMiddleware"])
def test_middleware_loaded_only_once(self):
command = runserver.Command()
- with mock.patch('django.middleware.common.CommonMiddleware') as mocked:
+ with mock.patch("django.middleware.common.CommonMiddleware") as mocked:
command.get_handler(use_static_handler=True, insecure_serving=True)
self.assertEqual(mocked.call_count, 1)
def test_404_response(self):
command = runserver.Command()
handler = command.get_handler(use_static_handler=True, insecure_serving=True)
- missing_static_file = os.path.join(settings.STATIC_URL, 'unknown.css')
+ missing_static_file = os.path.join(settings.STATIC_URL, "unknown.css")
req = RequestFactory().get(missing_static_file)
with override_settings(DEBUG=False):
response = handler.get_response(req)
@@ -62,75 +59,98 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
"""
Test ``findstatic`` management command.
"""
+
def _get_file(self, filepath):
- path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=StringIO())
- with open(path, encoding='utf-8') as f:
+ path = call_command(
+ "findstatic", filepath, all=False, verbosity=0, stdout=StringIO()
+ )
+ with open(path, encoding="utf-8") as f:
return f.read()
def test_all_files(self):
"""
findstatic returns all candidate files if run without --first and -v1.
"""
- result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=StringIO())
- lines = [line.strip() for line in result.split('\n')]
- self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
- self.assertIn('project', lines[1])
- self.assertIn('apps', lines[2])
+ result = call_command(
+ "findstatic", "test/file.txt", verbosity=1, stdout=StringIO()
+ )
+ lines = [line.strip() for line in result.split("\n")]
+ self.assertEqual(
+ len(lines), 3
+ ) # three because there is also the "Found <file> here" line
+ self.assertIn("project", lines[1])
+ self.assertIn("apps", lines[2])
def test_all_files_less_verbose(self):
"""
findstatic returns all candidate files if run without --first and -v0.
"""
- result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=StringIO())
- lines = [line.strip() for line in result.split('\n')]
+ result = call_command(
+ "findstatic", "test/file.txt", verbosity=0, stdout=StringIO()
+ )
+ lines = [line.strip() for line in result.split("\n")]
self.assertEqual(len(lines), 2)
- self.assertIn('project', lines[0])
- self.assertIn('apps', lines[1])
+ self.assertIn("project", lines[0])
+ self.assertIn("apps", lines[1])
def test_all_files_more_verbose(self):
"""
findstatic returns all candidate files if run without --first and -v2.
Also, test that findstatic returns the searched locations with -v2.
"""
- result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=StringIO())
- lines = [line.strip() for line in result.split('\n')]
- self.assertIn('project', lines[1])
- self.assertIn('apps', lines[2])
+ result = call_command(
+ "findstatic", "test/file.txt", verbosity=2, stdout=StringIO()
+ )
+ lines = [line.strip() for line in result.split("\n")]
+ self.assertIn("project", lines[1])
+ self.assertIn("apps", lines[2])
self.assertIn("Looking in the following locations:", lines[3])
- searched_locations = ', '.join(lines[4:])
+ searched_locations = ", ".join(lines[4:])
# AppDirectoriesFinder searched locations
- self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), searched_locations)
- self.assertIn(os.path.join('staticfiles_tests', 'apps', 'no_label', 'static'), searched_locations)
+ self.assertIn(
+ os.path.join("staticfiles_tests", "apps", "test", "static"),
+ searched_locations,
+ )
+ self.assertIn(
+ os.path.join("staticfiles_tests", "apps", "no_label", "static"),
+ searched_locations,
+ )
# FileSystemFinder searched locations
- self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][1][1], searched_locations)
- self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][0], searched_locations)
- self.assertIn(str(TEST_SETTINGS['STATICFILES_DIRS'][2]), searched_locations)
+ self.assertIn(TEST_SETTINGS["STATICFILES_DIRS"][1][1], searched_locations)
+ self.assertIn(TEST_SETTINGS["STATICFILES_DIRS"][0], searched_locations)
+ self.assertIn(str(TEST_SETTINGS["STATICFILES_DIRS"][2]), searched_locations)
# DefaultStorageFinder searched locations
self.assertIn(
- os.path.join('staticfiles_tests', 'project', 'site_media', 'media'),
- searched_locations
+ os.path.join("staticfiles_tests", "project", "site_media", "media"),
+ searched_locations,
)
class TestConfiguration(StaticFilesTestCase):
def test_location_empty(self):
- msg = 'without having set the STATIC_ROOT setting to a filesystem path'
+ msg = "without having set the STATIC_ROOT setting to a filesystem path"
err = StringIO()
- for root in ['', None]:
+ for root in ["", None]:
with override_settings(STATIC_ROOT=root):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
- call_command('collectstatic', interactive=False, verbosity=0, stderr=err)
+ call_command(
+ "collectstatic", interactive=False, verbosity=0, stderr=err
+ )
def test_local_storage_detection_helper(self):
staticfiles_storage = storage.staticfiles_storage
try:
storage.staticfiles_storage._wrapped = empty
- with self.settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'):
+ with self.settings(
+ STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage"
+ ):
command = collectstatic.Command()
self.assertTrue(command.is_local_storage())
storage.staticfiles_storage._wrapped = empty
- with self.settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage'):
+ with self.settings(
+ STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage"
+ ):
command = collectstatic.Command()
self.assertFalse(command.is_local_storage())
@@ -146,11 +166,11 @@ class TestConfiguration(StaticFilesTestCase):
collectstatic.staticfiles_storage = staticfiles_storage
storage.staticfiles_storage = staticfiles_storage
- @override_settings(STATICFILES_DIRS=('test'))
+ @override_settings(STATICFILES_DIRS=("test"))
def test_collectstatis_check(self):
- msg = 'The STATICFILES_DIRS setting is not a tuple or list.'
+ msg = "The STATICFILES_DIRS setting is not a tuple or list."
with self.assertRaisesMessage(SystemCheckError, msg):
- call_command('collectstatic', skip_checks=False)
+ call_command("collectstatic", skip_checks=False)
class TestCollectionHelpSubcommand(AdminScriptTestCase):
@@ -160,8 +180,8 @@ class TestCollectionHelpSubcommand(AdminScriptTestCase):
Even if the STATIC_ROOT setting is not set, one can still call the
`manage.py help collectstatic` command.
"""
- self.write_settings('settings.py', apps=['django.contrib.staticfiles'])
- out, err = self.run_manage(['help', 'collectstatic'])
+ self.write_settings("settings.py", apps=["django.contrib.staticfiles"])
+ out, err = self.run_manage(["help", "collectstatic"])
self.assertNoOutput(err)
@@ -169,22 +189,23 @@ class TestCollection(TestDefaults, CollectionTestCase):
"""
Test ``collectstatic`` management command.
"""
+
def test_ignore(self):
"""
-i patterns are ignored.
"""
- self.assertFileNotFound('test/test.ignoreme')
+ self.assertFileNotFound("test/test.ignoreme")
def test_common_ignore_patterns(self):
"""
Common ignore patterns (*~, .*, CVS) are ignored.
"""
- self.assertFileNotFound('test/.hidden')
- self.assertFileNotFound('test/backup~')
- self.assertFileNotFound('test/CVS')
+ self.assertFileNotFound("test/.hidden")
+ self.assertFileNotFound("test/backup~")
+ self.assertFileNotFound("test/CVS")
def test_pathlib(self):
- self.assertFileContains('pathlib.txt', 'pathlib')
+ self.assertFileContains("pathlib.txt", "pathlib")
class TestCollectionPathLib(TestCollection):
@@ -194,15 +215,15 @@ class TestCollectionPathLib(TestCollection):
class TestCollectionVerbosity(CollectionTestCase):
- copying_msg = 'Copying '
+ copying_msg = "Copying "
run_collectstatic_in_setUp = False
- post_process_msg = 'Post-processed'
- staticfiles_copied_msg = 'static files copied to'
+ post_process_msg = "Post-processed"
+ staticfiles_copied_msg = "static files copied to"
def test_verbosity_0(self):
stdout = StringIO()
self.run_collectstatic(verbosity=0, stdout=stdout)
- self.assertEqual(stdout.getvalue(), '')
+ self.assertEqual(stdout.getvalue(), "")
def test_verbosity_1(self):
stdout = StringIO()
@@ -218,13 +239,17 @@ class TestCollectionVerbosity(CollectionTestCase):
self.assertIn(self.staticfiles_copied_msg, output)
self.assertIn(self.copying_msg, output)
- @override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage')
+ @override_settings(
+ STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
+ )
def test_verbosity_1_with_post_process(self):
stdout = StringIO()
self.run_collectstatic(verbosity=1, stdout=stdout, post_process=True)
self.assertNotIn(self.post_process_msg, stdout.getvalue())
- @override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage')
+ @override_settings(
+ STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
+ )
def test_verbosity_2_with_post_process(self):
stdout = StringIO()
self.run_collectstatic(verbosity=2, stdout=stdout, post_process=True)
@@ -235,23 +260,26 @@ class TestCollectionClear(CollectionTestCase):
"""
Test the ``--clear`` option of the ``collectstatic`` management command.
"""
+
def run_collectstatic(self, **kwargs):
- clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt')
- with open(clear_filepath, 'w') as f:
- f.write('should be cleared')
+ clear_filepath = os.path.join(settings.STATIC_ROOT, "cleared.txt")
+ with open(clear_filepath, "w") as f:
+ f.write("should be cleared")
super().run_collectstatic(clear=True)
def test_cleared_not_found(self):
- self.assertFileNotFound('cleared.txt')
+ self.assertFileNotFound("cleared.txt")
def test_dir_not_exists(self, **kwargs):
shutil.rmtree(settings.STATIC_ROOT)
super().run_collectstatic(clear=True)
- @override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.PathNotImplementedStorage')
+ @override_settings(
+ STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage"
+ )
def test_handle_path_notimplemented(self):
self.run_collectstatic()
- self.assertFileNotFound('cleared.txt')
+ self.assertFileNotFound("cleared.txt")
class TestInteractiveMessages(CollectionTestCase):
@@ -263,14 +291,15 @@ class TestInteractiveMessages(CollectionTestCase):
def mock_input(stdout):
def _input(msg):
stdout.write(msg)
- return 'yes'
+ return "yes"
+
return _input
def test_warning_when_clearing_staticdir(self):
stdout = StringIO()
self.run_collectstatic()
- with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
- call_command('collectstatic', interactive=True, clear=True, stdout=stdout)
+ with mock.patch("builtins.input", side_effect=self.mock_input(stdout)):
+ call_command("collectstatic", interactive=True, clear=True, stdout=stdout)
output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
@@ -279,8 +308,8 @@ class TestInteractiveMessages(CollectionTestCase):
def test_warning_when_overwriting_files_in_staticdir(self):
stdout = StringIO()
self.run_collectstatic()
- with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
- call_command('collectstatic', interactive=True, stdout=stdout)
+ with mock.patch("builtins.input", side_effect=self.mock_input(stdout)):
+ call_command("collectstatic", interactive=True, stdout=stdout)
output = stdout.getvalue()
self.assertIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
@@ -288,7 +317,7 @@ class TestInteractiveMessages(CollectionTestCase):
def test_no_warning_when_staticdir_does_not_exist(self):
stdout = StringIO()
shutil.rmtree(settings.STATIC_ROOT)
- call_command('collectstatic', interactive=True, stdout=stdout)
+ call_command("collectstatic", interactive=True, stdout=stdout)
output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
@@ -296,9 +325,11 @@ class TestInteractiveMessages(CollectionTestCase):
def test_no_warning_for_empty_staticdir(self):
stdout = StringIO()
- with tempfile.TemporaryDirectory(prefix='collectstatic_empty_staticdir_test') as static_dir:
+ with tempfile.TemporaryDirectory(
+ prefix="collectstatic_empty_staticdir_test"
+ ) as static_dir:
with override_settings(STATIC_ROOT=static_dir):
- call_command('collectstatic', interactive=True, stdout=stdout)
+ call_command("collectstatic", interactive=True, stdout=stdout)
output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
@@ -306,9 +337,11 @@ class TestInteractiveMessages(CollectionTestCase):
def test_cancelled(self):
self.run_collectstatic()
- with mock.patch('builtins.input', side_effect=lambda _: 'no'):
- with self.assertRaisesMessage(CommandError, 'Collecting static files cancelled'):
- call_command('collectstatic', interactive=True)
+ with mock.patch("builtins.input", side_effect=lambda _: "no"):
+ with self.assertRaisesMessage(
+ CommandError, "Collecting static files cancelled"
+ ):
+ call_command("collectstatic", interactive=True)
class TestCollectionNoDefaultIgnore(TestDefaults, CollectionTestCase):
@@ -316,6 +349,7 @@ class TestCollectionNoDefaultIgnore(TestDefaults, CollectionTestCase):
The ``--no-default-ignore`` option of the ``collectstatic`` management
command.
"""
+
def run_collectstatic(self):
super().run_collectstatic(use_default_ignore_patterns=False)
@@ -324,35 +358,40 @@ class TestCollectionNoDefaultIgnore(TestDefaults, CollectionTestCase):
With --no-default-ignore, common ignore patterns (*~, .*, CVS)
are not ignored.
"""
- self.assertFileContains('test/.hidden', 'should be ignored')
- self.assertFileContains('test/backup~', 'should be ignored')
- self.assertFileContains('test/CVS', 'should be ignored')
+ self.assertFileContains("test/.hidden", "should be ignored")
+ self.assertFileContains("test/backup~", "should be ignored")
+ self.assertFileContains("test/CVS", "should be ignored")
-@override_settings(INSTALLED_APPS=[
- 'staticfiles_tests.apps.staticfiles_config.IgnorePatternsAppConfig',
- 'staticfiles_tests.apps.test',
-])
+@override_settings(
+ INSTALLED_APPS=[
+ "staticfiles_tests.apps.staticfiles_config.IgnorePatternsAppConfig",
+ "staticfiles_tests.apps.test",
+ ]
+)
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
def test_custom_ignore_patterns(self):
"""
A custom ignore_patterns list, ['*.css', '*/vendor/*.js'] in this case,
can be specified in an AppConfig definition.
"""
- self.assertFileNotFound('test/nonascii.css')
- self.assertFileContains('test/.hidden', 'should be ignored')
- self.assertFileNotFound(os.path.join('test', 'vendor', 'module.js'))
+ self.assertFileNotFound("test/nonascii.css")
+ self.assertFileContains("test/.hidden", "should be ignored")
+ self.assertFileNotFound(os.path.join("test", "vendor", "module.js"))
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
"""
Test ``--dry-run`` option for ``collectstatic`` management command.
"""
+
def run_collectstatic(self):
super().run_collectstatic(dry_run=True)
-@override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage')
+@override_settings(
+ STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
+)
class TestCollectionDryRunManifestStaticFilesStorage(TestCollectionDryRun):
pass
@@ -365,12 +404,15 @@ class TestCollectionFilesOverride(CollectionTestCase):
'staticfiles_test_app',
'staticfiles_tests.apps.no_label',
"""
+
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.temp_dir)
# get modification and access times for no_label/static/file2.txt
- self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt')
+ self.orig_path = os.path.join(
+ TEST_ROOT, "apps", "no_label", "static", "file2.txt"
+ )
self.orig_mtime = os.path.getmtime(self.orig_path)
self.orig_atime = os.path.getatime(self.orig_path)
@@ -378,21 +420,21 @@ class TestCollectionFilesOverride(CollectionTestCase):
# this file will have modification time older than no_label/static/file2.txt
# anyway it should be taken to STATIC_ROOT because the temporary app is before
# 'no_label' app in installed apps
- self.temp_app_path = os.path.join(self.temp_dir, 'staticfiles_test_app')
- self.testfile_path = os.path.join(self.temp_app_path, 'static', 'file2.txt')
+ self.temp_app_path = os.path.join(self.temp_dir, "staticfiles_test_app")
+ self.testfile_path = os.path.join(self.temp_app_path, "static", "file2.txt")
os.makedirs(self.temp_app_path)
- with open(os.path.join(self.temp_app_path, '__init__.py'), 'w+'):
+ with open(os.path.join(self.temp_app_path, "__init__.py"), "w+"):
pass
os.makedirs(os.path.dirname(self.testfile_path))
- with open(self.testfile_path, 'w+') as f:
- f.write('duplicate of file2.txt')
+ with open(self.testfile_path, "w+") as f:
+ f.write("duplicate of file2.txt")
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
self.settings_with_test_app = self.modify_settings(
- INSTALLED_APPS={'prepend': 'staticfiles_test_app'},
+ INSTALLED_APPS={"prepend": "staticfiles_test_app"},
)
with extend_sys_path(self.temp_dir):
self.settings_with_test_app.enable()
@@ -407,12 +449,12 @@ class TestCollectionFilesOverride(CollectionTestCase):
"""
Test if collectstatic takes files in proper order
"""
- self.assertFileContains('file2.txt', 'duplicate of file2.txt')
+ self.assertFileContains("file2.txt", "duplicate of file2.txt")
# run collectstatic again
self.run_collectstatic()
- self.assertFileContains('file2.txt', 'duplicate of file2.txt')
+ self.assertFileContains("file2.txt", "duplicate of file2.txt")
# The collectstatic test suite already has conflicting files since both
@@ -425,9 +467,10 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
Test warning in ``collectstatic`` output when a file is skipped because a
previous file was already written to the same path.
"""
+
# If this string is in the collectstatic output, it means the warning we're
# looking for was emitted.
- warning_string = 'Found another file'
+ warning_string = "Found another file"
def _collectstatic_output(self, **kwargs):
"""
@@ -436,7 +479,9 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
just call e.g. BaseCollectionTestCase.run_collectstatic()
"""
out = StringIO()
- call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs)
+ call_command(
+ "collectstatic", interactive=False, verbosity=3, stdout=out, **kwargs
+ )
return out.getvalue()
def test_no_warning(self):
@@ -451,10 +496,10 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
There is a warning when there are duplicate destinations.
"""
with tempfile.TemporaryDirectory() as static_dir:
- duplicate = os.path.join(static_dir, 'test', 'file.txt')
+ duplicate = os.path.join(static_dir, "test", "file.txt")
os.mkdir(os.path.dirname(duplicate))
- with open(duplicate, 'w+') as f:
- f.write('duplicate of file.txt')
+ with open(duplicate, "w+") as f:
+ f.write("duplicate of file.txt")
with self.settings(STATICFILES_DIRS=[static_dir]):
output = self._collectstatic_output(clear=True)
@@ -468,23 +513,30 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
self.assertNotIn(self.warning_string, output)
-@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
+@override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage")
class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase):
"""
Tests for a Storage that implements get_modified_time() but not path()
(#15035).
"""
+
def test_storage_properties(self):
# Properties of the Storage as described in the ticket.
storage = DummyStorage()
- self.assertEqual(storage.get_modified_time('name'), datetime.datetime(1970, 1, 1, tzinfo=timezone.utc))
- with self.assertRaisesMessage(NotImplementedError, "This backend doesn't support absolute paths."):
- storage.path('name')
+ self.assertEqual(
+ storage.get_modified_time("name"),
+ datetime.datetime(1970, 1, 1, tzinfo=timezone.utc),
+ )
+ with self.assertRaisesMessage(
+ NotImplementedError, "This backend doesn't support absolute paths."
+ ):
+ storage.path("name")
class TestCollectionNeverCopyStorage(CollectionTestCase):
-
- @override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.NeverCopyRemoteStorage')
+ @override_settings(
+ STATICFILES_STORAGE="staticfiles_tests.storage.NeverCopyRemoteStorage"
+ )
def test_skips_newer_files_in_remote_storage(self):
"""
collectstatic skips newer files in a remote storage.
@@ -508,6 +560,7 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase):
the standard file resolving tests here, to make sure using
``--link`` does not change the file-selection semantics.
"""
+
def run_collectstatic(self, clear=False, link=True, **kwargs):
super().run_collectstatic(link=link, clear=clear, **kwargs)
@@ -515,13 +568,13 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase):
"""
With ``--link``, symbolic links are created.
"""
- self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt')))
+ self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, "test.txt")))
def test_broken_symlink(self):
"""
Test broken symlink gets deleted.
"""
- path = os.path.join(settings.STATIC_ROOT, 'test.txt')
+ path = os.path.join(settings.STATIC_ROOT, "test.txt")
os.unlink(path)
self.run_collectstatic()
self.assertTrue(os.path.islink(path))
@@ -531,7 +584,7 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase):
Running collectstatic in non-symlink mode replaces symlinks with files,
while symlink mode replaces files with symlinks.
"""
- path = os.path.join(settings.STATIC_ROOT, 'test.txt')
+ path = os.path.join(settings.STATIC_ROOT, "test.txt")
self.assertTrue(os.path.islink(path))
self.run_collectstatic(link=False)
self.assertFalse(os.path.islink(path))
@@ -542,13 +595,17 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase):
"""
With ``--clear``, broken symbolic links are deleted.
"""
- nonexistent_file_path = os.path.join(settings.STATIC_ROOT, 'nonexistent.txt')
- broken_symlink_path = os.path.join(settings.STATIC_ROOT, 'symlink.txt')
+ nonexistent_file_path = os.path.join(settings.STATIC_ROOT, "nonexistent.txt")
+ broken_symlink_path = os.path.join(settings.STATIC_ROOT, "symlink.txt")
os.symlink(nonexistent_file_path, broken_symlink_path)
self.run_collectstatic(clear=True)
self.assertFalse(os.path.lexists(broken_symlink_path))
- @override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.PathNotImplementedStorage')
+ @override_settings(
+ STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage"
+ )
def test_no_remote_link(self):
- with self.assertRaisesMessage(CommandError, "Can't symlink to a remote destination."):
+ with self.assertRaisesMessage(
+ CommandError, "Can't symlink to a remote destination."
+ ):
self.run_collectstatic()