Previously, we were running the test suite for several combinations of MongoDB, Python, and PyMongo: - PyPy, MongoDB v2.6, PyMongo v3.x (which really means v3.6.1 at the moment) - Python v2.7, MongoDB v2.6, PyMongo v3.x - Python v3.5, MongoDB v2.6, PyMongo v3.x - Python v3.6, MongoDB v2.6, PyMongo v3.x - Python v2.7, MongoDB v3.0, PyMongo v3.5.0 - Python v3.6, MongoDB v3.0, PyMongo v3.5.0 - Python v3.5, MongoDB v3.2, PyMongo v3.x - Python v3.6, MongoDB v3.2, PyMongo v3.x - Python v3.6, MongoDB v3.4, PyMongo v3.x - Python v3.6, MongoDB v3.6, PyMongo v3.x There were a couple issues with this setup: 1. MongoDB v2.6 – v3.2 have reached their End of Life already (v2.6 almost 3 years ago!). See the "MongoDB Server" section on https://www.mongodb.com/support-policy. 2. We were only testing two recent-ish PyMongo versions (v3.5.0 & v3.6.1). We were not testing the oldest actively supported MongoDB/PyMongo/Python setup. This PR updates the test matrix so that these problems are solved. For the sake of simplicity, it does not yet attempt to cover MongoDB v4.0: - PyPy, MongoDB v3.4, PyMongo v3.x (aka v3.6.1 at the moment) - Python v2.7, MongoDB v3.4, PyMongo v3.x - Python v3.5, MongoDB v3.4, PyMongo v3.x - Python v3.6, MongoDB v3.4, PyMongo v3.x - Python v2.7, MongoDB v3.4, PyMongo v3.4 - Python v3.6, MongoDB v3.6, PyMongo v3.x
		
			
				
	
	
		
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import operator
 | |
| import unittest
 | |
| 
 | |
| from nose.plugins.skip import SkipTest
 | |
| 
 | |
| from mongoengine import connect
 | |
| from mongoengine.connection import get_db, disconnect_all
 | |
| from mongoengine.mongodb_support import get_mongodb_version
 | |
| 
 | |
| 
 | |
| MONGO_TEST_DB = 'mongoenginetest'   # standard name for the test database
 | |
| 
 | |
| 
 | |
| 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
 | |
|     """
 | |
| 
 | |
|     @classmethod
 | |
|     def setUpClass(cls):
 | |
|         disconnect_all()
 | |
|         cls._connection = connect(db=MONGO_TEST_DB)
 | |
|         cls._connection.drop_database(MONGO_TEST_DB)
 | |
|         cls.db = get_db()
 | |
| 
 | |
|     @classmethod
 | |
|     def tearDownClass(cls):
 | |
|         cls._connection.drop_database(MONGO_TEST_DB)
 | |
|         disconnect_all()
 | |
| 
 | |
| 
 | |
| def get_as_pymongo(doc):
 | |
|     """Fetch the pymongo version of a certain Document"""
 | |
|     return doc.__class__.objects.as_pymongo().get(id=doc.id)
 | |
| 
 | |
| 
 | |
| def _decorated_with_ver_requirement(func, mongo_version_req, oper):
 | |
|     """Return a MongoDB version requirement decorator.
 | |
| 
 | |
|     The resulting decorator will raise a SkipTest exception if the current
 | |
|     MongoDB version doesn't match the provided version/operator.
 | |
| 
 | |
|     For example, if you define a decorator like so:
 | |
| 
 | |
|         def requires_mongodb_gte_36(func):
 | |
|             return _decorated_with_ver_requirement(
 | |
|                 func, (3.6), oper=operator.ge
 | |
|             )
 | |
| 
 | |
|     Then tests decorated with @requires_mongodb_gte_36 will be skipped if
 | |
|     ran against MongoDB < v3.6.
 | |
| 
 | |
|     :param mongo_version_req: The mongodb version requirement (tuple(int, int))
 | |
|     :param oper: The operator to apply (e.g: operator.ge)
 | |
|     """
 | |
|     def _inner(*args, **kwargs):
 | |
|         mongodb_v = get_mongodb_version()
 | |
|         if oper(mongodb_v, mongo_version_req):
 | |
|             return func(*args, **kwargs)
 | |
| 
 | |
|         raise SkipTest('Needs MongoDB v{}+'.format('.'.join(str(n) for n in mongo_version_req)))
 | |
| 
 | |
|     _inner.__name__ = func.__name__
 | |
|     _inner.__doc__ = func.__doc__
 | |
|     return _inner
 |