fix queryset tests in mongodb v2.4
This commit is contained in:
parent
71ccfeac3c
commit
70faaf445e
@ -1177,7 +1177,7 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
pipeline = initial_pipeline + list(pipeline)
|
pipeline = initial_pipeline + list(pipeline)
|
||||||
|
|
||||||
return self._collection.aggregate(pipeline, cursor={}, **kwargs)
|
return self._collection.aggregate(pipeline, **kwargs)
|
||||||
|
|
||||||
# JS functionality
|
# JS functionality
|
||||||
def map_reduce(self, map_f, reduce_f, output, finalize_f=None, limit=None,
|
def map_reduce(self, map_f, reduce_f, output, finalize_f=None, limit=None,
|
||||||
|
@ -2,15 +2,14 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
import pymongo
|
|
||||||
|
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import pymongo
|
||||||
|
|
||||||
from mongoengine import *
|
from mongoengine import *
|
||||||
from mongoengine.connection import get_db
|
from mongoengine.connection import get_db
|
||||||
from tests.utils import get_mongodb_version
|
|
||||||
|
from tests.utils import get_mongodb_version, skip_in_old_mongodb
|
||||||
|
|
||||||
__all__ = ("IndexesTest", )
|
__all__ = ("IndexesTest", )
|
||||||
|
|
||||||
@ -733,13 +732,6 @@ class IndexesTest(unittest.TestCase):
|
|||||||
|
|
||||||
Log.drop_collection()
|
Log.drop_collection()
|
||||||
|
|
||||||
if pymongo.version_tuple[0] < 2 and pymongo.version_tuple[1] < 3:
|
|
||||||
raise SkipTest('pymongo needs to be 2.3 or higher for this test')
|
|
||||||
|
|
||||||
version_array = get_mongodb_version()
|
|
||||||
if version_array[0] < 2 and version_array[1] < 2:
|
|
||||||
raise SkipTest('MongoDB needs to be 2.2 or higher for this test')
|
|
||||||
|
|
||||||
# Indexes are lazy so use list() to perform query
|
# Indexes are lazy so use list() to perform query
|
||||||
list(Log.objects)
|
list(Log.objects)
|
||||||
info = Log.objects._collection.index_information()
|
info = Log.objects._collection.index_information()
|
||||||
@ -874,9 +866,7 @@ class IndexesTest(unittest.TestCase):
|
|||||||
self.assertTrue(info['provider_ids.foo_1_provider_ids.bar_1']['sparse'])
|
self.assertTrue(info['provider_ids.foo_1_provider_ids.bar_1']['sparse'])
|
||||||
|
|
||||||
def test_text_indexes(self):
|
def test_text_indexes(self):
|
||||||
mongodb_ver = get_mongodb_version()
|
skip_in_old_mongodb('Text search is disabled by default in MongoDB < v2.6')
|
||||||
if mongodb_ver[0] == 2 and mongodb_ver[1] < 6:
|
|
||||||
raise SkipTest('Text search is disabled by default in MongoDB < v2.6')
|
|
||||||
|
|
||||||
class Book(Document):
|
class Book(Document):
|
||||||
title = DictField()
|
title = DictField()
|
||||||
|
@ -19,6 +19,8 @@ from mongoengine.python_support import IS_PYMONGO_3
|
|||||||
from mongoengine.queryset import (DoesNotExist, MultipleObjectsReturned,
|
from mongoengine.queryset import (DoesNotExist, MultipleObjectsReturned,
|
||||||
QuerySet, QuerySetManager, queryset_manager)
|
QuerySet, QuerySetManager, queryset_manager)
|
||||||
|
|
||||||
|
from tests.utils import skip_in_old_mongodb
|
||||||
|
|
||||||
__all__ = ("QuerySetTest",)
|
__all__ = ("QuerySetTest",)
|
||||||
|
|
||||||
|
|
||||||
@ -600,6 +602,8 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(post.comments[0].votes.score, 4)
|
self.assertEqual(post.comments[0].votes.score, 4)
|
||||||
|
|
||||||
def test_update_min_max(self):
|
def test_update_min_max(self):
|
||||||
|
skip_in_old_mongodb('$min is not supported in MongoDB < v2.6')
|
||||||
|
|
||||||
class Scores(Document):
|
class Scores(Document):
|
||||||
high_score = IntField()
|
high_score = IntField()
|
||||||
low_score = IntField()
|
low_score = IntField()
|
||||||
@ -4977,11 +4981,13 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEquals(Animal.objects(folded_ears=True).count(), 1)
|
self.assertEquals(Animal.objects(folded_ears=True).count(), 1)
|
||||||
self.assertEquals(Animal.objects(whiskers_length=5.1).count(), 1)
|
self.assertEquals(Animal.objects(whiskers_length=5.1).count(), 1)
|
||||||
|
|
||||||
def test_loop_via_invalid_id_does_not_crash(self):
|
def test_loop_over_invalid_id_does_not_crash(self):
|
||||||
class Person(Document):
|
class Person(Document):
|
||||||
name = StringField()
|
name = StringField()
|
||||||
Person.objects.delete()
|
|
||||||
Person._get_collection().update({"name": "a"}, {"$set": {"_id": ""}}, upsert=True)
|
Person.drop_collection()
|
||||||
|
|
||||||
|
Person._get_collection().insert({'name': 'a', 'id': ''})
|
||||||
for p in Person.objects():
|
for p in Person.objects():
|
||||||
self.assertEqual(p.name, 'a')
|
self.assertEqual(p.name, 'a')
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
from mongoengine import connect
|
from mongoengine import connect
|
||||||
from mongoengine.connection import get_db, get_connection
|
from mongoengine.connection import get_db, get_connection
|
||||||
|
|
||||||
|
|
||||||
MONGO_TEST_DB = 'mongoenginetest'
|
MONGO_TEST_DB = 'mongoenginetest'
|
||||||
|
|
||||||
|
|
||||||
@ -27,3 +30,12 @@ def get_mongodb_version():
|
|||||||
connection is connected to.
|
connection is connected to.
|
||||||
"""
|
"""
|
||||||
return get_connection().server_info()['versionArray']
|
return get_connection().server_info()['versionArray']
|
||||||
|
|
||||||
|
|
||||||
|
def skip_in_old_mongodb(msg):
|
||||||
|
"""Raise a SkipTest exception with a given message if we're working
|
||||||
|
with MongoDB version lower than v2.6.
|
||||||
|
"""
|
||||||
|
mongodb_ver = get_mongodb_version()
|
||||||
|
if mongodb_ver[0] == 2 and mongodb_ver[1] < 6:
|
||||||
|
raise SkipTest(msg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user