Example #1
0
 def test_age_filter(self, mock_now):
     mock_now.return_value = datetime.datetime(2015, 1, 1, 2, 0, 0)
     age = Age('some_field', lte=3600, gte=1800, gt=1860, lt=1920)
     self.assertEqual(age.to_query(), {
         'range': {
             'some_field': {
                 'gte': '2015-01-01T01:00:00',
                 'lte': '2015-01-01T01:30:00',
                 'lt': '2015-01-01T01:29:00',
                 'gt': '2015-01-01T01:28:00',
             }
         }
     })
Example #2
0
    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())