Compare commits
4 Commits
master
...
test-conne
Author | SHA1 | Date | |
---|---|---|---|
|
4e8bb14131 | ||
|
9cc4fad614 | ||
|
2a486ee537 | ||
|
2579ed754f |
@ -51,7 +51,9 @@ def register_connection(alias, name=None, host=None, port=None,
|
|||||||
MONGODB-CR (MongoDB Challenge Response protocol) for older servers.
|
MONGODB-CR (MongoDB Challenge Response protocol) for older servers.
|
||||||
:param is_mock: explicitly use mongomock for this connection
|
:param is_mock: explicitly use mongomock for this connection
|
||||||
(can also be done by using `mongomock://` as db host prefix)
|
(can also be done by using `mongomock://` as db host prefix)
|
||||||
:param kwargs: allow ad-hoc parameters to be passed into the pymongo driver
|
:param kwargs: ad-hoc parameters to be passed into the pymongo driver,
|
||||||
|
for example maxpoolsize, tz_aware, etc. See the documentation
|
||||||
|
for pymongo's `MongoClient` for a full list.
|
||||||
|
|
||||||
.. versionchanged:: 0.10.6 - added mongomock support
|
.. versionchanged:: 0.10.6 - added mongomock support
|
||||||
"""
|
"""
|
||||||
@ -241,9 +243,12 @@ def connect(db=None, alias=DEFAULT_CONNECTION_NAME, **kwargs):
|
|||||||
running on the default port on localhost. If authentication is needed,
|
running on the default port on localhost. If authentication is needed,
|
||||||
provide username and password arguments as well.
|
provide username and password arguments as well.
|
||||||
|
|
||||||
Multiple databases are supported by using aliases. Provide a separate
|
Multiple databases are supported by using aliases. Provide a separate
|
||||||
`alias` to connect to a different instance of :program:`mongod`.
|
`alias` to connect to a different instance of :program:`mongod`.
|
||||||
|
|
||||||
|
See the docstring for `register_connection` for more details about all
|
||||||
|
supported kwargs.
|
||||||
|
|
||||||
.. versionchanged:: 0.6 - added multiple database support.
|
.. versionchanged:: 0.6 - added multiple database support.
|
||||||
"""
|
"""
|
||||||
if alias not in _connections:
|
if alias not in _connections:
|
||||||
|
@ -285,8 +285,7 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient))
|
self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient))
|
||||||
|
|
||||||
def test_connection_kwargs(self):
|
def test_connection_kwargs(self):
|
||||||
"""Ensure that connection kwargs get passed to pymongo.
|
"""Ensure that connection kwargs get passed to pymongo."""
|
||||||
"""
|
|
||||||
connect('mongoenginetest', alias='t1', tz_aware=True)
|
connect('mongoenginetest', alias='t1', tz_aware=True)
|
||||||
conn = get_connection('t1')
|
conn = get_connection('t1')
|
||||||
|
|
||||||
@ -296,6 +295,32 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
conn = get_connection('t2')
|
conn = get_connection('t2')
|
||||||
self.assertFalse(get_tz_awareness(conn))
|
self.assertFalse(get_tz_awareness(conn))
|
||||||
|
|
||||||
|
def test_connection_pool_via_kwarg(self):
|
||||||
|
"""Ensure we can specify a max connection pool size using
|
||||||
|
a connection kwarg.
|
||||||
|
"""
|
||||||
|
# Use "max_pool_size" or "maxpoolsize" depending on PyMongo version
|
||||||
|
# (former was changed to the latter as described in
|
||||||
|
# https://jira.mongodb.org/browse/PYTHON-854).
|
||||||
|
# TODO remove once PyMongo < 3.0 support is dropped
|
||||||
|
if pymongo.version_tuple[0] >= 3:
|
||||||
|
pool_size_kwargs = {'maxpoolsize': 100}
|
||||||
|
else:
|
||||||
|
pool_size_kwargs = {'max_pool_size': 100}
|
||||||
|
|
||||||
|
conn = connect('mongoenginetest', alias='max_pool_size_via_kwarg', **pool_size_kwargs)
|
||||||
|
self.assertEqual(conn.max_pool_size, 100)
|
||||||
|
|
||||||
|
def test_connection_pool_via_uri(self):
|
||||||
|
"""Ensure we can specify a max connection pool size using
|
||||||
|
an option in a connection URI.
|
||||||
|
"""
|
||||||
|
if pymongo.version_tuple[0] == 2 and pymongo.version_tuple[1] < 9:
|
||||||
|
raise SkipTest('maxpoolsize as a URI option is only supported in PyMongo v2.9+')
|
||||||
|
|
||||||
|
conn = connect(host='mongodb://localhost/test?maxpoolsize=100', alias='max_pool_size_via_uri')
|
||||||
|
self.assertEqual(conn.max_pool_size, 100)
|
||||||
|
|
||||||
def test_write_concern(self):
|
def test_write_concern(self):
|
||||||
"""Ensure write concern can be specified in connect() via
|
"""Ensure write concern can be specified in connect() via
|
||||||
a kwarg or as part of the connection URI.
|
a kwarg or as part of the connection URI.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user