Esempio n. 1
0
def test_conf_subject_aggregation_and_filter(inspire_app, override_config):
    config = {
        "RECORDS_REST_FACETS": {
            "records-conferences": {
                "filters": {**current_app.config["CONFERENCES_FILTERS"]},
                "aggs": {**conf_subject_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"inspire_categories": [{"term": "Lattice"}]}
        expected_record = create_record("con", data)
        data = {"inspire_categories": [{"term": "Instrumentation"}]}
        create_record("con", data)
        with inspire_app.test_client() as client:
            response = client.get("/conferences/facets").json
        expected_aggregation = {
            "meta": {"title": "Subject", "type": "checkbox", "order": 1},
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {"key": "instrumentation", "doc_count": 1},
                {"key": "lattice", "doc_count": 1},
            ],
        }
        assert response["aggregations"]["subject"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get("/conferences?subject=lattice").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Esempio n. 2
0
def test_records_conferences_facets(inspire_app):
    with current_app.test_request_context():
        expected_filters = {"subject", "start_date", "contains"}
        expected_aggregations = {**conf_subject_aggregation(order=1)}

        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
Esempio n. 3
0
def records_conferences(order=None):
    if order is None:
        order = count(start=1)
    return {
        "filters": {
            **current_app.config["CONFERENCES_FILTERS"]
        },
        "aggs": {
            **conf_subject_aggregation(order=next(order))
        },
    }