additional fixes to support Mongo3.4
This commit is contained in:
parent
dca837b843
commit
7247b9b68e
@ -4,7 +4,7 @@
|
|||||||
# combinations:
|
# combinations:
|
||||||
# * MongoDB v2.6 is currently the "main" version tested against Python v2.7,
|
# * MongoDB v2.6 is currently the "main" version tested against Python v2.7,
|
||||||
# v3.5, v3.6, PyPy, and PyMongo v3.x.
|
# 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
|
# and Pymongo v3.5 & v3.x
|
||||||
# * MongoDB v3.4 is tested against v3.6 and Pymongo 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.
|
# Reminder: Update README.rst if you change MongoDB versions we test.
|
||||||
|
@ -808,7 +808,7 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
db.drop_collection(col_name)
|
db.drop_collection(col_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_index(cls, keys, background=False, **kwargs):
|
def _create_index(cls, keys, background=False, **kwargs):
|
||||||
"""Creates the given indexes if required.
|
"""Creates the given indexes if required.
|
||||||
|
|
||||||
:param keys: a single index key or a list of index keys (to
|
: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)
|
warnings.warn(msg, DeprecationWarning)
|
||||||
elif not IS_PYMONGO_3:
|
elif not IS_PYMONGO_3:
|
||||||
kwargs.update({'drop_dups': drop_dups})
|
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
|
||||||
def ensure_indexes(cls):
|
def ensure_indexes(cls):
|
||||||
|
@ -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
|
from mongoengine.connection import get_connection
|
||||||
|
|
||||||
|
@ -603,18 +603,24 @@ class IndexesTest(unittest.TestCase):
|
|||||||
|
|
||||||
@requires_mongodb_gte_34
|
@requires_mongodb_gte_34
|
||||||
def test_primary_key_unique_not_working_under_mongo_34(self):
|
def test_primary_key_unique_not_working_under_mongo_34(self):
|
||||||
|
"""Relates to #1445"""
|
||||||
class Blog(Document):
|
class Blog(Document):
|
||||||
id = StringField(primary_key=True, unique=True)
|
id = StringField(primary_key=True, unique=True)
|
||||||
|
|
||||||
|
Blog.drop_collection()
|
||||||
|
|
||||||
with self.assertRaises(OperationFailure) as ctx_err:
|
with self.assertRaises(OperationFailure) as ctx_err:
|
||||||
Blog(id='garbage').save()
|
Blog(id='garbage').save()
|
||||||
self.assertIn("The field 'unique' is not valid for an _id index specification", str(ctx_err.exception))
|
self.assertIn("The field 'unique' is not valid for an _id index specification", str(ctx_err.exception))
|
||||||
|
|
||||||
@requires_mongodb_lte_32
|
@requires_mongodb_lte_32
|
||||||
def test_primary_key_unique_working_under_mongo_32(self):
|
def test_primary_key_unique_working_under_mongo_32(self):
|
||||||
|
"""Relates to #1445"""
|
||||||
class Blog(Document):
|
class Blog(Document):
|
||||||
id = StringField(primary_key=True, unique=True)
|
id = StringField(primary_key=True, unique=True)
|
||||||
|
|
||||||
|
Blog.drop_collection()
|
||||||
|
|
||||||
Blog(id='garbage').save()
|
Blog(id='garbage').save()
|
||||||
|
|
||||||
def test_unique_with(self):
|
def test_unique_with(self):
|
||||||
|
@ -33,12 +33,12 @@ def get_as_pymongo(doc):
|
|||||||
return doc.__class__.objects.as_pymongo().get(id=doc.id)
|
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
|
"""Return a given function decorated with the version requirement
|
||||||
for a particular MongoDB version tuple.
|
for a particular MongoDB version tuple.
|
||||||
|
|
||||||
:param mongo_version_req: The mongodb version requirement (tuple(int, int))
|
: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):
|
def _inner(*args, **kwargs):
|
||||||
mongodb_v = get_mongodb_version()
|
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
|
"""Raise a SkipTest exception if we're working with MongoDB version
|
||||||
lower than v3.4
|
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):
|
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
|
"""Raise a SkipTest exception if we're working with MongoDB version
|
||||||
lower than v2.6.
|
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):
|
def requires_mongodb_gte_3(func):
|
||||||
"""Raise a SkipTest exception if we're working with MongoDB version
|
"""Raise a SkipTest exception if we're working with MongoDB version
|
||||||
lower than v3.0.
|
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):
|
def skip_pymongo3(f):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user