fix authSource test

This commit is contained in:
Stefan Wojcik 2017-02-26 02:21:25 -05:00
parent 4acd7a5b75
commit a94ec06275

View File

@ -225,9 +225,8 @@ class ConnectionTest(unittest.TestCase):
self.assertRaises(OperationFailure, get_db) self.assertRaises(OperationFailure, get_db)
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 `authSource`
the option `authSource` in URI. option in the URI.
This feature was introduced in MongoDB 2.4 and removed in 2.6
""" """
# Create users # Create users
c = connect('mongoenginetest') c = connect('mongoenginetest')
@ -236,30 +235,31 @@ class ConnectionTest(unittest.TestCase):
# Authentication fails without "authSource" # Authentication fails without "authSource"
if IS_PYMONGO_3: if IS_PYMONGO_3:
test_conn = connect('mongoenginetest', alias='test1', test_conn = connect(
host='mongodb://username2:password@localhost/mongoenginetest') 'mongoenginetest', alias='test1',
host='mongodb://username2:password@localhost/mongoenginetest'
)
self.assertRaises(OperationFailure, test_conn.server_info) self.assertRaises(OperationFailure, test_conn.server_info)
else: else:
self.assertRaises( self.assertRaises(
MongoEngineConnectionError, connect, 'mongoenginetest', MongoEngineConnectionError,
alias='test1', connect, 'mongoenginetest', alias='test1',
host='mongodb://username2:password@localhost/mongoenginetest' host='mongodb://username2:password@localhost/mongoenginetest'
) )
self.assertRaises(MongoEngineConnectionError, get_db, 'test1') self.assertRaises(MongoEngineConnectionError, get_db, 'test1')
# Authentication succeeds with "authSource" # Authentication succeeds with "authSource"
connect( authd_conn = connect(
'mongoenginetest', alias='test2', 'mongoenginetest', alias='test2',
host=('mongodb://username2:password@localhost/' host=('mongodb://username2:password@localhost/'
'mongoenginetest?authSource=admin') 'mongoenginetest?authSource=admin')
) )
# This will fail starting from MongoDB 2.6+
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')
# Clear all users # Clear all users
c.admin.system.users.remove({}) authd_conn.admin.system.users.remove({})
def test_register_connection(self): def test_register_connection(self):
"""Ensure that connections with different aliases may be registered. """Ensure that connections with different aliases may be registered.