def test_is_empty(self): # And filter with no nested clauses is empty. and_filter = And() self.assertTrue(and_filter.is_empty()) # Not filter with no nested clauses is empty. not_filter = Not() self.assertTrue(not_filter.is_empty()) # An age filter is never empty. age_filter = Age('woot') self.assertFalse(age_filter.is_empty()) # We're adding the not filter to the and_filter. The not_filter is # empty, therefore so is the and_filter. and_filter.add_filter(not_filter) self.assertTrue(and_filter.is_empty()) # Now we add an age_filter to the not filter, and the whole onion of # nested filters starts evaluating as "not empty." not_filter.add_filter(age_filter) self.assertFalse(not_filter.is_empty()) self.assertFalse(and_filter.is_empty())
def test_single_clause_and_filter(self): and_filter = And() and_filter.add_filter(Exists("value")) self.assertEquals({"and": [ {"exists": {"field": "value"}} ]}, and_filter.to_query())
def test_empty_and_filter(self): and_filter = And() self.assertEquals({"and": []}, and_filter.to_query())