From 86e2797c577d007b1883164867eaca7548703ea9 Mon Sep 17 00:00:00 2001 From: vandersonmota Date: Wed, 9 Jun 2010 22:28:30 -0300 Subject: [PATCH] added a TestCase for tests that uses mongoDB --- mongoengine/django/tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 mongoengine/django/tests.py diff --git a/mongoengine/django/tests.py b/mongoengine/django/tests.py new file mode 100644 index 00000000..a8d7c7ff --- /dev/null +++ b/mongoengine/django/tests.py @@ -0,0 +1,21 @@ +#coding: utf-8 +from django.test import TestCase +from django.conf import settings + +from mongoengine import connect + +class MongoTestCase(TestCase): + """ + TestCase class that clear the collection between the tests + """ + db_name = 'test_%s' % settings.MONGO_DATABASE_NAME + def __init__(self, methodName='runtest'): + self.db = connect(self.db_name) + super(MongoTestCase, self).__init__(methodName) + + def _post_teardown(self): + super(MongoTestCase, self)._post_teardown() + for collection in self.db.collection_names(): + if collection == 'system.indexes': + continue + self.db.drop_collection(collection)