def test_seminar_subject_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-seminars": { "filters": {**current_app.config["SEMINARS_FILTERS"]}, "aggs": {**seminar_subject_aggregation(1)}, } } } with override_config(**config): data = {"inspire_categories": [{"term": "Lattice"}]} expected_record = create_record("sem", data) data = {"inspire_categories": [{"term": "Instrumentation"}]} create_record("sem", data) with inspire_app.test_client() as client: response = client.get("/seminars/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("/seminars?subject=Lattice").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def records_seminars(order=None): if order is None: order = count(start=1) return { "filters": seminars_filters(), "aggs": { **seminar_series_aggregation(order=next(order)), **seminar_subject_aggregation(order=next(order)), }, }
def test_records_seminars_facets(inspire_app): with current_app.test_request_context(): expected_filters = {"subject", "series", "start_date"} expected_aggregations = { **seminar_series_aggregation(order=1), **seminar_subject_aggregation(order=2), } filters = current_app.config["RECORDS_REST_FACETS"][ "records-seminars"]()["filters"].keys() aggregations = current_app.config["RECORDS_REST_FACETS"][ "records-seminars"]()["aggs"] assert filters == expected_filters assert aggregations == expected_aggregations