Skip to content

Commit 5b4e11d

Browse files
author
Mark Unsworth
committed
added fixture teardown override to wipe out all collections. The django built-in fixture teardown tries to delete all records from the collections, however this breaks on the capped collections.
1 parent 292e74c commit 5b4e11d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

tests/mongodb/tests.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

44
from django.core.management import call_command
55
from django.contrib.sites.models import Site
6-
from django.db import connection, connections
6+
from django.db import connection
77
from django.db.utils import DatabaseError, IntegrityError
88
from django.db.models import Q
9-
109
from gridfs import GridOut
1110
from pymongo import ASCENDING, DESCENDING
12-
1311
from django_mongodb_engine.base import DatabaseWrapper
14-
1512
from models import *
1613
from utils import *
1714

@@ -57,7 +54,6 @@ def test_generic_field(self):
5754
def test_databasewrapper_api(self):
5855
from pymongo.mongo_client import MongoClient
5956
from pymongo.database import Database
60-
from pymongo.collection import Collection
6157
from random import shuffle
6258

6359
if settings.DEBUG:

tests/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
from django.test import TestCase
55
from django.utils.unittest import skip
66

7-
87
class TestCase(TestCase):
98

109
def setUp(self):
1110
super(TestCase, self).setUp()
1211
if getattr(settings, 'TEST_DEBUG', False):
1312
settings.DEBUG = True
1413

14+
15+
def _fixture_teardown(self):
16+
from django.db import connections
17+
for connection_name in connections:
18+
19+
db_wrapper = connections[connection_name]
20+
21+
for collection_name in db_wrapper.database.collection_names(include_system_collections=False):
22+
db_wrapper.get_collection(collection_name).drop()
23+
24+
25+
26+
1527
def assertEqualLists(self, a, b):
1628
self.assertEqual(list(a), list(b))
1729

0 commit comments

Comments
 (0)