1
1
#coding: utf-8
2
- from nose .plugins .skip import SkipTest
3
2
4
- from mongoengine .python_support import PY3
5
3
from mongoengine import connect
4
+ from mongoengine .connection import get_db
5
+ from mongoengine .python_support import PY3
6
6
7
7
try :
8
8
from django .test import TestCase
9
- from django .conf import settings
10
9
except Exception as err :
11
10
if PY3 :
12
11
from unittest import TestCase
13
- # Dummy value so no error
14
- class settings :
15
- MONGO_DATABASE_NAME = 'dummy'
16
12
else :
17
13
raise err
18
14
19
15
20
16
class MongoTestCase (TestCase ):
21
-
22
- def setUp (self ):
23
- if PY3 :
24
- raise SkipTest ('django does not have Python 3 support' )
25
-
26
17
"""
27
18
TestCase class that clear the collection between the tests
28
19
"""
29
20
30
21
@property
31
22
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' )
33
25
34
26
def __init__ (self , methodName = 'runtest' ):
35
- self .db = connect (self .db_name ).get_db ()
27
+ connect (self .db_name )
28
+ self .db = get_db ()
36
29
super (MongoTestCase , self ).__init__ (methodName )
37
30
38
31
def _post_teardown (self ):
@@ -41,3 +34,14 @@ def _post_teardown(self):
41
34
if collection == 'system.indexes' :
42
35
continue
43
36
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
0 commit comments