From 3c7bf500894f1475fedecc2627f8533b583dd1b9 Mon Sep 17 00:00:00 2001 From: Robert Kajic Date: Tue, 28 Feb 2012 23:18:22 +0100 Subject: [PATCH 1/2] Make uri style connections use parameters not specified in the uri, as well as other keyword arguments --- mongoengine/connection.py | 14 ++++++-------- tests/connection.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 70eac1e7..815ffa01 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -45,14 +45,12 @@ def register_connection(alias, name, host='localhost', port=27017, if uri_dict.get('database') is None: raise ConnectionError("If using URI style connection include "\ "database name in string") - uri_dict['name'] = uri_dict.get('database') - _connection_settings[alias] = { - 'host': host, - 'name': uri_dict.get('database'), - 'username': uri_dict.get('username'), - 'password': uri_dict.get('password') - } - return + node = uri_dict['nodelist'][0] + host = node[0] + port = node[1] + name = uri_dict.get('database') + username = uri_dict.get('username') or username + password = uri_dict.get('password') or password _connection_settings[alias] = { 'name': name, diff --git a/tests/connection.py b/tests/connection.py index ce20a54a..9aad142f 100644 --- a/tests/connection.py +++ b/tests/connection.py @@ -41,7 +41,7 @@ class ConnectionTest(unittest.TestCase): c.admin.authenticate("admin", "password") c.mongoenginetest.add_user("username", "password") - self.assertRaises(ConnectionError, connect, "testdb_uri_bad", host='mongodb://test:password@localhost/mongoenginetest') + self.assertRaises(ConnectionError, connect, "testdb_uri_bad", host='mongodb://test:password@localhost') connect("testdb_uri", host='mongodb://username:password@localhost/mongoenginetest') From c61de6540a12c1365cff50b32c3c5db0be2a3580 Mon Sep 17 00:00:00 2001 From: Robert Kajic Date: Fri, 2 Mar 2012 11:37:45 +0100 Subject: [PATCH 2/2] Don't ignore kwargs for uri style connections --- mongoengine/connection.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 815ffa01..dbde9e67 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -45,12 +45,14 @@ def register_connection(alias, name, host='localhost', port=27017, if uri_dict.get('database') is None: raise ConnectionError("If using URI style connection include "\ "database name in string") - node = uri_dict['nodelist'][0] - host = node[0] - port = node[1] - name = uri_dict.get('database') - username = uri_dict.get('username') or username - password = uri_dict.get('password') or password + _connection_settings[alias] = { + 'host': host, + 'name': uri_dict.get('database'), + 'username': uri_dict.get('username'), + 'password': uri_dict.get('password') + } + _connection_settings[alias].update(kwargs) + return _connection_settings[alias] = { 'name': name, @@ -62,7 +64,6 @@ def register_connection(alias, name, host='localhost', port=27017, 'password': password, 'read_preference': read_preference } - _connection_settings[alias].update(kwargs)