remove dead code (related to pymongo2) + minor cleaning
This commit is contained in:
parent
ee85af34d8
commit
ac64ade10f
@ -816,11 +816,9 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
index_spec = index_spec.copy()
|
index_spec = index_spec.copy()
|
||||||
fields = index_spec.pop('fields')
|
fields = index_spec.pop('fields')
|
||||||
drop_dups = kwargs.get('drop_dups', False)
|
drop_dups = kwargs.get('drop_dups', False)
|
||||||
if IS_PYMONGO_3 and drop_dups:
|
if drop_dups:
|
||||||
msg = 'drop_dups is deprecated and is removed when using PyMongo 3+.'
|
msg = 'drop_dups is deprecated and is removed when using PyMongo 3+.'
|
||||||
warnings.warn(msg, DeprecationWarning)
|
warnings.warn(msg, DeprecationWarning)
|
||||||
elif not IS_PYMONGO_3:
|
|
||||||
index_spec['drop_dups'] = drop_dups
|
|
||||||
index_spec['background'] = background
|
index_spec['background'] = background
|
||||||
index_spec.update(kwargs)
|
index_spec.update(kwargs)
|
||||||
|
|
||||||
@ -842,11 +840,9 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
:param drop_dups: Was removed/ignored with MongoDB >2.7.5. The value
|
:param drop_dups: Was removed/ignored with MongoDB >2.7.5. The value
|
||||||
will be removed if PyMongo3+ is used
|
will be removed if PyMongo3+ is used
|
||||||
"""
|
"""
|
||||||
if IS_PYMONGO_3 and drop_dups:
|
if drop_dups:
|
||||||
msg = 'drop_dups is deprecated and is removed when using PyMongo 3+.'
|
msg = 'drop_dups is deprecated and is removed when using PyMongo 3+.'
|
||||||
warnings.warn(msg, DeprecationWarning)
|
warnings.warn(msg, DeprecationWarning)
|
||||||
elif not IS_PYMONGO_3:
|
|
||||||
kwargs.update({'drop_dups': drop_dups})
|
|
||||||
return cls.create_index(key_or_list, background=background, **kwargs)
|
return cls.create_index(key_or_list, background=background, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -626,7 +626,7 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
queryset = self.clone()
|
queryset = self.clone()
|
||||||
query = queryset._query
|
query = queryset._query
|
||||||
if not IS_PYMONGO_3 or not remove:
|
if not remove:
|
||||||
update = transform.update(queryset._document, **update)
|
update = transform.update(queryset._document, **update)
|
||||||
sort = queryset._ordering
|
sort = queryset._ordering
|
||||||
|
|
||||||
@ -1090,7 +1090,7 @@ class BaseQuerySet(object):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def timeout(self, enabled):
|
def timeout(self, enabled):
|
||||||
"""Enable or disable the default mongod timeout when querying.
|
"""Enable or disable the default mongod timeout when querying. (no_cursor_timeout option)
|
||||||
|
|
||||||
:param enabled: whether or not the timeout is used
|
:param enabled: whether or not the timeout is used
|
||||||
|
|
||||||
@ -1531,26 +1531,16 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _cursor_args(self):
|
def _cursor_args(self):
|
||||||
if not IS_PYMONGO_3:
|
fields_name = 'projection'
|
||||||
fields_name = 'fields'
|
# snapshot is not handled at all by PyMongo 3+
|
||||||
cursor_args = {
|
# TODO: evaluate similar possibilities using modifiers
|
||||||
'timeout': self._timeout,
|
if self._snapshot:
|
||||||
'snapshot': self._snapshot
|
msg = 'The snapshot option is not anymore available with PyMongo 3+'
|
||||||
}
|
warnings.warn(msg, DeprecationWarning)
|
||||||
if self._read_preference is not None:
|
cursor_args = {
|
||||||
cursor_args['read_preference'] = self._read_preference
|
'no_cursor_timeout': not self._timeout
|
||||||
else:
|
}
|
||||||
cursor_args['slave_okay'] = self._slave_okay
|
|
||||||
else:
|
|
||||||
fields_name = 'projection'
|
|
||||||
# snapshot is not handled at all by PyMongo 3+
|
|
||||||
# TODO: evaluate similar possibilities using modifiers
|
|
||||||
if self._snapshot:
|
|
||||||
msg = 'The snapshot option is not anymore available with PyMongo 3+'
|
|
||||||
warnings.warn(msg, DeprecationWarning)
|
|
||||||
cursor_args = {
|
|
||||||
'no_cursor_timeout': not self._timeout
|
|
||||||
}
|
|
||||||
if self._loaded_fields:
|
if self._loaded_fields:
|
||||||
cursor_args[fields_name] = self._loaded_fields.as_dict()
|
cursor_args[fields_name] = self._loaded_fields.as_dict()
|
||||||
|
|
||||||
|
@ -3415,10 +3415,7 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(query.count(), 3)
|
self.assertEqual(query.count(), 3)
|
||||||
self.assertEqual(query._query, {'$text': {'$search': 'brasil'}})
|
self.assertEqual(query._query, {'$text': {'$search': 'brasil'}})
|
||||||
cursor_args = query._cursor_args
|
cursor_args = query._cursor_args
|
||||||
if not IS_PYMONGO_3:
|
cursor_args_fields = cursor_args['projection']
|
||||||
cursor_args_fields = cursor_args['fields']
|
|
||||||
else:
|
|
||||||
cursor_args_fields = cursor_args['projection']
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cursor_args_fields, {'_text_score': {'$meta': 'textScore'}})
|
cursor_args_fields, {'_text_score': {'$meta': 'textScore'}})
|
||||||
|
|
||||||
@ -4511,11 +4508,7 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
bars = list(Bar.objects(read_preference=ReadPreference.PRIMARY))
|
bars = list(Bar.objects(read_preference=ReadPreference.PRIMARY))
|
||||||
self.assertEqual([], bars)
|
self.assertEqual([], bars)
|
||||||
|
|
||||||
if not IS_PYMONGO_3:
|
self.assertRaises(TypeError, Bar.objects, read_preference='Primary')
|
||||||
error_class = ConfigurationError
|
|
||||||
else:
|
|
||||||
error_class = TypeError
|
|
||||||
self.assertRaises(error_class, Bar.objects, read_preference='Primary')
|
|
||||||
|
|
||||||
# read_preference as a kwarg
|
# read_preference as a kwarg
|
||||||
bars = Bar.objects(read_preference=ReadPreference.SECONDARY_PREFERRED)
|
bars = Bar.objects(read_preference=ReadPreference.SECONDARY_PREFERRED)
|
||||||
|
@ -23,10 +23,7 @@ from mongoengine.connection import (MongoEngineConnectionError, get_db,
|
|||||||
|
|
||||||
|
|
||||||
def get_tz_awareness(connection):
|
def get_tz_awareness(connection):
|
||||||
if not IS_PYMONGO_3:
|
return connection.codec_options.tz_aware
|
||||||
return connection.tz_aware
|
|
||||||
else:
|
|
||||||
return connection.codec_options.tz_aware
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionTest(unittest.TestCase):
|
class ConnectionTest(unittest.TestCase):
|
||||||
@ -425,12 +422,6 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
c.admin.authenticate("admin", "password")
|
c.admin.authenticate("admin", "password")
|
||||||
c.admin.command("createUser", "username", pwd="password", roles=["dbOwner"])
|
c.admin.command("createUser", "username", pwd="password", roles=["dbOwner"])
|
||||||
|
|
||||||
if not IS_PYMONGO_3:
|
|
||||||
self.assertRaises(
|
|
||||||
MongoEngineConnectionError, connect, 'testdb_uri_bad',
|
|
||||||
host='mongodb://test:password@localhost'
|
|
||||||
)
|
|
||||||
|
|
||||||
connect("testdb_uri", host='mongodb://username:password@localhost/mongoenginetest')
|
connect("testdb_uri", host='mongodb://username:password@localhost/mongoenginetest')
|
||||||
|
|
||||||
conn = get_connection()
|
conn = get_connection()
|
||||||
@ -641,17 +632,14 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
self.assertEqual(len(mongo_connections.items()), 2)
|
self.assertEqual(len(mongo_connections.items()), 2)
|
||||||
self.assertIn('t1', mongo_connections.keys())
|
self.assertIn('t1', mongo_connections.keys())
|
||||||
self.assertIn('t2', mongo_connections.keys())
|
self.assertIn('t2', mongo_connections.keys())
|
||||||
if not IS_PYMONGO_3:
|
|
||||||
self.assertEqual(mongo_connections['t1'].host, 'localhost')
|
# Handle PyMongo 3+ Async Connection
|
||||||
self.assertEqual(mongo_connections['t2'].host, '127.0.0.1')
|
# Ensure we are connected, throws ServerSelectionTimeoutError otherwise.
|
||||||
else:
|
# Purposely not catching exception to fail test if thrown.
|
||||||
# Handle PyMongo 3+ Async Connection
|
mongo_connections['t1'].server_info()
|
||||||
# Ensure we are connected, throws ServerSelectionTimeoutError otherwise.
|
mongo_connections['t2'].server_info()
|
||||||
# Purposely not catching exception to fail test if thrown.
|
self.assertEqual(mongo_connections['t1'].address[0], 'localhost')
|
||||||
mongo_connections['t1'].server_info()
|
self.assertEqual(mongo_connections['t2'].address[0], '127.0.0.1')
|
||||||
mongo_connections['t2'].server_info()
|
|
||||||
self.assertEqual(mongo_connections['t1'].address[0], 'localhost')
|
|
||||||
self.assertEqual(mongo_connections['t2'].address[0], '127.0.0.1')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user