示例#1
0
def test_jobs_field_of_interest_aggregation_and_filter(inspire_app, override_config):
    config = {
        "RECORDS_REST_FACETS": {
            "records-jobs": {
                "filters": {**current_app.config["JOBS_FILTERS"]},
                "aggs": {**jobs_field_of_interest_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"arxiv_categories": ["physics"], "status": "open"}
        expected_record = create_record("job", data)
        data = {"arxiv_categories": ["hep-ex"], "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": "Field of Interest", "order": 1},
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {"key": "hep-ex", "doc_count": 1},
                {"key": "physics", "doc_count": 1},
            ],
        }
        assert response["aggregations"]["field_of_interest"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get("/jobs?field_of_interest=physics").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
示例#2
0
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