def test_elastic_using_endswith_filter(self): f = FilterConditionService() doc = {'field': 'headline', 'operator': 'endswith', 'value': 'Que'} query = f.get_elastic_query(doc) with self.app.app_context(): self._setup_elastic_args(query, 'keyword') docs = superdesk.get_resource_service('archive').get(req=self.req, lookup=None) self.assertEqual(1, docs.count()) self.assertEqual('2', docs[0]['_id'])
def test_elastic_using_notlike_filter(self): f = FilterConditionService() doc = {'field': 'headline', 'operator': 'notlike', 'value': 'que'} query = f.get_elastic_query(doc) with self.app.app_context(): self._setup_elastic_args(query, 'not') docs = superdesk.get_resource_service('archive').get(req=self.req, lookup=None) self.assertEqual(7, docs.count()) doc_ids = [d['_id'] for d in docs] self.assertTrue('2' not in doc_ids)
def test_elastic_using_subject_filter_complete_string(self): f = FilterConditionService() doc = {'field': 'subject', 'operator': 'in', 'value': '05005003'} query = f.get_elastic_query(doc) with self.app.app_context(): self._setup_elastic_args(query) docs = superdesk.get_resource_service('archive').get(req=self.req, lookup=None) doc_ids = [d['_id'] for d in docs] self.assertEqual(1, docs.count()) self.assertTrue('8' in doc_ids)
def test_elastic_using_in_filter(self): f = FilterConditionService() doc = {'field': 'urgency', 'operator': 'in', 'value': '3,4'} query = f.get_elastic_query(doc) with self.app.app_context(): self._setup_elastic_args(query) docs = superdesk.get_resource_service('archive').get(req=self.req, lookup=None) doc_ids = [d['_id'] for d in docs] self.assertEqual(2, docs.count()) self.assertTrue('4' in doc_ids) self.assertTrue('3' in doc_ids)