MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / test_empty_q

Method test_empty_q

tests/queryset/test_visitor.py:25–41  ·  view source on GitHub ↗

Ensure that empty Q objects won't hurt.

(self)

Source from the content-addressed store, hash-verified

23 self.Person = Person
24
25 def test_empty_q(self):
26 """Ensure that empty Q objects won't hurt."""
27 q1 = Q()
28 q2 = Q(age__gte=18)
29 q3 = Q()
30 q4 = Q(name="test")
31 q5 = Q()
32
33 class Person(Document):
34 name = StringField()
35 age = IntField()
36
37 query = {"$or": [{"age": {"$gte": 18}}, {"name": "test"}]}
38 assert (q1 | q2 | q3 | q4 | q5).to_query(Person) == query
39
40 query = {"age": {"$gte": 18}, "name": "test"}
41 assert (q1 & q2 & q3 & q4 & q5).to_query(Person) == query
42
43 def test_q_with_dbref(self):
44 """Ensure Q objects handle DBRefs correctly"""

Callers

nothing calls this directly

Calls 2

QClass · 0.90
to_queryMethod · 0.80

Tested by

no test coverage detected