diff --git a/sorl/thumbnail/images.py b/sorl/thumbnail/images.py index 862e45f2c..890a3fa69 100644 --- a/sorl/thumbnail/images.py +++ b/sorl/thumbnail/images.py @@ -182,7 +182,7 @@ def write(self, content): def delete(self): return self.storage.delete(self.name) - def serialize_storage(self): + def serialize_storage(self, use_backend_name=False): if isinstance(self.storage, LazyObject): # if storage is wrapped in a lazy object we need to get the real # thing. @@ -192,6 +192,8 @@ def serialize_storage(self): else: cls = self.storage.__class__ backend = f"{cls.__module__}.{cls.__name__}" + if use_backend_name: + return backend # Try our best to find and serialize the storage alias instead of the backend class. for alias, params in storages.backends.items(): if params.get("BACKEND") == backend: @@ -200,7 +202,7 @@ def serialize_storage(self): @property def key(self): - return tokey(self.name, self.serialize_storage()) + return tokey(self.name, self.serialize_storage(use_backend_name=True)) def serialize(self): return serialize_image_file(self) diff --git a/tests/thumbnail_tests/test_alternative_resolutions.py b/tests/thumbnail_tests/test_alternative_resolutions.py index 92f80914e..7ebeb0f26 100644 --- a/tests/thumbnail_tests/test_alternative_resolutions.py +++ b/tests/thumbnail_tests/test_alternative_resolutions.py @@ -23,7 +23,7 @@ def tearDown(self): def test_retina(self): get_thumbnail(self.image, '50x50') - cache_path = "test/cache/2c/0f/2c0f909d420e760b8dc4e1d1f79e705b" + cache_path = "test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d" actions = [ f"exists: {cache_path}.jpg", diff --git a/tests/thumbnail_tests/test_backends.py b/tests/thumbnail_tests/test_backends.py index 726a1f064..864ecaff2 100644 --- a/tests/thumbnail_tests/test_backends.py +++ b/tests/thumbnail_tests/test_backends.py @@ -133,7 +133,7 @@ def setUp(self): def test_nonascii(self): # also test the get_thumbnail shortcut th = get_thumbnail(self.name, '200x200') - self.assertEqual(th.url, '/media/test/cache/79/48/79489fd416471a8850d1c7c6f7a28343.jpg') + self.assertEqual(th.url, '/media/test/cache/f5/26/f52608b56718f62abc45a90ff9459f2c.jpg') def tearDown(self): shutil.rmtree(settings.MEDIA_ROOT) diff --git a/tests/thumbnail_tests/test_engines.py b/tests/thumbnail_tests/test_engines.py index a67536abc..8171c2059 100644 --- a/tests/thumbnail_tests/test_engines.py +++ b/tests/thumbnail_tests/test_engines.py @@ -172,6 +172,25 @@ def test_storage_serialize(self): 'default', ) + self.assertEqual( + im.serialize_storage(use_backend_name=True), + 'tests.thumbnail_tests.storage.TestStorage', + ) + self.assertEqual( + ImageFile('http://www.image.jpg').serialize_storage(use_backend_name=True), + 'sorl.thumbnail.images.UrlStorage', + ) + self.assertEqual( + ImageFile('http://www.image.jpg', default.storage).serialize_storage( + use_backend_name=True + ), + 'tests.thumbnail_tests.storage.TestStorage', + ) + self.assertEqual( + ImageFile('getit', default_storage).serialize_storage(use_backend_name=True), + 'tests.thumbnail_tests.storage.TestStorage', + ) + @unittest.skipIf(platform.system() == "Darwin", 'quality is saved a different way on os x') def test_quality(self): im = ImageFile(Item.objects.get(image='500x500.jpg').image) diff --git a/tests/thumbnail_tests/test_filters.py b/tests/thumbnail_tests/test_filters.py index 2a10e7617..763c0c935 100644 --- a/tests/thumbnail_tests/test_filters.py +++ b/tests/thumbnail_tests/test_filters.py @@ -20,7 +20,7 @@ def test_html_filter_local_url(self): self.assertEqual( 'A image!', + 'src="/media/test/cache/c7/f2/c7f2880b48e9f07d46a05472c22f0fde.jpg" />', val ) @@ -38,6 +38,6 @@ def test_markdown_filter_local_url(self): val = render_to_string('markdownfilter.html', {'text': text, }).strip() self.assertEqual( - '![A image!](/media/test/cache/62/5b/625b3d4c6020c1179d7888ca8d29845d.jpg)', + '![A image!](/media/test/cache/c7/f2/c7f2880b48e9f07d46a05472c22f0fde.jpg)', val ) diff --git a/tests/thumbnail_tests/test_storage.py b/tests/thumbnail_tests/test_storage.py index 2f389c80f..4390dfd46 100644 --- a/tests/thumbnail_tests/test_storage.py +++ b/tests/thumbnail_tests/test_storage.py @@ -13,7 +13,7 @@ class StorageTestCase(BaseStorageTestCase): def test_new(self): get_thumbnail(self.image, '50x50') - cache_path = "test/cache/55/ce/55ceec8f0d3f20a89304da3a65644db0.jpg" + cache_path = "test/cache/45/bb/45bbbdab11e235a80e603aa119e8786b.jpg" actions = [ f"exists: {cache_path}", # open the original for thumbnailing diff --git a/tests/thumbnail_tests/test_templatetags.py b/tests/thumbnail_tests/test_templatetags.py index bb880d832..02fa90d4c 100644 --- a/tests/thumbnail_tests/test_templatetags.py +++ b/tests/thumbnail_tests/test_templatetags.py @@ -26,8 +26,8 @@ def test_nested(self): item = Item.objects.get(image='500x500.jpg') val = render_to_string('thumbnail6.html', {'item': item, }).strip() self.assertEqual(val, ( - '' - '' + '' )) @@ -195,10 +195,10 @@ def test_nested(self): self.assertEqual( val, ( - '' - '' + '' ) )