Ensure that empty Q objects won't hurt.
(self)
| 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""" |