Compare commits

...

4 Commits

Author SHA1 Message Date
Stefan Wojcik
38c36c0ba4 make the test simpler by using a new doc class 2016-12-03 23:57:07 -05:00
Stefan Wojcik
c1a8b468c5 try dropping collection 2016-12-03 23:32:52 -05:00
Stefan Wojcik
890e58bfcd debug print to see what travis is doing 2016-12-03 21:20:29 -05:00
Stefan Wojcik
debc28a5cf add support for cursor.comment 2016-12-03 18:16:09 -05:00
2 changed files with 23 additions and 1 deletions

View File

@ -933,6 +933,14 @@ class BaseQuerySet(object):
queryset._ordering = queryset._get_order_by(keys)
return queryset
def comment(self, text):
"""Add a comment to the query.
See https://docs.mongodb.com/manual/reference/method/cursor.comment/#cursor.comment
for details.
"""
return self._chainable_method("comment", text)
def explain(self, format=False):
"""Return an explain plan record for the
:class:`~mongoengine.queryset.QuerySet`\ 's cursor.

View File

@ -339,7 +339,6 @@ class QuerySetTest(unittest.TestCase):
def test_update_write_concern(self):
"""Test that passing write_concern works"""
self.Person.drop_collection()
write_concern = {"fsync": True}
@ -2199,6 +2198,21 @@ class QuerySetTest(unittest.TestCase):
a.author.name for a in Author.objects.order_by('-author__age')]
self.assertEqual(names, ['User A', 'User B', 'User C'])
def test_comment(self):
"""Make sure adding a comment to the query works."""
class User(Document):
age = IntField()
with db_ops_tracker() as q:
adult = (User.objects.filter(age__gte=18)
.comment('looking for an adult')
.first())
ops = q.get_ops()
self.assertEqual(len(ops), 1)
op = ops[0]
self.assertEqual(op['query']['$query'], {'age': {'$gte': 18}})
self.assertEqual(op['query']['$comment'], 'looking for an adult')
def test_map_reduce(self):
"""Ensure map/reduce is both mapping and reducing.
"""