diff options
author | Florian Apolloner <florian@apolloner.eu> | 2022-12-29 16:52:56 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-02 09:53:52 +0100 |
commit | afa2e28205fe708334ad463b6d3b0e9960b945a6 (patch) | |
tree | dd04d81ebdaca8ab8c38f37f5c221923e67cf7cf /tests/staticfiles_tests | |
parent | 75500feecddcb27b6ab65c9057e7317024cef761 (diff) | |
download | django-afa2e28205fe708334ad463b6d3b0e9960b945a6.tar.gz |
Fixed #34235 -- Added ManifestFilesMixin.manifest_hash attribute.
This adds ManifestFilesMixin.manifest_hash attribute exposing a "hash"
of the full manifest. This allows applications to determine when their
static files have changed.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/project/documents/staticfiles_v1.json | 6 | ||||
-rw-r--r-- | tests/staticfiles_tests/test_storage.py | 31 |
2 files changed, 33 insertions, 4 deletions
diff --git a/tests/staticfiles_tests/project/documents/staticfiles_v1.json b/tests/staticfiles_tests/project/documents/staticfiles_v1.json new file mode 100644 index 0000000000..4f85945e3f --- /dev/null +++ b/tests/staticfiles_tests/project/documents/staticfiles_v1.json @@ -0,0 +1,6 @@ +{ + "version": "1.0", + "paths": { + "dummy.txt": "dummy.txt" + } +} diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 077d14bcc4..f2f1899aac 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -436,7 +436,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): # The in-memory version of the manifest matches the one on disk # since a properly created manifest should cover all filenames. if hashed_files: - manifest = storage.staticfiles_storage.load_manifest() + manifest, _ = storage.staticfiles_storage.load_manifest() self.assertEqual(hashed_files, manifest) def test_manifest_exists(self): @@ -463,7 +463,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): def test_parse_cache(self): hashed_files = storage.staticfiles_storage.hashed_files - manifest = storage.staticfiles_storage.load_manifest() + manifest, _ = storage.staticfiles_storage.load_manifest() self.assertEqual(hashed_files, manifest) def test_clear_empties_manifest(self): @@ -476,7 +476,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): hashed_files = storage.staticfiles_storage.hashed_files self.assertIn(cleared_file_name, hashed_files) - manifest_content = storage.staticfiles_storage.load_manifest() + manifest_content, _ = storage.staticfiles_storage.load_manifest() self.assertIn(cleared_file_name, manifest_content) original_path = storage.staticfiles_storage.path(cleared_file_name) @@ -491,7 +491,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): hashed_files = storage.staticfiles_storage.hashed_files self.assertNotIn(cleared_file_name, hashed_files) - manifest_content = storage.staticfiles_storage.load_manifest() + manifest_content, _ = storage.staticfiles_storage.load_manifest() self.assertNotIn(cleared_file_name, manifest_content) def test_missing_entry(self): @@ -535,6 +535,29 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): 2, ) + def test_manifest_hash(self): + # Collect the additional file. + self.run_collectstatic() + + _, manifest_hash_orig = storage.staticfiles_storage.load_manifest() + self.assertNotEqual(manifest_hash_orig, "") + self.assertEqual(storage.staticfiles_storage.manifest_hash, manifest_hash_orig) + # Saving doesn't change the hash. + storage.staticfiles_storage.save_manifest() + self.assertEqual(storage.staticfiles_storage.manifest_hash, manifest_hash_orig) + # Delete the original file from the app, collect with clear. + os.unlink(self._clear_filename) + self.run_collectstatic(clear=True) + # Hash is changed. + _, manifest_hash = storage.staticfiles_storage.load_manifest() + self.assertNotEqual(manifest_hash, manifest_hash_orig) + + def test_manifest_hash_v1(self): + storage.staticfiles_storage.manifest_name = "staticfiles_v1.json" + manifest_content, manifest_hash = storage.staticfiles_storage.load_manifest() + self.assertEqual(manifest_hash, "") + self.assertEqual(manifest_content, {"dummy.txt": "dummy.txt"}) + @override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.NoneHashStorage") class TestCollectionNoneHashStorage(CollectionTestCase): |