def test_add_search_aggregations_no_filters(self): """Test that when add_search_aggregations is called with an empty\ filter object, no aggregations are added to the search object""" q = Q("bool", should=[Q("match", Test="test")], minimum_should_match=1) query = XSEQueries('test', 'test') query.search = query.search.query(q) filters = [] hasAggs = False query.add_search_aggregations(filters) result_dict = query.search.to_dict() if 'aggs' in result_dict: hasAggs = True self.assertFalse(hasAggs)
def test_add_search_aggregations_with_filters(self): """Test that when add_search_aggregations is called with a list of\ filter object then aggregations are added to the search object""" q = Q("bool", should=[Q("match", Test="test")], minimum_should_match=1) query = XSEQueries('test', 'test') query.search = query.search.query(q) config = XDSConfiguration("test") uiConfig = XDSUIConfiguration(10, config) filterObj = SearchFilter(display_name='type', field_name='type', xds_ui_configuration=uiConfig) filterObj2 = SearchFilter(display_name='color', field_name='color', xds_ui_configuration=uiConfig) filters = [ filterObj, filterObj2, ] hasAggs = False query.add_search_aggregations(filters) result_dict = query.search.to_dict() if 'aggs' in result_dict: hasAggs = True for filtr in filters: hasBucket = False if filtr.display_name in result_dict['aggs']: hasBucket = True self.assertTrue(hasBucket) self.assertTrue(hasAggs)