Ensure that QuerySet.only() works correctly after QuerySet.count()

This test checks if .only() method of QuerySet instance works after
using .count() method.
This commit is contained in:
Tom Floyer 2018-12-08 22:10:10 +03:00
parent 0e00695fc7
commit 72ebaa52e9

View File

@ -4720,6 +4720,28 @@ class QuerySetTest(unittest.TestCase):
'password_salt').only('email').to_json() 'password_salt').only('email').to_json()
self.assertEqual('[{"email": "ross@example.com"}]', serialized_user) self.assertEqual('[{"email": "ross@example.com"}]', serialized_user)
def test_only_after_count(self):
"""Test that only() works after count()"""
class User(Document):
name = StringField()
age = IntField()
address = StringField()
User.drop_collection()
User(name="User", age=50,
address="Moscow, Russia").save()
user_queryset = User.objects(age=50)
result = user_queryset.only("name", "age").as_pymongo().first()
self.assertEqual(result, {"name": "User", "age": 50})
result = user_queryset.count()
self.assertEqual(result, 1)
result = user_queryset.only("name", "age").as_pymongo().first()
self.assertEqual(result, {"name": "User", "age": 50})
def test_no_dereference(self): def test_no_dereference(self):
class Organization(Document): class Organization(Document):