Fix MongoTestCase and add test for it
This commit is contained in:
parent
c4b3196917
commit
3e54da03e2
@ -1,16 +1,9 @@
|
|||||||
#coding: utf-8
|
#coding: utf-8
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
from mongoengine import connect
|
from mongoengine import connect
|
||||||
from mongoengine.connection import get_db
|
from mongoengine.connection import get_db
|
||||||
from mongoengine.python_support import PY3
|
|
||||||
|
|
||||||
try:
|
|
||||||
from django.test import TestCase
|
|
||||||
except Exception as err:
|
|
||||||
if PY3:
|
|
||||||
from unittest import TestCase
|
|
||||||
else:
|
|
||||||
raise err
|
|
||||||
|
|
||||||
|
|
||||||
class MongoTestCase(TestCase):
|
class MongoTestCase(TestCase):
|
||||||
@ -28,20 +21,11 @@ class MongoTestCase(TestCase):
|
|||||||
self.db = get_db()
|
self.db = get_db()
|
||||||
super(MongoTestCase, self).__init__(methodName)
|
super(MongoTestCase, self).__init__(methodName)
|
||||||
|
|
||||||
def _post_teardown(self):
|
def dropCollections(self):
|
||||||
super(MongoTestCase, self)._post_teardown()
|
|
||||||
for collection in self.db.collection_names():
|
for collection in self.db.collection_names():
|
||||||
if collection == 'system.indexes':
|
if collection == 'system.indexes':
|
||||||
continue
|
continue
|
||||||
self.db.drop_collection(collection)
|
self.db.drop_collection(collection)
|
||||||
|
|
||||||
# prevent standard db init
|
def tearDown(self):
|
||||||
|
self.dropCollections()
|
||||||
def _databases_names(self, *args, **kwargs):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def _fixture_setup(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _fixture_teardown(self):
|
|
||||||
pass
|
|
||||||
|
@ -301,8 +301,7 @@ class MongoAuthTest(unittest.TestCase):
|
|||||||
|
|
||||||
class MongoTestCaseTest(MongoTestCase):
|
class MongoTestCaseTest(MongoTestCase):
|
||||||
def test_mongo_test_case(self):
|
def test_mongo_test_case(self):
|
||||||
# test __init__ and teardown in MongoTestCase
|
self.db.dummy_collection.insert({'collection': 'will be dropped'})
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user