summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests
diff options
context:
space:
mode:
authorJarosław Wygoda <jaroslaw@wygoda.me>2021-06-02 21:44:59 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-08-05 12:40:34 +0200
commitd3c4696596822281c0a5d4b9e3ee27732a4ce092 (patch)
treea9cf2c603c8d9938a83132c0dcc1ac46eea125b5 /tests/staticfiles_tests
parent4fe3774c729f3fd5105b3001fe69a70bdca95ac3 (diff)
downloaddjango-d3c4696596822281c0a5d4b9e3ee27732a4ce092.tar.gz
Fixed #27590 -- Allowed customizing a manifest file storage in ManifestFilesMixin.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r--tests/staticfiles_tests/test_storage.py52
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index d5aa1c1c9d..0a34f64394 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -1,3 +1,4 @@
+import json
import os
import shutil
import sys
@@ -13,7 +14,7 @@ from django.contrib.staticfiles.management.commands.collectstatic import (
Command as CollectstaticCommand,
)
from django.core.management import call_command
-from django.test import override_settings
+from django.test import SimpleTestCase, override_settings
from .cases import CollectionTestCase
from .settings import TEST_ROOT
@@ -499,6 +500,55 @@ class TestCollectionSimpleStorage(CollectionTestCase):
self.assertIn(b"other.deploy12345.css", content)
+class CustomManifestStorage(storage.ManifestStaticFilesStorage):
+ def __init__(self, *args, manifest_storage=None, **kwargs):
+ manifest_storage = storage.StaticFilesStorage(
+ location=kwargs.pop('manifest_location'),
+ )
+ super().__init__(*args, manifest_storage=manifest_storage, **kwargs)
+
+
+class TestCustomManifestStorage(SimpleTestCase):
+ def setUp(self):
+ self.manifest_path = Path(tempfile.mkdtemp())
+ self.addCleanup(shutil.rmtree, self.manifest_path)
+
+ self.staticfiles_storage = CustomManifestStorage(
+ manifest_location=self.manifest_path,
+ )
+ self.manifest_file = self.manifest_path / self.staticfiles_storage.manifest_name
+ # Manifest without paths.
+ self.manifest = {'version': self.staticfiles_storage.manifest_version}
+ with self.manifest_file.open('w') as manifest_file:
+ json.dump(self.manifest, manifest_file)
+
+ def test_read_manifest(self):
+ self.assertEqual(
+ self.staticfiles_storage.read_manifest(),
+ json.dumps(self.manifest),
+ )
+
+ def test_read_manifest_nonexistent(self):
+ os.remove(self.manifest_file)
+ self.assertIsNone(self.staticfiles_storage.read_manifest())
+
+ def test_save_manifest_override(self):
+ self.assertIs(self.manifest_file.exists(), True)
+ self.staticfiles_storage.save_manifest()
+ self.assertIs(self.manifest_file.exists(), True)
+ new_manifest = json.loads(self.staticfiles_storage.read_manifest())
+ self.assertIn('paths', new_manifest)
+ self.assertNotEqual(new_manifest, self.manifest)
+
+ def test_save_manifest_create(self):
+ os.remove(self.manifest_file)
+ self.staticfiles_storage.save_manifest()
+ self.assertIs(self.manifest_file.exists(), True)
+ new_manifest = json.loads(self.staticfiles_storage.read_manifest())
+ self.assertIn('paths', new_manifest)
+ self.assertNotEqual(new_manifest, self.manifest)
+
+
class CustomStaticFilesStorage(storage.StaticFilesStorage):
"""
Used in TestStaticFilePermissions