Пример #1
0
def test_minter_deletes_pids_when_record_is_deleted(inspire_app):
    data = {
        "authors": [{
            "full_name": "Janeway, K."
        }],
        "publication_info": [{
            "year": 2000
        }],
        "texkeys": ["Janeway:2000abc", "Janeway:2000def"],
    }
    with override_config(FEATURE_FLAG_ENABLE_TEXKEY_MINTER=True):
        record = create_record("lit", data=data)

    pids = PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_type == "texkey").all()
    assert len(pids) == 2
    assert pids[0].status == PIDStatus.REGISTERED
    assert pids[1].status == PIDStatus.REGISTERED

    with override_config(FEATURE_FLAG_ENABLE_TEXKEY_MINTER=True):
        record.delete()
    pids = PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_type == "texkey").all()
    assert len(pids) == 2
    assert pids[0].status == PIDStatus.DELETED
    assert pids[1].status == PIDStatus.DELETED
Пример #2
0
def test_old_minter_bai_already_existing(inspire_app):
    with override_config(FEATURE_FLAG_ENABLE_BAI_PROVIDER=False):
        record_1 = create_record("aut", other_pids=["bai"])
    data2 = {"ids": record_1["ids"]}

    with pytest.raises(PIDAlreadyExists), override_config(
            FEATURE_FLAG_ENABLE_BAI_PROVIDER=False):
        create_record("aut", data2)
Пример #3
0
def test_facet_configuration_with_existing_facet_callable(inspire_app):
    facet_mock = Mock()
    facet_mock.return_value = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    config = {"RECORDS_REST_FACETS": {"defenders": facet_mock}}
    expected = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    with current_app.test_request_context("?facet_name=defenders"):
        with override_config(**config):
            result = get_facet_configuration("records-hep")
            facet_mock.assert_called_once()
            assert expected == result
Пример #4
0
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"]
        )
Пример #5
0
    def test_push_unhandled_duplicated_external_identifier_pusher_exception(
            self):
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
                ORCID_APP_CREDENTIALS={"consumer_key": "0000-0001-8607-8906"},
        ):
            pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                               self.oauth_token)
            pusher.push()

            self.factory_clashing.record_metadata.json["titles"] = [{
                "source":
                "submitter",
                "title":
                "title1"
            }]

            pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                               self.oauth_token)
            pusher.push()

            with pytest.raises(
                    exceptions.DuplicatedExternalIdentifierPusherException):
                pusher = domain_models.OrcidPusher(self.orcid,
                                                   self.clashing_recid,
                                                   self.oauth_token)
                pusher.push()
Пример #6
0
def test_get_search_with_source_with_LiteratureSearch_instance_with_defined_headers(
        inspire_app):
    config = {
        "LITERATURE_SOURCE_INCLUDES_BY_CONTENT_TYPE": {
            "application/vnd+inspire.record.ui+json": ["title", "description"]
        },
        "LITERATURE_SOURCE_EXCLUDES_BY_CONTENT_TYPE": {
            "application/vnd+inspire.record.ui+json":
            ["excludes_with_includes_looks_stupid"],
            "application/bibtex": ["control_number"],
        },
    }
    headers = {"Accept": "application/vnd+inspire.record.ui+json"}
    with override_config(**config), current_app.test_request_context(
            headers=headers):
        search = LiteratureSearch()
        search = get_search_with_source(search)

        expected_source_includes = ["title", "description"]
        expected_source_excludes = ["excludes_with_includes_looks_stupid"]

        search_to_dict = search.to_dict()
        search_source = search_to_dict["_source"]

        assert expected_source_includes == search_source["includes"]
        assert expected_source_excludes == search_source["excludes"]
Пример #7
0
def test_search_factory_only_with_aggs_without_query(inspire_app):
    mock_filter = MagicMock()
    mock_post_filter = MagicMock()
    facets = {
        "aggs": {
            "type": {
                "terms": {
                    "field": "value"
                }
            }
        },
        "filters": {
            "type": mock_filter("type")
        },
        "post_filters": {
            "type": mock_post_filter("type")
        },
    }
    config = {"RECORDS_REST_FACETS": {"*": facets}}
    with override_config(**config), current_app.test_request_context(""):
        search = InspireSearch()
        search, urlkwargs = search_factory_only_with_aggs(None, search)
        search_to_dict = search.to_dict()

        assert "aggs" in search_to_dict
        assert "filter" not in search_to_dict
        assert "post_filter" not in search_to_dict
Пример #8
0
 def test_push_new_work_happy_flow(self):
     with override_config(
             FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
             FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
     ):
         orcid_push(self.orcid, self.recid, self.oauth_token)
     assert not self.cache.has_work_content_changed(self.inspire_record)
Пример #9
0
def test_search_links_with_fields_filtering(inspire_app):
    expected_links_test = {
        "self": "http://localhost:5000/api/test/?q=&size=10&page=1&fields=ids,authors",
        "next": "http://localhost:5000/api/test/?q=&size=10&page=2&fields=ids,authors",
        "format1": "http://localhost:5000/api/test/?q=&size=10&page=1&format=format1",
        "json": "http://localhost:5000/api/test/?q=&size=10&page=1&fields=ids,authors&format=json",
    }
    config = {
        "TEST": {
            "search_serializers_aliases": {
                "format1": "format/1",
                "json": "application/json",
            }
        }
    }
    with override_config(**config):
        links_test = {
            "self": "http://localhost:5000/api/test/?q=&size=10&page=1",
            "next": "http://localhost:5000/api/test/?q=&size=10&page=2",
        }
        with mock.patch("inspirehep.records.links.request") as mock_request:
            mock_request.path = "/test"
            mock_request.values = MultiDict([("fields", "ids,authors")])
            links_test = inspire_search_links(links_test)
    assert links_test == expected_links_test
Пример #10
0
def test_facet_configuration_with_existing_facet_dict(inspire_app):
    config = {
        "RECORDS_REST_FACETS": {
            "defenders": {
                "aggs": {
                    "jessica-jones": {
                        "terms": {
                            "field": "defenders",
                            "size": 20
                        }
                    }
                }
            }
        }
    }
    expected = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    with current_app.test_request_context("?facet_name=defenders"):
        with override_config(**config):
            result = get_facet_configuration("records-hep")
            assert expected == result
Пример #11
0
def test_minter_bai_provided(inspire_app):
    data = {
        "ids": [
            {
                "schema": "JACOW",
                "value": "JACoW-12345678"
            },
            {
                "schema": "INSPIRE BAI",
                "value": "K.Janeway.1"
            },
        ]
    }
    expected_pids_len = 1
    epxected_pids_values = [data["ids"][1]["value"]]
    expected_pids_provider = "bai"
    expected_pids_status = PIDStatus.REGISTERED
    with override_config(FEATURE_FLAG_ENABLE_BAI_PROVIDER=True):
        record = create_record("aut", data=data)
    result_pids = (PersistentIdentifier.query.filter_by(
        object_uuid=record.id).filter_by(pid_type="bai").all())
    result_pids_len = len(result_pids)

    assert expected_pids_len == result_pids_len

    pid = result_pids[0]
    assert expected_pids_provider == pid.pid_provider
    assert expected_pids_status == pid.status
    assert pid.pid_value in epxected_pids_values
Пример #12
0
def test_hep_collection_aggregation(inspire_app):
    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"]
        )
Пример #13
0
def test_seminar_series_aggregation_and_filter(inspire_app):
    config = {
        "RECORDS_REST_FACETS": {
            "records-seminars": {
                "filters": {**current_app.config["SEMINARS_FILTERS"]},
                "aggs": {**seminar_series_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"series": [{"name": "Series1"}]}
        expected_record = create_record("sem", data)
        data = {"series": [{"name": "ICHEP"}]}
        create_record("sem", data)
        with inspire_app.test_client() as client:
            response = client.get("/seminars/facets").json
        expected_aggregation = {
            "meta": {"title": "Series", "type": "checkbox", "order": 1},
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {"key": "ICHEP", "doc_count": 1},
                {"key": "Series1", "doc_count": 1},
            ],
        }
        assert response["aggregations"]["series"] == expected_aggregation

        with inspire_app.test_client() as client:
            response = client.get("/seminars?series=Series1").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Пример #14
0
def test_hep_earliest_date_aggregation_and_filter(inspire_app):
    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"]
        )
Пример #15
0
def test_conf_subject_aggregation_and_filter(inspire_app):
    config = {
        "RECORDS_REST_FACETS": {
            "records-conferences": {
                "filters": {**current_app.config["CONFERENCES_FILTERS"]},
                "aggs": {**conf_subject_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"inspire_categories": [{"term": "Lattice"}]}
        expected_record = create_record("con", data)
        data = {"inspire_categories": [{"term": "Instrumentation"}]}
        create_record("con", data)
        with inspire_app.test_client() as client:
            response = client.get("/conferences/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("/conferences?subject=lattice").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Пример #16
0
def test_jobs_region_aggregation_and_filter(inspire_app):
    config = {
        "RECORDS_REST_FACETS": {
            "records-jobs": {
                "filters": {**current_app.config["JOBS_FILTERS"]},
                "aggs": {**jobs_region_aggregation(1)},
            }
        }
    }

    with override_config(**config):
        data = {"regions": ["Europe"], "status": "open"}
        expected_record = create_record("job", data)
        data = {"regions": ["North America"], "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": "Region", "order": 1},
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {"doc_count": 1, "key": "Europe"},
                {"doc_count": 1, "key": "North America"},
            ],
        }
        assert response["aggregations"]["region"] == expected_aggregation

        response = client.get("/jobs?region=Europe").json
        assert len(response["hits"]["hits"]) == 1
        assert (
            response["hits"]["hits"][0]["metadata"]["control_number"]
            == expected_record["control_number"]
        )
Пример #17
0
def test_jobs_field_of_interest_aggregation_and_filter(inspire_app):
    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"]
        )
Пример #18
0
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"]
        )
Пример #19
0
def test_minter_creates_record_with_texkey_provided_and_new_one_when_metadata_requires_it(
        inspire_app):
    data = {
        "authors": [{
            "full_name": "Janeway, K."
        }],
        "publication_info": [{
            "year": 2000
        }],
        "texkeys": ["Janeway:1999abc", "Janewaj:2000def"],
    }

    expected_existing_texkeys = ["Janeway:1999abc", "Janewaj:2000def"]
    expected_new_texkey = "Janeway:2000"
    expected_texkeys_count = 3
    with override_config(FEATURE_FLAG_ENABLE_TEXKEY_MINTER=True):
        record = create_record("lit", data=data)

    assert len(record["texkeys"]) == expected_texkeys_count

    pids_from_pidstore = (PersistentIdentifier.query.filter(
        PersistentIdentifier.object_uuid == record.id).filter(
            PersistentIdentifier.pid_type == "texkey").all())

    assert len(pids_from_pidstore) == expected_texkeys_count
    assert record["texkeys"][0].startswith(expected_new_texkey)
    assert record["texkeys"][1] in expected_existing_texkeys
    assert record["texkeys"][2] in expected_existing_texkeys

    all_expected_texkeys = record["texkeys"]

    assert pids_from_pidstore[0].pid_value in all_expected_texkeys
    assert pids_from_pidstore[1].pid_value in all_expected_texkeys
    assert pids_from_pidstore[2].pid_value in all_expected_texkeys
Пример #20
0
def test_inspire_filter_factory(inspire_app):
    index_name = "test_facet_aggs"
    mock_filter = MagicMock()
    mock_filter_wrapper = MagicMock()
    mock_filter_wrapper.return_value = mock_filter

    mock_post_filter = MagicMock()
    mock_post_filter_wrapper = MagicMock()
    mock_post_filter_wrapper.return_value = mock_post_filter

    facets_filter = {
        "filters": {
            "type": mock_filter("type")
        },
        "post_filters": {
            "type": mock_post_filter("type")
        },
    }
    config = {"RECORDS_REST_FACETS": {index_name: facets_filter}}

    with override_config(**config):
        with current_app.test_request_context("?type=FOO&q=BAR"):

            search = Search()
            search, urlwargs = inspire_filter_factory(search, index_name)

            mock_filter.assert_called_once()
            mock_post_filter.assert_called_once()
 def test_delete_work_cache_miss(self):
     pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                        self.oauth_token)
     # ORCID_APP_CREDENTIALS is required because ORCID adds it as source_client_id_path.
     with override_config(
             ORCID_APP_CREDENTIALS={"consumer_key": "0000-0001-8607-8906"}):
         assert not pusher.push()
Пример #22
0
def test_view_disambiguate(disambiguate_signatures_mock, inspire_app):
    token = create_user_and_token()
    headers = {"Authorization": "BEARER " + token.access_token}
    clusters = [{
        "signatures": [{
            "publication_id":
            374836,
            "signature_uuid":
            "94fc2b0a-dc17-42c2-bae3-ca0024079e51",
        }],
        "authors": [{
            "author_id": 100,
            "has_claims": True
        }],
    }]
    config = {"FEATURE_FLAG_ENABLE_DISAMBIGUATION": True}
    with override_config(**config), inspire_app.test_client() as client:
        response = client.post(
            "/disambiguation",
            content_type="application/json",
            data=json.dumps({"clusters": clusters}),
            headers=headers,
        )
    expected_message = "Disambiguation started."
    expected_status_code = 200

    result_message = response.json["message"]
    result_status_code = response.status_code

    assert expected_status_code == result_status_code
    assert expected_message == result_message
    disambiguate_signatures_mock.apply_async.assert_called_with(
        queue="disambiguation", kwargs={"clusters": clusters})
Пример #23
0
def test_detail_links_factory_generates_proper_additional_links(inspire_app):
    expected_links = {
        "format4": "http://localhost:5000/literature/1?format=format4",
        "format5": "http://localhost:5000/literature/1?format=format5",
        "citations": "http://localhost:5000/literature/1/citations",
    }

    config = {
        "JOBS": {
            "record_serializers_aliases": {
                "format1": "format/1",
                "format2": "format/2",
                "format3": "format/3",
            }
        },
        "LITERATURE": {
            "record_serializers_aliases": {"format4": "format/4", "format5": "format/5"}
        },
        "ADDITIONAL_LINKS": {
            "LITERATURE": {"citations": "inspirehep_records.literature_citations"}
        },
    }
    with override_config(**config):
        pid = PersistentIdentifier(pid_type="lit", pid_value=1)
        links = inspire_detail_links_factory(pid)
    assert links == expected_links
Пример #24
0
def test_generate_multiple_sitemap_files_with_multiple_collection(
        mocked_open, inspire_app, cli):
    create_record("lit")
    create_record("con")
    create_record("job", data={"status": "open"})
    create_record("job", data={"status": "closed"})  # excluded
    create_record("job", data={"status": "pending"})  # excluded
    create_record("aut")
    create_record("sem")
    create_record("exp")  # excluded

    config = {"SITEMAP_FILES_PATH": "/tmp", "SITEMAP_PAGE_SIZE": 1}
    with override_config(**config):
        result = cli.invoke(["sitemap", "generate"])

        assert result.exit_code == 0

        mocked_open.assert_any_call("/tmp/sitemap1.xml", "w+")
        mocked_open.assert_any_call("/tmp/sitemap2.xml", "w+")
        mocked_open.assert_any_call("/tmp/sitemap3.xml", "w+")
        mocked_open.assert_any_call("/tmp/sitemap4.xml", "w+")
        mocked_open.assert_any_call("/tmp/sitemap5.xml", "w+")
        mocked_open.assert_any_call("/tmp/sitemap.xml", "w+")

        # make sure no more file is added for experiment and not open jobs
        assert mocked_open.call_count == 6
Пример #25
0
def test_generate_inspire_search_links_gets_proper_formats(inspire_app):
    expected_links_test2 = {
        "self": "http://localhost:5000/api/test2/?q=&size=10&page=1",
        "format4": "http://localhost:5000/api/test2/?q=&size=10&page=1&format=format4",
        "format5": "http://localhost:5000/api/test2/?q=&size=10&page=1&format=format5",
    }
    expected_links_test = {
        "self": "http://localhost:5000/api/test/?q=&size=10&page=1",
        "format1": "http://localhost:5000/api/test/?q=&size=10&page=1&format=format1",
        "format2": "http://localhost:5000/api/test/?q=&size=10&page=1&format=format2",
        "format3": "http://localhost:5000/api/test/?q=&size=10&page=1&format=format3",
    }
    config = {
        "TEST": {
            "search_serializers_aliases": {
                "format1": "format/1",
                "format2": "format/2",
                "format3": "format/3",
            }
        },
        "TEST2": {
            "search_serializers_aliases": {"format4": "format/4", "format5": "format/5"}
        },
    }
    with override_config(**config):
        links_test = {"self": "http://localhost:5000/api/test/?q=&size=10&page=1"}
        links_test2 = {"self": "http://localhost:5000/api/test2/?q=&size=10&page=1"}
        with mock.patch("inspirehep.records.links.request") as mock_request:
            mock_request.values = MultiDict()
            mock_request.path = "/test"
            links_test = inspire_search_links(links_test)
            mock_request.path = "/test2"
            links_test2 = inspire_search_links(links_test2)
    assert links_test == expected_links_test
    assert links_test2 == expected_links_test2
Пример #26
0
def test_detail_links_factory_generates_proper_links(inspire_app):
    expected_links = {
        "format1": "http://localhost:5000/jobs/1?format=format1",
        "format2": "http://localhost:5000/jobs/1?format=format2",
        "format3": "http://localhost:5000/jobs/1?format=format3",
    }

    config = {
        "JOBS": {
            "record_serializers_aliases": {
                "format1": "format/1",
                "format2": "format/2",
                "format3": "format/3",
            }
        },
        "LITERATURE": {
            "record_serializers_aliases": {
                "format4": "format/4",
                "format5": "format/5"
            }
        },
    }
    with override_config(**config):
        pid = PersistentIdentifier(pid_type="job", pid_value=1)
        links = inspire_detail_links_factory(pid)
    assert links == expected_links
Пример #27
0
def test_search_factory_only_with_aggs(inspire_app):
    mock_filter = MagicMock()
    mock_post_filter = MagicMock()
    facets = {
        "aggs": {
            "type": {
                "terms": {
                    "field": "value"
                }
            }
        },
        "filters": {
            "type": mock_filter("type")
        },
        "post_filters": {
            "type": mock_post_filter("type")
        },
    }
    config = {"RECORDS_REST_FACETS": {"*": facets}}
    with override_config(
            **config), current_app.test_request_context("?q=foo&type=bar"):
        search = InspireSearch()
        search, urlkwargs = search_factory_only_with_aggs(None, search)
        search_to_dict = search.to_dict()
        search_to_dict_filters = search_to_dict["query"]["bool"]
        urlkwargs_to_dict = urlkwargs.to_dict()

        expected_urlkwargs = {"q": "foo", "type": "bar"}

        assert expected_urlkwargs == urlkwargs_to_dict
        assert "aggs" in search_to_dict
        assert "filter" in search_to_dict_filters
        assert "post_filter" in search_to_dict
Пример #28
0
    def test_happy_flow_put(self):
        with override_config(
                FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX=".*",
                ORCID_APP_CREDENTIALS={"consumer_key": "0000-0001-8607-8906"},
        ):
            dois = self.factory.record_metadata.json.pop("dois")

            pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                               self.oauth_token)
            self.putcode = pusher.push()

            self.factory.record_metadata.json["dois"] = dois
            self.factory_clashing.record_metadata.json["deleted"] = True

            with pytest.raises(
                    exceptions.DuplicatedExternalIdentifierPusherException):
                tasks.orcid_push.apply(
                    queue="orcid_push_legacy_tokens",
                    kwargs={
                        "orcid": self.orcid,
                        "rec_id": self.recid,
                        "oauth_token": self.oauth_token,
                    },
                    throw=True,
                )

            pusher = domain_models.OrcidPusher(self.orcid, self.recid,
                                               self.oauth_token)
            result_putcode = pusher.push()

            assert result_putcode == self.putcode
            assert not self.cache.has_work_content_changed(self.inspire_record)
Пример #29
0
def test_query_parser_should_return_404_when_endpoint_is_disabled(inspire_app):
    with override_config(FEATURE_FLAG_ENABLE_QUERY_PARSER_ENDPOINT=False
                         ), inspire_app.test_client() as client:
        response = client.get(f"/search/query-parser",
                              content_type="application/json")

        assert response.status_code == 404
Пример #30
0
def test_hep_author_aggregation_and_filter(inspire_app):
    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"]
        )