def test_search_factory_only_with_aggs_without_query(inspire_app): mock_filter = MagicMock() mock_post_filter = MagicMock() facets = { "aggs": { "type": { "terms": { "field": "value" } } }, "filters": { "type": mock_filter("type") }, "post_filters": { "type": mock_post_filter("type") }, } config = {"RECORDS_REST_FACETS": {"*": facets}} with override_config(**config), current_app.test_request_context(""): search = InspireSearch() search, urlkwargs = search_factory_only_with_aggs(None, search) search_to_dict = search.to_dict() assert "aggs" in search_to_dict assert "filter" not in search_to_dict assert "post_filter" not in search_to_dict
def test_search_factory_only_with_aggs(inspire_app): mock_filter = MagicMock() mock_post_filter = MagicMock() facets = { "aggs": { "type": { "terms": { "field": "value" } } }, "filters": { "type": mock_filter("type") }, "post_filters": { "type": mock_post_filter("type") }, } config = {"RECORDS_REST_FACETS": {"*": facets}} with override_config( **config), current_app.test_request_context("?q=foo&type=bar"): search = InspireSearch() search, urlkwargs = search_factory_only_with_aggs(None, search) search_to_dict = search.to_dict() search_to_dict_filters = search_to_dict["query"]["bool"] urlkwargs_to_dict = urlkwargs.to_dict() expected_urlkwargs = {"q": "foo", "type": "bar"} assert expected_urlkwargs == urlkwargs_to_dict assert "aggs" in search_to_dict assert "filter" in search_to_dict_filters assert "post_filter" in search_to_dict
def test_search_factory_without_aggs_with_query(base_app): mock_filter = MagicMock() mock_post_filter = MagicMock() facets = { "aggs": { "type": { "terms": { "field": "value" } } }, "filters": { "type": mock_filter("type") }, "post_filters": { "type": mock_post_filter("type") }, } config = {"RECORDS_REST_FACETS": {"_all": facets}} with patch.dict(base_app.config, config), base_app.test_request_context("?q=foo&type=bar"): search = InspireSearch() search, urlkwargs = search_factory_without_aggs(None, search) search_to_dict = search.to_dict() urlkwargs_to_dict = urlkwargs.to_dict() search_to_dict_filters = search_to_dict["query"]["bool"] expected_urlkwargs = {"q": "foo", "type": "bar"} assert expected_urlkwargs == urlkwargs_to_dict assert "aggs" not in search_to_dict assert "filter" in search_to_dict_filters assert "post_filter" in search_to_dict
def test_search_factory_without_query(base_app): with base_app.test_request_context(""): search = InspireSearch() expected_query_string = "" expected_search_to_dict = {"query": {"match_all": {}}} query_string, search = inspire_search_factory(None, search) search_to_dict = search.to_dict() assert expected_query_string == query_string assert expected_search_to_dict == search_to_dict
def test_search_factory_without_query(inspire_app): with current_app.test_request_context(""): search = InspireSearch() expected_query_string = "" expected_search_to_dict = { "query": { "match_all": {} }, "track_total_hits": True } query_string, search = inspire_search_factory(None, search) search_to_dict = search.to_dict() assert expected_query_string == query_string assert expected_search_to_dict == search_to_dict
def test_search_factory_with_query(inspire_app): with current_app.test_request_context("?q=foo"): search = InspireSearch() expected_query_string = "foo" expected_search_to_dict = { "query": { "query_string": { "default_operator": "AND", "query": "foo" } }, "track_total_hits": True, } query_string, search = inspire_search_factory(None, search) search_to_dict = search.to_dict() assert expected_query_string == query_string assert expected_search_to_dict == search_to_dict