summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoreevelweezel <eevel.weezel@gmail.com>2025-12-18 16:17:14 -0600
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-19 13:02:22 -0500
commit948f1bf5a1c1c93ee9c6f4baa2fd990e31361f81 (patch)
tree0e062386c5539b188499accc09007a5825b4b124 /tests
parent7a2f35b1b755b20a1e4d290a88bf059e6897f798 (diff)
Fixed #36590 -- Made async cache methods use specialized sync versions if available.
Thanks Simon Charette, Sarah Boyce, and Jacob Walls for reviews.
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/tests.py86
1 files changed, 85 insertions, 1 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index c4cf0a84e3..db5df20701 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -25,7 +25,7 @@ from django.core.cache import (
cache,
caches,
)
-from django.core.cache.backends.base import InvalidCacheBackendError
+from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from django.core.cache.backends.redis import RedisCacheClient
from django.core.cache.utils import make_template_fragment_key
from django.db import close_old_connections, connection, connections
@@ -1165,6 +1165,90 @@ class BaseCacheTests:
cache_add.return_value = False
self.assertEqual(cache.get_or_set("key", "default"), "default")
+ async def test_get_many_async_uses_specialized_implementation(self):
+ if (
+ cache.get_many.__func__ is not BaseCache.get_many
+ and cache.aget_many.__func__ is BaseCache.aget_many
+ ):
+ with mock.patch.object(cache, "get_many") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aget_many({})
+ mocked.assert_called_once()
+
+ async def test_set_many_async_uses_specialized_implementation(self):
+ if (
+ cache.set_many.__func__ is not BaseCache.set_many
+ and cache.aset_many.__func__ is BaseCache.aset_many
+ ):
+ with mock.patch.object(cache, "set_many") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aset_many({})
+ mocked.assert_called_once()
+
+ async def test_delete_many_async_uses_specialized_implementation(self):
+ if (
+ cache.delete_many.__func__ is not BaseCache.delete_many
+ and cache.adelete_many.__func__ is BaseCache.adelete_many
+ ):
+ with mock.patch.object(cache, "delete_many") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.adelete_many({})
+ mocked.assert_called_once()
+
+ async def test_get_or_set_async_uses_specialized_implementation(self):
+ await cache.aset("key", "value")
+ if (
+ cache.get_or_set.__func__ is not BaseCache.get_or_set
+ and cache.aget_or_set.__func__ is BaseCache.aget_or_set
+ ):
+ with mock.patch.object(cache, "get_or_set") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aget_or_set("key")
+ mocked.assert_called_once()
+
+ async def test_has_key_async_uses_specialized_implementation(self):
+ await cache.aset("key", "value")
+ if (
+ cache.has_key.__func__ is not BaseCache.has_key
+ and cache.ahas_key.__func__ is BaseCache.ahas_key
+ ):
+ with mock.patch.object(cache, "has_key") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.ahas_key("key")
+ mocked.assert_called_once()
+
+ async def test_incr_async_uses_specialized_implementation(self):
+ await cache.aset("key", 1)
+ if (
+ cache.incr.__func__ is not BaseCache.incr
+ and cache.aincr.__func__ is BaseCache.aincr
+ ):
+ with mock.patch.object(cache, "incr") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aincr("key")
+ mocked.assert_called_once()
+
+ async def test_incr_version_async_uses_specialized_implementation(self):
+ await cache.aset("key", "value", version=1)
+ if (
+ cache.incr_version.__func__ is not BaseCache.incr_version
+ and cache.aincr_version.__func__ is BaseCache.aincr_version
+ ):
+ with mock.patch.object(cache, "incr_version") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aincr_version("key")
+ mocked.assert_called_once()
+
+ async def test_close_async_uses_specialized_implementation(self):
+ if (
+ cache.close.__func__ is not BaseCache.close
+ and cache.aclose.__func__ is BaseCache.aclose
+ ):
+ with mock.patch.object(cache, "close") as mocked:
+ mocked.__func__ = lambda x: x
+ await cache.aclose()
+ mocked.assert_called_once()
+
@override_settings(
CACHES=caches_setting_for_tests(