Skip to content

Commit 9640212

Browse files
committed
Fix failing tests and add some default connection parameters.
1 parent 03315c7 commit 9640212

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

django_mongodb_engine/base.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def pop(name, default=None):
213213

214214
db_name = pop('NAME')
215215
host = pop('HOST')
216-
port = int(pop('PORT', 27017))
216+
port = pop('PORT', 27017)
217217
user = pop('USER')
218218
password = pop('PASSWORD')
219219
options = pop('OPTIONS', {})
@@ -238,15 +238,27 @@ def pop(name, default=None):
238238
if read_preference:
239239
options['read_preference'] = ReadPreference.SECONDARY
240240
warnings.warn("slave_okay has been deprecated. "
241-
"Please use read_preference instead.")
241+
"Please use read_preference instead.")
242242

243243
if replicaset:
244-
connection = MongoReplicaSetClient
244+
connection_class = MongoReplicaSetClient
245245
else:
246-
connection = MongoClient
246+
connection_class = MongoClient
247+
248+
conn_options = dict(
249+
host=host,
250+
port=int(port),
251+
max_pool_size=None,
252+
document_class=dict,
253+
tz_aware=False,
254+
_connect=True,
255+
auto_start_request=True,
256+
safe=False
257+
)
258+
conn_options.update(options)
247259

248260
try:
249-
self.connection = connection(host=host, port=port, **options)
261+
self.connection = connection_class(**conn_options)
250262
self.database = self.connection[db_name]
251263
except TypeError:
252264
exc_info = sys.exc_info()

tests/mongodb/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_generic_field(self):
5555
self.assertEqual(RawModel.objects.get(id=id).raw, obj)
5656

5757
def test_databasewrapper_api(self):
58-
from pymongo.connection import Connection
58+
from pymongo.mongo_client import MongoClient
5959
from pymongo.database import Database
6060
from pymongo.collection import Collection
6161
from random import shuffle
@@ -70,7 +70,7 @@ def test_databasewrapper_api(self):
7070
lambda: self.assertIsInstance(wrapper.get_collection('foo'),
7171
Collection),
7272
lambda: self.assertIsInstance(wrapper.database, Database),
73-
lambda: self.assertIsInstance(wrapper.connection, Connection),
73+
lambda: self.assertIsInstance(wrapper.connection, MongoClient),
7474
]
7575
shuffle(calls)
7676
for call in calls:

0 commit comments

Comments
 (0)