Пример #1
0
def test_seminar_accessibility_aggregation(inspire_app, override_config):
    config = {
        "RECORDS_REST_FACETS": {
            "records-seminars": {
                "filters": {
                    **current_app.config["SEMINARS_FILTERS"]
                },
                "aggs": {
                    **seminar_accessibility_aggregation(1)
                },
            }
        }
    }

    with override_config(**config):
        data = {
            "material_urls": [
                {
                    "description": "slides",
                    "value": "http://slides.com"
                },
                {
                    "value": "http://pdf.com"
                },
            ],
            "captioned":
            True,
        }
        expected_record = create_record("sem", data)
        data = {"captioned": True}
        create_record("sem", data)
        with inspire_app.test_client() as client:
            response = client.get("/seminars/facets").json
        expected_aggregation = {
            "meta": {
                "title": "Accessibility",
                "type": "checkbox",
                "order": 1,
                "is_filter_aggregation": True,
            },
            "buckets": [
                {
                    "key": "Has captions",
                    "doc_count": 2
                },
                {
                    "key": "Has material",
                    "doc_count": 1
                },
            ],
        }
        assert response["aggregations"][
            "accessibility"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get(
                "/seminars?accessibility=Has%20material").json
        assert len(response["hits"]["hits"]) == 1
        assert (response["hits"]["hits"][0]["metadata"]["control_number"] ==
                expected_record["control_number"])
Пример #2
0
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)),
            **seminar_accessibility_aggregation(order=next(order)),
        },
    }
def test_records_seminars_facets(inspire_app):
    with current_app.test_request_context():
        expected_filters = {"subject", "series", "start_date", "accessibility"}
        expected_aggregations = {
            **seminar_series_aggregation(order=1),
            **seminar_subject_aggregation(order=2),
            **seminar_accessibility_aggregation(order=3),
        }

        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