##// END OF EJS Templates
Use username and password for MongoDB on ShiningPanda.
Thomas Kluyver -
Show More
@@ -1,52 +1,56 b''
1 """Tests for mongodb backend
1 """Tests for mongodb backend
2
2
3 Authors:
3 Authors:
4
4
5 * Min RK
5 * Min RK
6 """
6 """
7
7
8 #-------------------------------------------------------------------------------
8 #-------------------------------------------------------------------------------
9 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-------------------------------------------------------------------------------
13 #-------------------------------------------------------------------------------
14
14
15 #-------------------------------------------------------------------------------
15 #-------------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-------------------------------------------------------------------------------
17 #-------------------------------------------------------------------------------
18
18
19 import os
19 import os
20
20
21 from unittest import TestCase
21 from unittest import TestCase
22
22
23 from nose import SkipTest
23 from nose import SkipTest
24
24
25 from pymongo import Connection
25 from pymongo import Connection
26 from IPython.parallel.controller.mongodb import MongoDB
26 from IPython.parallel.controller.mongodb import MongoDB
27
27
28 from . import test_db
28 from . import test_db
29
29
30 conn_kwargs = {}
30 conn_kwargs = {}
31 if 'DB_IP' in os.environ:
31 if 'DB_IP' in os.environ:
32 conn_kwargs['host'] = os.environ['DB_IP']
32 conn_kwargs['host'] = os.environ['DB_IP']
33 if 'DBA_MONGODB_ADMIN_URI' in os.environ:
34 # On ShiningPanda, we need a username and password to connect. They are
35 # passed in a mongodb:// URI.
36 conn_kwargs['host'] = os.environ['DBA_MONGODB_ADMIN_URI']
33 if 'DB_PORT' in os.environ:
37 if 'DB_PORT' in os.environ:
34 conn_kwargs['port'] = int(os.environ['DB_PORT'])
38 conn_kwargs['port'] = int(os.environ['DB_PORT'])
35
39
36 try:
40 try:
37 c = Connection(**conn_kwargs)
41 c = Connection(**conn_kwargs)
38 except Exception:
42 except Exception:
39 c=None
43 c=None
40
44
41 class TestMongoBackend(test_db.TaskDBTest, TestCase):
45 class TestMongoBackend(test_db.TaskDBTest, TestCase):
42 """MongoDB backend tests"""
46 """MongoDB backend tests"""
43
47
44 def create_db(self):
48 def create_db(self):
45 try:
49 try:
46 return MongoDB(database='iptestdb', _connection=c)
50 return MongoDB(database='iptestdb', _connection=c)
47 except Exception:
51 except Exception:
48 raise SkipTest("Couldn't connect to mongodb")
52 raise SkipTest("Couldn't connect to mongodb")
49
53
50 def teardown(self):
54 def teardown(self):
51 if c is not None:
55 if c is not None:
52 c.drop_database('iptestdb')
56 c.drop_database('iptestdb')
General Comments 0
You need to be logged in to leave comments. Login now