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 4
4
from functools import wraps
5
5
from unittest import mock
6
6
7
+ from bson import SON
7
8
from django .conf import settings
8
9
from django .core import management
9
10
from django .core .cache import DEFAULT_CACHE_ALIAS , CacheKeyWarning , cache , caches
@@ -919,12 +920,27 @@ def test_get_or_set_version(self):
919
920
self .assertIsNone (cache .get ("brian" , version = 3 ))
920
921
921
922
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 :
923
924
# Simulate cache.add() failing to add a value. In that case, the
924
925
# default value should be returned.
925
926
cache_add .return_value = False
926
927
self .assertEqual (cache .get_or_set ("key" , "default" ), "default" )
927
928
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
+
928
944
929
945
@override_settings (
930
946
CACHES = caches_setting_for_tests (
You can’t perform that action at this time.
0 commit comments