diff options
| author | Berker Peksag <berker.peksag@gmail.com> | 2016-03-14 05:17:05 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-17 09:51:48 -0400 |
| commit | b4bb2ad13d178dd2db484c7721fd47aa3d285908 (patch) | |
| tree | ea25de5130a0c995de3e9ec4060a9e10cad948ef /tests | |
| parent | f49cfb76c7b24a4fa5f8ac36dfa0a82ab66336c5 (diff) | |
[1.9.x] Fixed #26297 -- Fixed `collectstatic --clear` crash if storage doesn't implement path().
Backport of 28bcff82c5ed4694f4761c303294ffafbd7096ce from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/staticfiles_tests/storage.py | 37 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_management.py | 5 |
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py index fe4811a495..925f4b7fed 100644 --- a/tests/staticfiles_tests/storage.py +++ b/tests/staticfiles_tests/storage.py @@ -1,5 +1,8 @@ +import errno +import os from datetime import datetime +from django.conf import settings from django.contrib.staticfiles.storage import CachedStaticFilesStorage from django.core.files import storage @@ -22,6 +25,40 @@ class DummyStorage(storage.Storage): return datetime.date(1970, 1, 1) +class PathNotImplementedStorage(storage.Storage): + + def _save(self, name, content): + return 'dummy' + + def _path(self, name): + return os.path.join(settings.STATIC_ROOT, name) + + def exists(self, name): + return os.path.exists(self._path(name)) + + def listdir(self, path): + path = self._path(path) + directories, files = [], [] + for entry in os.listdir(path): + if os.path.isdir(os.path.join(path, entry)): + directories.append(entry) + else: + files.append(entry) + return directories, files + + def delete(self, name): + name = self._path(name) + if os.path.exists(name): + try: + os.remove(name) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + def path(self, name): + raise NotImplementedError + + class SimpleCachedStaticFilesStorage(CachedStaticFilesStorage): def file_hash(self, name, content=None): diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 94166f9888..b6c2a9fe87 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -166,6 +166,11 @@ class TestCollectionClear(CollectionTestCase): shutil.rmtree(six.text_type(settings.STATIC_ROOT)) super(TestCollectionClear, self).run_collectstatic(clear=True) + @override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.PathNotImplementedStorage') + def test_handle_path_notimplemented(self): + self.run_collectstatic() + self.assertFileNotFound('cleared.txt') + class TestCollectionExcludeNoDefaultIgnore(CollectionTestCase, TestDefaults): """ |
