|
@@ -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
|