Adapted one more test for MongoDB < 3

This commit is contained in:
Matthieu Rigal 2015-06-21 13:41:41 +02:00
parent 95165aa92f
commit 40f6df7160
2 changed files with 13 additions and 5 deletions

View File

@ -6,7 +6,7 @@ from bson import SON
from mongoengine.base.fields import UPDATE_OPERATORS from mongoengine.base.fields import UPDATE_OPERATORS
from mongoengine.connection import get_connection from mongoengine.connection import get_connection
from mongoengine.common import _import_class from mongoengine.common import _import_class
from mongoengine.errors import InvalidQueryError, LookUpError from mongoengine.errors import InvalidQueryError
__all__ = ('query', 'update') __all__ = ('query', 'update')

View File

@ -189,15 +189,23 @@ class GeoQueriesTest(unittest.TestCase):
location__max_distance=60 / earth_radius) location__max_distance=60 / earth_radius)
self.assertEqual(points.count(), 2) self.assertEqual(points.count(), 2)
# Test query works with max_distance being farer from one point # Test query works with max_distance, being farer from one point
points = Point.objects(location__near_sphere=[-122, 37.8], points = Point.objects(location__near_sphere=[-122, 37.8],
location__min_distance=60 / earth_radius) location__max_distance=60 / earth_radius)
close_point = points.first()
self.assertEqual(points.count(), 1) self.assertEqual(points.count(), 1)
# Test query works with min_distance being farer from one point # Test query works with min_distance, being farer from one point
points = Point.objects(location__near_sphere=[-122, 37.8], points = Point.objects(location__near_sphere=[-122, 37.8],
location__min_distance=60 / earth_radius) location__min_distance=60 / earth_radius)
self.assertEqual(points.count(), 1) # The following real test passes on MongoDB 3 but minDistance seems
# buggy on older MongoDB versions
if get_connection().server_info()['versionArray'][0] > 2:
self.assertEqual(points.count(), 1)
far_point = points.first()
self.assertNotEqual(close_point, far_point)
else:
self.assertTrue(points.count() >= 1)
# Finds both points, but orders the north point first because it's # Finds both points, but orders the north point first because it's
# closer to the reference point to the north. # closer to the reference point to the north.