Skip to content

Commit 850545d

Browse files
committed
Add unit test
1 parent 1ee2a04 commit 850545d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/cache_/tests.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from functools import wraps
55
from unittest import mock
66

7+
from bson import SON
78
from django.conf import settings
89
from django.core import management
910
from django.core.cache import DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches
@@ -919,12 +920,27 @@ def test_get_or_set_version(self):
919920
self.assertIsNone(cache.get("brian", version=3))
920921

921922
def test_get_or_set_racing(self):
922-
with mock.patch(f"{settings.CACHES["default"]["BACKEND"]}.add") as cache_add:
923+
with mock.patch(f"{settings.CACHES['default']['BACKEND']}.add") as cache_add:
923924
# Simulate cache.add() failing to add a value. In that case, the
924925
# default value should be returned.
925926
cache_add.return_value = False
926927
self.assertEqual(cache.get_or_set("key", "default"), "default")
927928

929+
def test_collection_has_indexes(self):
930+
indexes = list(cache.collection.list_indexes())
931+
self.assertTrue(
932+
any(
933+
index["key"] == SON([("expires_at", 1)]) and index.get("expireAfterSeconds") == 0
934+
for index in indexes
935+
)
936+
)
937+
self.assertTrue(
938+
any(
939+
index["key"] == SON([("key", 1)]) and index.get("unique") is True
940+
for index in indexes
941+
)
942+
)
943+
928944

929945
@override_settings(
930946
CACHES=caches_setting_for_tests(

0 commit comments

Comments
 (0)