Пример #1
0
def test_conf_series_aggregation_and_filter(inspire_app, override_config):
    config = {
        "RECORDS_REST_FACETS": {
            "records-conferences": {
                "filters": {**current_app.config["CONFERENCES_FILTERS"]},
                "aggs": {**conf_series_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"series": [{"name": "Series1"}]}
        expected_record = create_record("con", data)
        data = {"series": [{"name": "ICHEP"}]}
        create_record("con", data)
        with inspire_app.test_client() as client:
            response = client.get("/conferences/facets").json
        expected_aggregation = {
            "meta": {"title": "Series", "type": "checkbox", "order": 1},
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {"key": "ICHEP", "doc_count": 1},
                {"key": "Series1", "doc_count": 1},
            ],
        }
        assert response["aggregations"]["series"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get("/conferences?series=Series1").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Пример #2
0
def records_conferences(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": {
            **current_app.config["CONFERENCES_FILTERS"]
        },
        "aggs": {
            **conf_series_aggregation(order=next(order)),
            **conf_subject_aggregation(order=next(order)),
        },
    }
def test_records_conferences_facets(inspire_app):
    with current_app.test_request_context():
        expected_filters = {"subject", "series", "start_date", "contains"}
        expected_aggregations = {
            **conf_series_aggregation(order=1),
            **conf_subject_aggregation(order=2),
        }

        filters = current_app.config["RECORDS_REST_FACETS"][
            "records-conferences"]()["filters"].keys()
        aggregations = current_app.config["RECORDS_REST_FACETS"][
            "records-conferences"]()["aggs"]
        assert filters == expected_filters
        assert aggregations == expected_aggregations