Skip to content

Commit 13ddc42

Browse files
committed
Clean ups
1 parent b6096d4 commit 13ddc42

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

django_mongodb_backend/management/commands/createcachecollection.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@ def add_arguments(self, parser):
3232
'installed. Defaults to the "default" database.',
3333
)
3434

35-
# parser.add_argument(
36-
# "--dry-run",
37-
# action="store_true",
38-
# help="Does not create the table, just prints the SQL that would be run.",
39-
# )
40-
4135
def handle(self, *collection_names, **options):
4236
db = options["database"]
4337
self.verbosity = options["verbosity"]
44-
# dry_run = options["dry_run"]
4538
if collection_names:
4639
# Legacy behavior, collection_name specified as argument
4740
for collection_name in collection_names:

tests/cache_/tests.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from bson import SON
88
from django.conf import settings
9-
from django.core import management
109
from django.core.cache import DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches
1110
from django.core.cache.backends.base import InvalidCacheBackendError
1211
from django.http import (
@@ -16,7 +15,9 @@
1615
FetchFromCacheMiddleware,
1716
UpdateCacheMiddleware,
1817
)
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
2021

2122
from .models import Poll, expensive_calculation
2223

@@ -848,7 +849,9 @@ def test_custom_key_func(self):
848849

849850
@override_settings(
850851
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"},
852855
)
853856
def test_cache_write_unpicklable_object(self):
854857
fetch_middleware = FetchFromCacheMiddleware(empty_response)
@@ -948,7 +951,9 @@ def test_collection_has_indexes(self):
948951
# Spaces are used in the table name to ensure quoting/escaping is working
949952
LOCATION="test cache table",
950953
),
951-
INSTALLED_APPS=settings.INSTALLED_APPS + ["django_mongodb_backend"], # noqa: RUF005
954+
)
955+
@modify_settings(
956+
INSTALLED_APPS={"prepend": "django_mongodb_backend"},
952957
)
953958
class DBCacheTests(BaseCacheTests, TestCase):
954959
def setUp(self):
@@ -961,7 +966,13 @@ def drop_collection(self):
961966
cache.collection.drop()
962967

963968
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()
965976

966977

967978
@override_settings(USE_TZ=True)

0 commit comments

Comments
 (0)