Skip to content

Commit 00c376f

Browse files
A. Jesse Jiryu Davisbehackett
authored andcommitted
Respect the DB_PORT environment variable in all unittests
1 parent 88f49c6 commit 00c376f

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

test/test_common.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Test the pymongo common module."""
1616

17+
import os
18+
import socket
1719
import unittest
1820
import 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}

test/test_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ def test_ipv6(self):
419419
raise SkipTest()
420420

421421
# Try a few simple things
422-
connection = Connection("mongodb://[::1]:27017")
423-
connection = Connection("mongodb://[::1]:27017/?slaveOk=true")
424-
connection = Connection("[::1]:27017,localhost:27017")
425-
connection = Connection("localhost:27017,[::1]:27017")
422+
connection = Connection("mongodb://[::1]:%s" % self.port)
423+
connection = Connection("mongodb://[::1]:%s/?slaveOk=true" % self.port)
424+
connection = Connection("[::1]:%s,localhost:%s" % (self.port, self.port))
425+
connection = Connection("localhost:%s,[::1]:%s" % (self.port, self.port))
426426
connection.pymongo_test.test.save({"dummy": u"object"})
427427
connection.pymongo_test_bernie.test.save({"dummy": u"object"})
428428

test/test_replica_set_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from test import version
4040

4141
host = os.environ.get("DB_IP", socket.gethostname())
42-
port = os.environ.get("DB_PORT", 27017)
42+
port = int(os.environ.get("DB_PORT", 27017))
4343
pair = '%s:%d' % (host, port)
4444

4545
class TestConnectionReplicaSetBase(unittest.TestCase):

0 commit comments

Comments
 (0)