def test_jobs_rank_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-jobs": { "filters": {**current_app.config["JOBS_FILTERS"]}, "aggs": {**jobs_rank_aggregation(1)}, } } } with override_config(**config): data = {"ranks": ["POSTDOC"], "status": "open"} expected_record = create_record("job", data) data = {"ranks": ["JUNIOR"], "status": "open"} create_record("job", data) with inspire_app.test_client() as client: response = client.get("/jobs/facets").json expected_aggregation = { "meta": {"type": "multiselect", "title": "Rank", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"doc_count": 1, "key": "JUNIOR"}, {"doc_count": 1, "key": "POSTDOC"}, ], } assert response["aggregations"]["rank"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/jobs?rank=POSTDOC").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def records_jobs(order=None): if order is None: order = count(start=1) return { "filters": { **current_app.config["JOBS_FILTERS"] }, "aggs": { **jobs_field_of_interest_aggregation(order=next(order)), **jobs_rank_aggregation(order=next(order)), **jobs_region_aggregation(order=next(order)), }, }
def test_records_jobs_cataloger_facets(inspire_app): with current_app.test_request_context(): expected_filters = {"field_of_interest", "rank", "region", "status"} expected_aggregations = { **jobs_field_of_interest_aggregation(order=1), **jobs_rank_aggregation(order=2), **jobs_region_aggregation(order=3), **jobs_status_aggregation(order=4), } filters = current_app.config["CATALOGER_RECORDS_REST_FACETS"][ "records-jobs"]()["filters"].keys() aggregations = current_app.config["CATALOGER_RECORDS_REST_FACETS"][ "records-jobs"]()["aggs"] assert filters == expected_filters assert aggregations == expected_aggregations