kopia lustrzana https://github.com/wagtail/wagtail
Add `Rendition.cache_backend` tests
- to ensure correct backend is selected - for purging image renditions with cachepull/10666/head
rodzic
b05e675ceb
commit
8767f40f45
|
@ -3,7 +3,7 @@ import warnings
|
|||
from io import StringIO
|
||||
|
||||
from django.core import management
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from .utils import Image, get_test_image_file
|
||||
|
||||
|
@ -12,6 +12,8 @@ Rendition = Image.get_rendition_model()
|
|||
|
||||
|
||||
class TestUpdateImageRenditions(TestCase):
|
||||
REAESC = re.compile(r"\x1b[^m]*m")
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.image = Image.objects.create(
|
||||
|
@ -65,7 +67,7 @@ class TestUpdateImageRenditions(TestCase):
|
|||
renditions = Rendition.objects.all()
|
||||
total_renditions = len(renditions)
|
||||
output = self.run_command()
|
||||
output_string = self.reaesc.sub("", output.read())
|
||||
output_string = self.REAESC.sub("", output.read())
|
||||
# checking if the number of renditions regenerated equal total_renditions
|
||||
self.assertEqual(
|
||||
output_string,
|
||||
|
@ -82,7 +84,7 @@ class TestUpdateImageRenditions(TestCase):
|
|||
renditions = Rendition.objects.all()
|
||||
total_renditions = len(renditions)
|
||||
output = self.run_command(purge_only=True)
|
||||
output_string = self.reaesc.sub("", output.read())
|
||||
output_string = self.REAESC.sub("", output.read())
|
||||
# checking if the number of renditions purged equal total_renditions
|
||||
self.assertEqual(
|
||||
output_string,
|
||||
|
@ -94,3 +96,23 @@ class TestUpdateImageRenditions(TestCase):
|
|||
renditions_now = Rendition.objects.all()
|
||||
total_renditions_now = len(renditions_now)
|
||||
self.assertEqual(total_renditions_now, 0)
|
||||
|
||||
@override_settings(
|
||||
CACHES={"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
|
||||
)
|
||||
def test_image_renditions_with_cache(self):
|
||||
total_renditions = get_image_model().get_rendition_model().objects.count()
|
||||
output = self.run_command()
|
||||
output_string = self.REAESC.sub("", output.read())
|
||||
self.assertEqual(
|
||||
output_string,
|
||||
f"Successfully regenerated {total_renditions} image rendition(s)\n",
|
||||
)
|
||||
|
||||
# Run the command again with a warmed cache
|
||||
output = self.run_command()
|
||||
output_string = self.REAESC.sub("", output.read())
|
||||
self.assertEqual(
|
||||
output_string,
|
||||
f"Successfully regenerated {total_renditions} image rendition(s)\n",
|
||||
)
|
||||
|
|
|
@ -491,8 +491,8 @@ class TestRenditions(TestCase):
|
|||
},
|
||||
},
|
||||
)
|
||||
def test_renditions_cache_backend(self):
|
||||
cache = caches["renditions"]
|
||||
def test_renditions_cache(self):
|
||||
cache = Rendition.cache_backend
|
||||
rendition = self.image.get_rendition("width-500")
|
||||
rendition_cache_key = rendition.get_cache_key()
|
||||
|
||||
|
@ -531,6 +531,29 @@ class TestRenditions(TestCase):
|
|||
new_rendition = self.image.get_rendition("width-500")
|
||||
self.assertFalse(hasattr(new_rendition, "_mark"))
|
||||
|
||||
def test_prefers_rendition_cache_backend(self):
|
||||
with override_settings(
|
||||
CACHES={
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
||||
},
|
||||
"renditions": {
|
||||
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
||||
},
|
||||
}
|
||||
):
|
||||
self.assertEqual(Rendition.cache_backend, caches["renditions"])
|
||||
|
||||
def test_uses_default_cache_when_no_renditions_cache(self):
|
||||
with override_settings(
|
||||
CACHES={
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
||||
}
|
||||
}
|
||||
):
|
||||
self.assertEqual(Rendition.cache_backend, caches["default"])
|
||||
|
||||
def test_focal_point(self):
|
||||
self.image.focal_point_x = 100
|
||||
self.image.focal_point_y = 200
|
||||
|
|
Ładowanie…
Reference in New Issue