diff options
| author | Tim Graham <timograham@gmail.com> | 2017-01-03 19:03:08 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-01-04 12:50:31 -0500 |
| commit | c85831e4b7b5a7e4249df10327175b7251cb012d (patch) | |
| tree | add2d3d1811666d40316a3b22bd08a58483e68e0 /tests | |
| parent | f60d4e704d71b8af3f5ed4651accd33851bdee23 (diff) | |
Fixed #27658 -- Prevented collectstatic from overwriting newer files in remote storages.
Thanks revimi for the initial patch.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/staticfiles_tests/cases.py | 3 | ||||
| -rw-r--r-- | tests/staticfiles_tests/storage.py | 10 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_management.py | 17 |
3 files changed, 28 insertions, 2 deletions
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py index ea16101eb6..009672ee12 100644 --- a/tests/staticfiles_tests/cases.py +++ b/tests/staticfiles_tests/cases.py @@ -82,7 +82,8 @@ class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase): super(CollectionTestCase, self).tearDown() def run_collectstatic(self, **kwargs): - call_command('collectstatic', interactive=False, verbosity=0, + verbosity = kwargs.pop('verbosity', 0) + call_command('collectstatic', interactive=False, verbosity=verbosity, ignore_patterns=['*.ignoreme'], **kwargs) def _get_file(self, filepath): diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py index 12eb032d8e..79e6245f59 100644 --- a/tests/staticfiles_tests/storage.py +++ b/tests/staticfiles_tests/storage.py @@ -1,6 +1,6 @@ import errno import os -from datetime import datetime +from datetime import datetime, timedelta from django.conf import settings from django.contrib.staticfiles.storage import CachedStaticFilesStorage @@ -59,6 +59,14 @@ class PathNotImplementedStorage(storage.Storage): raise NotImplementedError +class NeverCopyRemoteStorage(PathNotImplementedStorage): + """ + Return a future modified time for all files so that nothing is collected. + """ + def get_modified_time(self, name): + return datetime.now() + timedelta(days=30) + + class QueryStringStorage(storage.Storage): def url(self, path): return path + '?a=b&c=d' diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index eb0b83bca9..bbb8567c2a 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -399,6 +399,23 @@ class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase): storage.path('name') +class TestCollectionNeverCopyStorage(CollectionTestCase): + + @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. + run_collectstatic() in setUp() copies the static files, then files are + always skipped after NeverCopyRemoteStorage is activated since + NeverCopyRemoteStorage.get_modified_time() returns a datetime in the + future to simulate an unmodified file. + """ + stdout = six.StringIO() + self.run_collectstatic(stdout=stdout, verbosity=2) + output = force_text(stdout.getvalue()) + self.assertIn("Skipping 'test.txt' (not modified)", output) + + @unittest.skipUnless(symlinks_supported(), "Must be able to symlink to run this test.") class TestCollectionLinks(TestDefaults, CollectionTestCase): """ |
