additional fixes to support Mongo3.4

This commit is contained in:
Bastien Gérard 2019-02-24 22:34:17 +01:00
parent dca837b843
commit 7247b9b68e
5 changed files with 15 additions and 9 deletions

View File

@ -4,7 +4,7 @@
# combinations:
# * MongoDB v2.6 is currently the "main" version tested against Python v2.7,
# v3.5, v3.6, PyPy, and PyMongo v3.x.
# * MongoDB v3.0, v3.2 are tested against Python v2.7, v3.5 & v3.6
# * MongoDB v3.0 & v3.2 are tested against Python v2.7, v3.5 & v3.6
# and Pymongo v3.5 & v3.x
# * MongoDB v3.4 is tested against v3.6 and Pymongo v3.x
# Reminder: Update README.rst if you change MongoDB versions we test.

View File

@ -808,7 +808,7 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
db.drop_collection(col_name)
@classmethod
def create_index(cls, keys, background=False, **kwargs):
def _create_index(cls, keys, background=False, **kwargs):
"""Creates the given indexes if required.
:param keys: a single index key or a list of index keys (to
@ -851,7 +851,7 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
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
def ensure_indexes(cls):

View File

@ -1,5 +1,5 @@
"""
Helper functions, constants, and types to aid with MongoDB v3.x support
Helper functions, constants, and types to aid with MongoDB version support
"""
from mongoengine.connection import get_connection

View File

@ -603,18 +603,24 @@ class IndexesTest(unittest.TestCase):
@requires_mongodb_gte_34
def test_primary_key_unique_not_working_under_mongo_34(self):
"""Relates to #1445"""
class Blog(Document):
id = StringField(primary_key=True, unique=True)
Blog.drop_collection()
with self.assertRaises(OperationFailure) as ctx_err:
Blog(id='garbage').save()
self.assertIn("The field 'unique' is not valid for an _id index specification", str(ctx_err.exception))
@requires_mongodb_lte_32
def test_primary_key_unique_working_under_mongo_32(self):
"""Relates to #1445"""
class Blog(Document):
id = StringField(primary_key=True, unique=True)
Blog.drop_collection()
Blog(id='garbage').save()
def test_unique_with(self):

View File

@ -33,12 +33,12 @@ def get_as_pymongo(doc):
return doc.__class__.objects.as_pymongo().get(id=doc.id)
def _decorated_with_ver_requirement(func, mongo_version_req, oper=operator.ge):
def _decorated_with_ver_requirement(func, mongo_version_req, oper):
"""Return a given function decorated with the version requirement
for a particular MongoDB version tuple.
:param mongo_version_req: The mongodb version requirement (tuple(int, int))
:param oper: The operator to apply
:param oper: The operator to apply (e.g: operator.ge)
"""
def _inner(*args, **kwargs):
mongodb_v = get_mongodb_version()
@ -56,7 +56,7 @@ def requires_mongodb_gte_34(func):
"""Raise a SkipTest exception if we're working with MongoDB version
lower than v3.4
"""
return _decorated_with_ver_requirement(func, MONGODB_34)
return _decorated_with_ver_requirement(func, MONGODB_34, oper=operator.ge)
def requires_mongodb_lte_32(func):
@ -70,14 +70,14 @@ def requires_mongodb_gte_26(func):
"""Raise a SkipTest exception if we're working with MongoDB version
lower than v2.6.
"""
return _decorated_with_ver_requirement(func, MONGODB_26)
return _decorated_with_ver_requirement(func, MONGODB_26, oper=operator.ge)
def requires_mongodb_gte_3(func):
"""Raise a SkipTest exception if we're working with MongoDB version
lower than v3.0.
"""
return _decorated_with_ver_requirement(func, MONGODB_3)
return _decorated_with_ver_requirement(func, MONGODB_3, oper=operator.ge)
def skip_pymongo3(f):