def test_hep_earliest_date_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_earliest_date_aggregation(1)}, } } } with override_config(**config): data = {"preprint_date": "2019-06-28"} expected_record = create_record("lit", data) data = {"preprint_date": "2015-06-28"} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json earliest_date_aggregation = { "meta": {"title": "Papers per year", "type": "range", "order": 1}, "buckets": [ {"doc_count": 1, "key": 1420070400000, "key_as_string": "2015"}, {"doc_count": 1, "key": 1546300800000, "key_as_string": "2019"}, ], } assert response["aggregations"]["earliest_date"] == earliest_date_aggregation with inspire_app.test_client() as client: response = client.get("/literature?earliest_date=2018--2019").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_collection_aggregation(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "filters": hep_filters(), "records-hep": {"aggs": {**hep_collection_aggregation(1)}}, } } with override_config(**config): data = {"_collections": ["Literature", "Fermilab"]} expected_record = create_record("lit", data) data = {"_collections": ["Fermilab"]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Collection", "type": "checkbox", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"key": "fermilab", "doc_count": 1}, {"key": "literature", "doc_count": 1}, ], } assert response["aggregations"]["collection"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?collection=Literature").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_author_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_author_aggregation(1)}, } } } with override_config(**config): data = {"authors": [{"full_name": "John Doe"}]} expected_record = create_record("lit", data) data = {"authors": [{"full_name": "Jane Doe"}]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"split": True, "title": "Author", "type": "checkbox", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"key": "NOREC_Jane Doe", "doc_count": 1}, {"key": "NOREC_John Doe", "doc_count": 1}, ], } assert response["aggregations"]["author"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?author=NOREC_John%20Doe").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_subject_aggregation_and_filter_unkown(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_subject_aggregation(1)}, } } } with override_config(**config): expected_record = create_record("lit") create_record("lit") with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Subject", "type": "checkbox", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"key": "Unknown", "doc_count": 2}, ], } assert response["aggregations"]["subject"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?subject=Unknown").json assert len(response["hits"]["hits"]) == 2 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_subject_aggregation_and_filter(inspire_app): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_subject_aggregation(1)}, } } } with override_config(**config): data = {"inspire_categories": [{"term": "Experiment-HEP"}]} expected_record = create_record("lit", data) data = {"inspire_categories": [{"term": "Phenomenology-HEP"}]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Subject", "type": "checkbox", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"key": "Experiment-HEP", "doc_count": 1}, {"key": "Phenomenology-HEP", "doc_count": 1}, ], } assert response["aggregations"]["subject"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?subject=Experiment-HEP").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_author_count_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_author_count_aggregation(1)}, } } } with override_config(**config): data = {"authors": [{"full_name": "John Doe"}]} expected_record = create_record("lit", data) data = {"authors": [{"full_name": "John Doe"}, {"full_name": "Jane Doe"}]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Number of authors", "type": "checkbox", "order": 1}, "buckets": [ {"key": "Single author", "from": 1.0, "to": 2.0, "doc_count": 1}, {"key": "10 authors or less", "from": 1.0, "to": 11.0, "doc_count": 2}, ], } assert response["aggregations"]["author_count"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?author_count=Single%20author").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def test_hep_rpp_aggregation_and_filter(inspire_app): config = { "RECORDS_REST_FACETS": { "records-hep": {"filters": hep_filters(), "aggs": {**hep_rpp(1)}} } } with override_config(**config): data = {"titles": [{"title": "This is my title"}]} expected_record = create_record("lit", data) data = {"titles": [{"title": "RPP"}]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": { "title": "Exclude RPP", "type": "checkbox", "order": 1, "is_filter_aggregation": True, }, "buckets": [{"doc_count": 1, "key": "Exclude Review of Particle Physics"}], } assert response["aggregations"]["rpp"] == expected_aggregation with inspire_app.test_client() as client: response = client.get( "/literature?rpp=Exclude%20Review%20of%20Particle%20Physics" ).json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )
def records_hep(): return { "filters": hep_filters(), "aggs": { **hep_self_author_names_aggregation(1, "999108") }, }
def records_hep(): return { "filters": hep_filters(), "aggs": { **hep_author_affiliations_aggregation(1) }, }
def test_hep_arxiv_categories_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": { **hep_arxiv_categories_aggregation(1) }, } } } with override_config(**config): data = { "arxiv_eprints": [{ "categories": ["astro-ph.GA"], "value": "2002.12811" }] } expected_record = create_record("lit", data) data = { "arxiv_eprints": [{ "categories": ["hep-ph"], "value": "2004.12811" }] } create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": { "title": "arXiv Category", "type": "checkbox", "order": 1 }, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "astro-ph.GA", "doc_count": 1 }, { "key": "hep-ph", "doc_count": 1 }, ], } assert response["aggregations"][ "arxiv_categories"] == expected_aggregation with inspire_app.test_client() as client: response = client.get( "/literature?arxiv_categories=astro-ph.GA").json assert len(response["hits"]["hits"]) == 1 assert (response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"])
def test_hep_self_curated_relation_aggregation_and_filter( inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": { **hep_self_author_claimed_papers_aggregation(1, "999108") }, } } } with override_config(**config): data = { "authors": [{ "full_name": "Maldacena, Juan", "curated_relation": True, "record": { "$ref": "http://labs.inspirehep.net/api/authors/999108" }, }] } create_record("lit", data) data = { "authors": [{ "full_name": "Maldacena, Juan", "curated_relation": False, "record": { "$ref": "http://labs.inspirehep.net/api/authors/999108" }, }] } create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": { "is_filter_aggregation": True, "title": "Claims", "type": "checkbox", "order": 1, }, "buckets": [ { "key": "Claimed papers", "doc_count": 1 }, { "key": "Unclaimed papers", "doc_count": 1 }, ], } assert response["aggregations"][ "self_curated_relation"] == expected_aggregation
def test_hep_doc_type_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": { **hep_doc_type_aggregation(1) }, } } } with override_config(**config): data = {"document_type": ["article"]} expected_record = create_record("lit", data) data = {"document_type": ["conference paper"]} create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json earliest_date_aggregation = { "meta": { "bucket_help": { "published": { "link": "https://inspirehep.net/help/knowledge-base/faq/#faq-published", "text": "Published papers are believed to have undergone rigorous peer review.", } }, "title": "Document Type", "type": "checkbox", "order": 1, }, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "article", "doc_count": 1 }, { "key": "conference paper", "doc_count": 1 }, ], } assert response["aggregations"][ "doc_type"] == earliest_date_aggregation with inspire_app.test_client() as client: response = client.get("/literature?doc_type=article").json assert len(response["hits"]["hits"]) == 1 assert (response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"])
def test_hep_experiments_aggregation_and_filter(inspire_app, override_config): config = { "RECORDS_REST_FACETS": { "records-hep": { "filters": hep_filters(), "aggs": {**hep_experiments_aggregation(1)}, } } } with override_config(**config): data = { "accelerator_experiments": [ { "record": { "$ref": "https://inspirebeta.net/api/experiments/1108541" }, "legacy_name": "CERN-LHC-ATLAS", } ] } expected_record = create_record("lit", data) data = { "accelerator_experiments": [ { "record": { "$ref": "https://inspirebeta.net/api/experiments/1108642" }, "legacy_name": "CERN-LHC-CMS", } ] } create_record("lit", data) with inspire_app.test_client() as client: response = client.get("/literature/facets").json expected_aggregation = { "meta": {"title": "Experiments", "type": "checkbox", "order": 1}, "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {"key": "CERN-LHC-ATLAS", "doc_count": 1}, {"key": "CERN-LHC-CMS", "doc_count": 1}, ], } assert response["aggregations"]["experiments"] == expected_aggregation with inspire_app.test_client() as client: response = client.get("/literature?experiments=CERN-LHC-ATLAS").json assert len(response["hits"]["hits"]) == 1 assert ( response["hits"]["hits"][0]["metadata"]["control_number"] == expected_record["control_number"] )