|
@@ -26,6 +26,11 @@ MONGODB_COLLECTION = 'collection1'
|
|
|
|
|
|
class test_MongoBackend(AppCase):
|
|
|
|
|
|
+ default_url = "mongodb://uuuu:pwpw@hostname.dom/database"
|
|
|
+ replica_set_url = "mongodb://uuuu:pwpw@hostname.dom,hostname.dom/database?replicaSet=rs"
|
|
|
+ sanitized_default_url = default_url.replace("pwpw", "**")
|
|
|
+ sanitized_replica_set_url = replica_set_url.replace("pwpw", "**")
|
|
|
+
|
|
|
def setup(self):
|
|
|
if pymongo is None:
|
|
|
raise SkipTest('pymongo is not installed.')
|
|
@@ -36,7 +41,7 @@ class test_MongoBackend(AppCase):
|
|
|
R['Binary'], module.Binary = module.Binary, Mock()
|
|
|
R['datetime'], datetime.datetime = datetime.datetime, Mock()
|
|
|
|
|
|
- self.backend = MongoBackend(app=self.app)
|
|
|
+ self.backend = MongoBackend(app=self.app, url=self.default_url)
|
|
|
|
|
|
def teardown(self):
|
|
|
MongoBackend.encode = self._reset['encode']
|
|
@@ -330,31 +335,16 @@ class test_MongoBackend(AppCase):
|
|
|
'auto_start_request': False
|
|
|
})
|
|
|
|
|
|
- @patch('celery.backends.mongodb.detect_environment')
|
|
|
- def test_prepare_client_options_for_ver_2_with_gevent(self, m_detect_env):
|
|
|
- m_detect_env.return_value = 'gevent'
|
|
|
- with patch('pymongo.version_tuple', new=(2, 6, 3)):
|
|
|
- options = self.backend._prepare_client_options()
|
|
|
- self.assertDictEqual(options, {
|
|
|
- 'max_pool_size': self.backend.max_pool_size,
|
|
|
- 'auto_start_request': False,
|
|
|
- 'use_greenlets': True
|
|
|
- })
|
|
|
+ def test_as_uri_include_password(self):
|
|
|
+ self.assertEqual(self.backend.as_uri(True), self.default_url)
|
|
|
|
|
|
- @patch('celery.backends.mongodb.detect_environment')
|
|
|
- def test_prepare_client_options_for_ver_3(self, m_detect_env):
|
|
|
- m_detect_env.return_value = 'default'
|
|
|
- with patch('pymongo.version_tuple', new=(3, 0, 3)):
|
|
|
- options = self.backend._prepare_client_options()
|
|
|
- self.assertDictEqual(options, {
|
|
|
- 'maxPoolSize': self.backend.max_pool_size
|
|
|
- })
|
|
|
+ def test_as_uri_exclude_password(self):
|
|
|
+ self.assertEqual(self.backend.as_uri(), self.sanitized_default_url)
|
|
|
|
|
|
- @patch('celery.backends.mongodb.detect_environment')
|
|
|
- def test_prepare_client_options_for_ver_3_with_gevent(self, m_detect_env):
|
|
|
- m_detect_env.return_value = 'gevent'
|
|
|
- with patch('pymongo.version_tuple', new=(3, 0, 3)):
|
|
|
- options = self.backend._prepare_client_options()
|
|
|
- self.assertDictEqual(options, {
|
|
|
- 'maxPoolSize': self.backend.max_pool_size
|
|
|
- })
|
|
|
+ def test_as_uri_include_password_replica_set(self):
|
|
|
+ backend = MongoBackend(app=self.app, url=self.replica_set_url)
|
|
|
+ self.assertEqual(backend.as_uri(True), self.replica_set_url)
|
|
|
+
|
|
|
+ def test_as_uri_exclude_password_replica_set(self):
|
|
|
+ backend = MongoBackend(app=self.app, url=self.replica_set_url)
|
|
|
+ self.assertEqual(backend.as_uri(), self.sanitized_replica_set_url)
|