From 3e54da03e26354e7b8c82df25b1677ee0da05313 Mon Sep 17 00:00:00 2001 From: Aleksey Porfirov Date: Sat, 5 Jul 2014 21:35:31 +0400 Subject: [PATCH] Fix MongoTestCase and add test for it --- mongoengine/django/tests.py | 26 +++++--------------------- tests/test_django.py | 3 +-- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/mongoengine/django/tests.py b/mongoengine/django/tests.py index 620e6ba6..d7fc3939 100644 --- a/mongoengine/django/tests.py +++ b/mongoengine/django/tests.py @@ -1,16 +1,9 @@ #coding: utf-8 +from unittest import TestCase + from mongoengine import connect 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): @@ -28,20 +21,11 @@ class MongoTestCase(TestCase): self.db = get_db() super(MongoTestCase, self).__init__(methodName) - def _post_teardown(self): - super(MongoTestCase, self)._post_teardown() + def dropCollections(self): for collection in self.db.collection_names(): if collection == 'system.indexes': continue self.db.drop_collection(collection) - # prevent standard db init - - def _databases_names(self, *args, **kwargs): - return [] - - def _fixture_setup(self): - pass - - def _fixture_teardown(self): - pass + def tearDown(self): + self.dropCollections() diff --git a/tests/test_django.py b/tests/test_django.py index de49e8ac..7badbd64 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -301,8 +301,7 @@ class MongoAuthTest(unittest.TestCase): class MongoTestCaseTest(MongoTestCase): def test_mongo_test_case(self): - # test __init__ and teardown in MongoTestCase - pass + self.db.dummy_collection.insert({'collection': 'will be dropped'}) if __name__ == '__main__':