- Fixed tests to allow support of MongoDB 3.2

- Replaced MongoDB 2.4 tests in CI by MongoDB 3.2
This commit is contained in:
Bastien Gérard
2018-09-28 22:39:08 +02:00
parent 1887f5b7e7
commit 96f0919633
8 changed files with 126 additions and 95 deletions

View File

@@ -10,6 +10,13 @@ from mongoengine.python_support import IS_PYMONGO_3
MONGO_TEST_DB = 'mongoenginetest' # standard name for the test database
# Constant that can be used to compare the version retrieved with
# get_mongodb_version()
MONGODB_26 = (2, 6)
MONGODB_3 = (3,0)
MONGODB_32 = (3, 2)
class MongoDBTestCase(unittest.TestCase):
"""Base class for tests that need a mongodb connection
It ensures that the db is clean at the beginning and dropped at the end automatically
@@ -27,24 +34,26 @@ class MongoDBTestCase(unittest.TestCase):
def get_mongodb_version():
"""Return the version tuple of the MongoDB server that the default
connection is connected to.
"""Return the version of the connected mongoDB (first 2 digits)
:return: tuple(int, int)
"""
return tuple(get_connection().server_info()['versionArray'])
version_list = get_connection().server_info()['versionArray'][:2] # e.g: (3, 2)
return tuple(version_list)
def _decorated_with_ver_requirement(func, ver_tuple):
def _decorated_with_ver_requirement(func, version):
"""Return a given function decorated with the version requirement
for a particular MongoDB version tuple.
:param version: The version required (tuple(int, int))
"""
def _inner(*args, **kwargs):
mongodb_ver = get_mongodb_version()
if mongodb_ver >= ver_tuple:
MONGODB_V = get_mongodb_version()
if MONGODB_V >= version:
return func(*args, **kwargs)
raise SkipTest('Needs MongoDB v{}+'.format(
'.'.join([str(v) for v in ver_tuple])
))
raise SkipTest('Needs MongoDB v{}+'.format('.'.join(str(n) for n in version)))
_inner.__name__ = func.__name__
_inner.__doc__ = func.__doc__
@@ -56,14 +65,14 @@ def needs_mongodb_v26(func):
"""Raise a SkipTest exception if we're working with MongoDB version
lower than v2.6.
"""
return _decorated_with_ver_requirement(func, (2, 6))
return _decorated_with_ver_requirement(func, MONGODB_26)
def needs_mongodb_v3(func):
"""Raise a SkipTest exception if we're working with MongoDB version
lower than v3.0.
"""
return _decorated_with_ver_requirement(func, (3, 0))
return _decorated_with_ver_requirement(func, MONGODB_3)
def skip_pymongo3(f):