Skip to content

Commit c4b3196

Browse files
committed
Fix MongoTestCase and add test for it
1 parent 0d81e79 commit c4b3196

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

mongoengine/django/tests.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
#coding: utf-8
2-
from nose.plugins.skip import SkipTest
32

4-
from mongoengine.python_support import PY3
53
from mongoengine import connect
4+
from mongoengine.connection import get_db
5+
from mongoengine.python_support import PY3
66

77
try:
88
from django.test import TestCase
9-
from django.conf import settings
109
except Exception as err:
1110
if PY3:
1211
from unittest import TestCase
13-
# Dummy value so no error
14-
class settings:
15-
MONGO_DATABASE_NAME = 'dummy'
1612
else:
1713
raise err
1814

1915

2016
class MongoTestCase(TestCase):
21-
22-
def setUp(self):
23-
if PY3:
24-
raise SkipTest('django does not have Python 3 support')
25-
2617
"""
2718
TestCase class that clear the collection between the tests
2819
"""
2920

3021
@property
3122
def db_name(self):
32-
return 'test_%s' % settings.MONGO_DATABASE_NAME
23+
from django.conf import settings
24+
return 'test_%s' % getattr(settings, 'MONGO_DATABASE_NAME', 'dummy')
3325

3426
def __init__(self, methodName='runtest'):
35-
self.db = connect(self.db_name).get_db()
27+
connect(self.db_name)
28+
self.db = get_db()
3629
super(MongoTestCase, self).__init__(methodName)
3730

3831
def _post_teardown(self):
@@ -41,3 +34,14 @@ def _post_teardown(self):
4134
if collection == 'system.indexes':
4235
continue
4336
self.db.drop_collection(collection)
37+
38+
# prevent standard db init
39+
40+
def _databases_names(self, *args, **kwargs):
41+
return []
42+
43+
def _fixture_setup(self):
44+
pass
45+
46+
def _fixture_teardown(self):
47+
pass

tests/test_django.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
sys.path[0:0] = [""]
33
import unittest
44
from nose.plugins.skip import SkipTest
5-
from mongoengine import *
6-
75

6+
from mongoengine import *
87
from mongoengine.django.shortcuts import get_document_or_404
98

109
import django
@@ -37,6 +36,7 @@
3736
DJ15 = False
3837
from django.contrib.sessions.tests import SessionTestsMixin
3938
from mongoengine.django.sessions import SessionStore, MongoSession
39+
from mongoengine.django.tests import MongoTestCase
4040
from datetime import tzinfo, timedelta
4141
ZERO = timedelta(0)
4242

@@ -298,5 +298,12 @@ def test_authenticate(self):
298298
db_user = User.objects.get(username='user')
299299
self.assertEqual(user.id, db_user.id)
300300

301+
302+
class MongoTestCaseTest(MongoTestCase):
303+
def test_mongo_test_case(self):
304+
# test __init__ and teardown in MongoTestCase
305+
pass
306+
307+
301308
if __name__ == '__main__':
302309
unittest.main()

0 commit comments

Comments
 (0)