corrected connection test for PyMongo3+
This commit is contained in:
parent
1005c99e9c
commit
c41dd6495d
@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
|
from pymongo.errors import OperationFailure
|
||||||
|
|
||||||
sys.path[0:0] = [""]
|
sys.path[0:0] = [""]
|
||||||
|
|
||||||
@ -124,6 +125,7 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
def test_connect_uri_with_authsource(self):
|
def test_connect_uri_with_authsource(self):
|
||||||
"""Ensure that the connect() method works well with
|
"""Ensure that the connect() method works well with
|
||||||
the option `authSource` in URI.
|
the option `authSource` in URI.
|
||||||
|
This feature was introduced in MongoDB 2.4 and removed in 2.6
|
||||||
"""
|
"""
|
||||||
# Create users
|
# Create users
|
||||||
c = connect('mongoenginetest')
|
c = connect('mongoenginetest')
|
||||||
@ -131,6 +133,11 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
c.admin.add_user('username', 'password')
|
c.admin.add_user('username', 'password')
|
||||||
|
|
||||||
# Authentication fails without "authSource"
|
# Authentication fails without "authSource"
|
||||||
|
if IS_PYMONGO_3:
|
||||||
|
test_conn = connect('mongoenginetest', alias='test2',
|
||||||
|
host='mongodb://username:password@localhost/mongoenginetest')
|
||||||
|
self.assertRaises(OperationFailure, test_conn.server_info)
|
||||||
|
else:
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
ConnectionError, connect, 'mongoenginetest', alias='test1',
|
ConnectionError, connect, 'mongoenginetest', alias='test1',
|
||||||
host='mongodb://username:password@localhost/mongoenginetest'
|
host='mongodb://username:password@localhost/mongoenginetest'
|
||||||
@ -138,11 +145,13 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
self.assertRaises(ConnectionError, get_db, 'test1')
|
self.assertRaises(ConnectionError, get_db, 'test1')
|
||||||
|
|
||||||
# Authentication succeeds with "authSource"
|
# Authentication succeeds with "authSource"
|
||||||
connect(
|
test_conn2 = connect(
|
||||||
'mongoenginetest', alias='test2',
|
'mongoenginetest', alias='test2',
|
||||||
host=('mongodb://username:password@localhost/'
|
host=('mongodb://username:password@localhost/'
|
||||||
'mongoenginetest?authSource=admin')
|
'mongoenginetest?authSource=admin')
|
||||||
)
|
)
|
||||||
|
# This will fail starting from MongoDB 2.6+
|
||||||
|
# test_conn2.server_info()
|
||||||
db = get_db('test2')
|
db = get_db('test2')
|
||||||
self.assertTrue(isinstance(db, pymongo.database.Database))
|
self.assertTrue(isinstance(db, pymongo.database.Database))
|
||||||
self.assertEqual(db.name, 'mongoenginetest')
|
self.assertEqual(db.name, 'mongoenginetest')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user