Merge branch 'feature-saferfilter' of https://github.com/elasticsales/mongoengine into 0.8
This commit is contained in:
commit
accdd82970
@ -117,6 +117,9 @@ class QuerySet(object):
|
|||||||
"""
|
"""
|
||||||
query = Q(**query)
|
query = Q(**query)
|
||||||
if q_obj:
|
if q_obj:
|
||||||
|
# make sure proper query object is passed
|
||||||
|
if not isinstance(q_obj, QNode):
|
||||||
|
raise InvalidQueryError('Not a query object: %s. Did you intend to use key=value?' % q_obj)
|
||||||
query &= q_obj
|
query &= q_obj
|
||||||
self._query_obj &= query
|
self._query_obj &= query
|
||||||
self._mongo_query = None
|
self._mongo_query = None
|
||||||
|
@ -1375,6 +1375,14 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(len(self.Person.objects(Q(age__in=[20]))), 2)
|
self.assertEqual(len(self.Person.objects(Q(age__in=[20]))), 2)
|
||||||
self.assertEqual(len(self.Person.objects(Q(age__in=[20, 30]))), 3)
|
self.assertEqual(len(self.Person.objects(Q(age__in=[20, 30]))), 3)
|
||||||
|
|
||||||
|
# Test invalid query objs
|
||||||
|
def wrong_query_objs():
|
||||||
|
self.Person.objects('user1')
|
||||||
|
def wrong_query_objs_filter():
|
||||||
|
self.Person.objects('user1')
|
||||||
|
self.assertRaises(InvalidQueryError, wrong_query_objs)
|
||||||
|
self.assertRaises(InvalidQueryError, wrong_query_objs_filter)
|
||||||
|
|
||||||
def test_q_regex(self):
|
def test_q_regex(self):
|
||||||
"""Ensure that Q objects can be queried using regexes.
|
"""Ensure that Q objects can be queried using regexes.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user