def test_apply_request_filter__query_string(client, app): with app.test_request_context(): search = SearchQuery() search.args = {'q': 'Sport AND Tennis'} service.apply_request_filter(search) assert { 'query_string': { 'query': 'Sport AND Tennis', 'default_operator': 'AND', 'lenient': True } } in search.query['bool']['must'] search.args = {'q': 'Sport AND Tennis', 'default_operator': 'OR'} service.apply_request_filter(search) assert { 'query_string': { 'query': 'Sport AND Tennis', 'default_operator': 'OR', 'lenient': True } } in search.query['bool']['must']
def test_apply_request_filter__filters(client, app): with app.test_request_context(): app.config['FILTER_BY_POST_FILTER'] = False app.config['FILTER_AGGREGATIONS'] = True search = SearchQuery() search.args = {'filter': json.dumps({'service': ['a']})} service.apply_request_filter(search) assert { 'terms': { 'service.name': ['a'] } } in search.query['bool']['must'] search = SearchQuery() search.args = {'filter': {'service': ['a']}} service.apply_request_filter(search) assert { 'terms': { 'service.name': ['a'] } } in search.query['bool']['must'] with raises(BadParameterValueError): search.args = {'filter': ['test']} service.apply_request_filter(search) app.config['FILTER_BY_POST_FILTER'] = False app.config['FILTER_AGGREGATIONS'] = False search = SearchQuery() search.args = {'filter': {'term': {'service': 'a'}}} service.apply_request_filter(search) assert {'term': {'service': 'a'}} in search.query['bool']['must'] app.config['FILTER_BY_POST_FILTER'] = True app.config['FILTER_AGGREGATIONS'] = True search = SearchQuery() search.args = {'filter': {'service': ['a']}} service.apply_request_filter(search) assert { 'terms': { 'service.name': ['a'] } } in search.source['post_filter']['bool']['must'] app.config['FILTER_BY_POST_FILTER'] = True app.config['FILTER_AGGREGATIONS'] = False search = SearchQuery() search.args = {'filter': {'term': {'service': 'a'}}} service.apply_request_filter(search) assert { 'term': { 'service': 'a' } } in search.source['post_filter']['bool']['must']
def test_apply_request_filter__versioncreated(client, app): with app.test_request_context(): app.config['FILTER_BY_POST_FILTER'] = False search = SearchQuery() search.args = {'created_from': '2020-03-27'} service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'gte': get_local_date('2020-03-27', '00:00:00', 0) } } } in search.query['bool']['must'] search = SearchQuery() search.args = {'created_to': '2020-03-27'} service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'lte': get_local_date('2020-03-27', '23:59:59', 0) } } } in search.query['bool']['must'] search = SearchQuery() search.args = { 'created_from': '2020-03-27', 'created_from_time': '01:12:45', 'created_to': '2020-03-27' } service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'gte': get_local_date('2020-03-27', '01:12:45', 0), 'lte': get_local_date('2020-03-27', '23:59:59', 0) } } } in search.query['bool']['must'] app.config['FILTER_BY_POST_FILTER'] = True search = SearchQuery() search.args = {'created_from': '2020-03-27'} service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'gte': get_local_date('2020-03-27', '00:00:00', 0) } } } in search.source['post_filter']['bool']['must'] search = SearchQuery() search.args = {'created_to': '2020-03-27'} service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'lte': get_local_date('2020-03-27', '23:59:59', 0) } } } in search.source['post_filter']['bool']['must'] search = SearchQuery() search.args = { 'created_from': '2020-03-27', 'created_from_time': '01:12:45', 'created_to': '2020-03-27' } service.apply_request_filter(search) assert { 'range': { 'versioncreated': { 'gte': get_local_date('2020-03-27', '01:12:45', 0), 'lte': get_local_date('2020-03-27', '23:59:59', 0) } } } in search.source['post_filter']['bool']['must']