Fixed error in empty property on QCombination

This commit is contained in:
Harry Marr 2010-10-03 23:22:36 +01:00
parent db2f64c290
commit c0f7c4ca2d
2 changed files with 11 additions and 1 deletions

View File

@ -158,7 +158,7 @@ class QCombination(QNode):
@property
def empty(self):
return not bool(self.query)
return not bool(self.children)
class NewQ(QNode):

View File

@ -1417,6 +1417,7 @@ class NewQTest(unittest.TestCase):
def test_and_combination(self):
class TestDoc(Document):
x = IntField()
y = StringField()
# Check than an error is raised when conflicting queries are anded
def invalid_combination():
@ -1432,6 +1433,15 @@ class NewQTest(unittest.TestCase):
query = (q1 & q2).to_query(TestDoc)
self.assertEqual(query, {'x': {'$lt': 7, '$gt': 3}})
# More complex nested example
query = NewQ(x__lt=100) & NewQ(y__ne='NotMyString')
query &= NewQ(y__in=['a', 'b', 'c']) & NewQ(x__gt=-100)
mongo_query = {
'x': {'$lt': 100, '$gt': -100},
'y': {'$ne': 'NotMyString', '$in': ['a', 'b', 'c']},
}
self.assertEqual(query.to_query(TestDoc), mongo_query)
def test_or_combination(self):
class TestDoc(Document):
x = IntField()