1414
1515"""Test the pymongo common module."""
1616
17+ import os
18+ import socket
1719import unittest
1820import warnings
1921
@@ -26,7 +28,11 @@ class TestCommon(unittest.TestCase):
2628 def test_baseobject (self ):
2729
2830 warnings .simplefilter ("ignore" )
29- c = Connection ()
31+
32+ host = os .environ .get ("DB_IP" , socket .gethostname ())
33+ port = int (os .environ .get ("DB_PORT" , 27017 ))
34+ pair = '%s:%d' % (host , port )
35+ c = Connection (pair )
3036 self .assertFalse (c .slave_okay )
3137 self .assertFalse (c .safe )
3238 self .assertEqual ({}, c .get_lasterror_options ())
@@ -43,7 +49,7 @@ def test_baseobject(self):
4349 cursor = coll .find (slave_okay = True )
4450 self .assertTrue (cursor ._Cursor__slave_okay )
4551
46- c = Connection (slaveok = True , w = 'majority' ,
52+ c = Connection (pair , slaveok = True , w = 'majority' ,
4753 wtimeout = 300 , fsync = True , j = True )
4854 self .assertTrue (c .slave_okay )
4955 self .assertTrue (c .safe )
@@ -62,14 +68,14 @@ def test_baseobject(self):
6268 cursor = coll .find (slave_okay = False )
6369 self .assertFalse (cursor ._Cursor__slave_okay )
6470
65- c = Connection ('mongodb://localhost:27017 /?'
66- 'w=2;wtimeoutMS=300;fsync=true;journal=true' )
71+ c = Connection ('mongodb://%s /?'
72+ 'w=2;wtimeoutMS=300;fsync=true;journal=true' % pair )
6773 self .assertTrue (c .safe )
6874 d = {'w' : 2 , 'wtimeout' : 300 , 'fsync' : True , 'j' : True }
6975 self .assertEqual (d , c .get_lasterror_options ())
7076
71- c = Connection ('mongodb://localhost:27017 /?'
72- 'slaveok=true;w=1;wtimeout=300;fsync=true;j=true' )
77+ c = Connection ('mongodb://%s /?'
78+ 'slaveok=true;w=1;wtimeout=300;fsync=true;j=true' % pair )
7379 self .assertTrue (c .slave_okay )
7480 self .assertTrue (c .safe )
7581 d = {'w' : 1 , 'wtimeout' : 300 , 'fsync' : True , 'j' : True }
0 commit comments