summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/storage.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-03-14 05:17:05 +0200
committerTim Graham <timograham@gmail.com>2016-03-17 09:49:57 -0400
commit28bcff82c5ed4694f4761c303294ffafbd7096ce (patch)
tree3cf2a2b00766d1e368c7c61e2732aec5f42491af /tests/staticfiles_tests/storage.py
parentecb59cc6579402b68ddfd4499bf30edacf5963be (diff)
Fixed #26297 -- Fixed `collectstatic --clear` crash if storage doesn't implement path().
Diffstat (limited to 'tests/staticfiles_tests/storage.py')
-rw-r--r--tests/staticfiles_tests/storage.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py
index 3e972552f2..06caebfcd2 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
from django.utils import timezone
@@ -22,6 +25,40 @@ class DummyStorage(storage.Storage):
return datetime.datetime(1970, 1, 1, tzinfo=timezone.utc)
+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):