6
6
7
7
from bson import SON
8
8
from django .conf import settings
9
- from django .core import management
10
9
from django .core .cache import DEFAULT_CACHE_ALIAS , CacheKeyWarning , cache , caches
11
10
from django .core .cache .backends .base import InvalidCacheBackendError
12
11
from django .http import (
16
15
FetchFromCacheMiddleware ,
17
16
UpdateCacheMiddleware ,
18
17
)
19
- from django .test import RequestFactory , TestCase , override_settings
18
+ from django .test import RequestFactory , TestCase , modify_settings , override_settings
19
+
20
+ from django_mongodb_backend .cache import MongoDBCache
20
21
21
22
from .models import Poll , expensive_calculation
22
23
@@ -848,7 +849,9 @@ def test_custom_key_func(self):
848
849
849
850
@override_settings (
850
851
CACHE_MIDDLEWARE_ALIAS = DEFAULT_CACHE_ALIAS ,
851
- INSTALLED_APPS = settings .INSTALLED_APPS + ["django_mongodb_backend" ], # noqa: RUF005
852
+ )
853
+ @modify_settings (
854
+ INSTALLED_APPS = {"prepend" : "django_mongodb_backend" },
852
855
)
853
856
def test_cache_write_unpicklable_object (self ):
854
857
fetch_middleware = FetchFromCacheMiddleware (empty_response )
@@ -948,7 +951,9 @@ def test_collection_has_indexes(self):
948
951
# Spaces are used in the table name to ensure quoting/escaping is working
949
952
LOCATION = "test cache table" ,
950
953
),
951
- INSTALLED_APPS = settings .INSTALLED_APPS + ["django_mongodb_backend" ], # noqa: RUF005
954
+ )
955
+ @modify_settings (
956
+ INSTALLED_APPS = {"prepend" : "django_mongodb_backend" },
952
957
)
953
958
class DBCacheTests (BaseCacheTests , TestCase ):
954
959
def setUp (self ):
@@ -961,7 +966,13 @@ def drop_collection(self):
961
966
cache .collection .drop ()
962
967
963
968
def create_cache_collection (self ):
964
- management .call_command ("createcachecollection" , verbosity = 0 )
969
+ for cache_alias in settings .CACHES :
970
+ cache = caches [cache_alias ]
971
+ connection = cache ._db
972
+ if cache ._collection_name in connection .introspection .table_names ():
973
+ return
974
+ cache = MongoDBCache (cache ._collection_name , {})
975
+ cache .create_indexes ()
965
976
966
977
967
978
@override_settings (USE_TZ = True )
0 commit comments