diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-04-12 12:14:29 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-04-12 12:14:29 +0200 |
commit | ae5d46af448fc33ef74eee99c5a3d686c8d26e72 (patch) | |
tree | 24395fb20457d7d53a0c349e6a7bcb3862cd33c1 /tests | |
parent | c77d97d950bcf6fab0061519922c4800e06ff711 (diff) | |
download | factory-boy-ae5d46af448fc33ef74eee99c5a3d686c8d26e72.tar factory-boy-ae5d46af448fc33ef74eee99c5a3d686c8d26e72.tar.gz |
Fix tests with latest pymongo/mongoengine.
mongoengine>=0.9.0 and pymongo>=2.1 require extra parameters:
- The server connection timeout was set too high
- We have to define a ``read_preference``.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_mongoengine.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py index 988c179..c0a019c 100644 --- a/tests/test_mongoengine.py +++ b/tests/test_mongoengine.py @@ -61,10 +61,20 @@ class MongoEngineTestCase(unittest.TestCase): db_name = os.environ.get('MONGO_DATABASE', 'factory_boy_test') db_host = os.environ.get('MONGO_HOST', 'localhost') db_port = int(os.environ.get('MONGO_PORT', '27017')) + MONGOD_TIMEOUT_MS = 100 @classmethod def setUpClass(cls): - cls.db = mongoengine.connect(cls.db_name, host=cls.db_host, port=cls.db_port) + from pymongo import read_preferences as mongo_rp + cls.db = mongoengine.connect( + db=cls.db_name, + host=cls.db_host, + port=cls.db_port, + # PyMongo>=2.1 requires an explicit read_preference. + read_preference=mongo_rp.ReadPreference.PRIMARY, + # PyMongo>=2.1 has a 20s timeout, use 100ms instead + serverselectiontimeoutms=cls.MONGOD_TIMEOUT_MS, + ) @classmethod def tearDownClass(cls): |