File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 44from functools import wraps
55from unittest import mock
66
7+ from bson import SON
78from django .conf import settings
89from django .core import management
910from 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 (
You can’t perform that action at this time.
0 commit comments