Skip to content

Commit

Permalink
make DatabaseCreation._destroy_test_db() clear the test database
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed May 3, 2024
1 parent de41b36 commit 66f08ec
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions django_mongodb/creation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.db.backends.base.creation import BaseDatabaseCreation


Expand All @@ -7,6 +8,11 @@ def _execute_create_test_db(self, cursor, parameters, keepdb=False):
self._destroy_test_db(parameters["dbname"], verbosity=0)

def _destroy_test_db(self, test_database_name, verbosity):
# At this point, settings still points to the non-test database. For
# MongoDB, it must use the test database.
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
self.connection.settings_dict["NAME"] = test_database_name

for collection in self.connection.introspection.table_names():
if not collection.startswith("system."):
self.connection.database.drop_collection(collection)

0 comments on commit 66f08ec

Please sign in to comment.