'Ensure that the connect() method works well with `authSource`
option in the URI.'

def test_connect_uri_with_authsource(self):

    c = connect('mongoenginetest')
    c.admin.system.users.remove({})
    c.admin.add_user('username2', 'password')
    if IS_PYMONGO_3:
        test_conn = connect('mongoenginetest', alias='test1', host='mongodb://username2:password@localhost/mongoenginetest')
        self.assertRaises(OperationFailure, test_conn.server_info)
    else:
        self.assertRaises(MongoEngineConnectionError, connect, 'mongoenginetest', alias='test1', host='mongodb://username2:password@localhost/mongoenginetest')
        self.assertRaises(MongoEngineConnectionError, get_db, 'test1')
    authd_conn = connect('mongoenginetest', alias='test2', host='mongodb://username2:password@localhost/mongoenginetest?authSource=admin')
    db = get_db('test2')
    self.assertTrue(isinstance(db, pymongo.database.Database))
    self.assertEqual(db.name, 'mongoenginetest')
    authd_conn.admin.system.users.remove({})
