additional fixes to support Mongo3.4
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user