QuerySet chaining test was supplemented with ReferenceField
chaining test
This commit is contained in:
parent
f7515cfca8
commit
165bea5bb9
@ -232,28 +232,33 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_chaining(self):
|
def test_chaining(self):
|
||||||
class A(Document):
|
class A(Document):
|
||||||
pass
|
s = StringField()
|
||||||
|
|
||||||
class B(Document):
|
class B(Document):
|
||||||
a = ReferenceField(A)
|
ref = ReferenceField(A)
|
||||||
|
boolfield = BooleanField(default=False)
|
||||||
|
|
||||||
A.drop_collection()
|
A.drop_collection()
|
||||||
B.drop_collection()
|
B.drop_collection()
|
||||||
|
|
||||||
a1 = A().save()
|
a1 = A(s="test1").save()
|
||||||
a2 = A().save()
|
a2 = A(s="test2").save()
|
||||||
|
|
||||||
B(a=a1).save()
|
B(ref=a1, boolfield=True).save()
|
||||||
|
|
||||||
# Works
|
# Works
|
||||||
q1 = B.objects.filter(a__in=[a1, a2], a=a1)._query
|
q1 = B.objects.filter(ref__in=[a1, a2], ref=a1)._query
|
||||||
|
|
||||||
# Doesn't work
|
# Doesn't work
|
||||||
q2 = B.objects.filter(a__in=[a1, a2])
|
q2 = B.objects.filter(ref__in=[a1, a2])
|
||||||
q2 = q2.filter(a=a1)._query
|
q2 = q2.filter(ref=a1)._query
|
||||||
|
|
||||||
self.assertEqual(q1, q2)
|
self.assertEqual(q1, q2)
|
||||||
|
|
||||||
|
a_objects = A.objects(s='test1')
|
||||||
|
query = B.objects(ref__in=a_objects)
|
||||||
|
query = query.filter(boolfield=True)
|
||||||
|
self.assertEquals(query.count(), 1)
|
||||||
|
|
||||||
def test_update_write_options(self):
|
def test_update_write_options(self):
|
||||||
"""Test that passing write_options works"""
|
"""Test that passing write_options works"""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user