예제 #1
0
def test_migrate_record_from_mirror_invalidates_local_file_cache_if_no_local_file(
    inspire_app, s3, redis, datadir
):
    expected_key = "f43f40833edfd8227c4deb9ad05b321e"
    create_s3_bucket(expected_key)
    with patch.dict(
        current_app.config, {"LABS_AFS_HTTP_SERVICE": "http://inspire-afs-web.cern.ch/"}
    ):
        redis.delete("afs_file_locations")
        # populate cache with invalid file path
        redis.hset(
            "afs_file_locations",
            "http://inspire-afs-web.cern.ch/var/data/files/g97/1940001/content.pdf%3B2",
            "/api/files/ddb1a354-1d2a-40b6-9cc4-2e823b6bef81/0000000000000000000000000000000000000000",
        )
        raw_record_path = (datadir / "1313624.xml").as_posix()

        migrate_from_file(raw_record_path)
        record = LiteratureRecord.get_record_by_pid_value("1313624")

        assert redis.hlen("afs_file_locations") > 0
        assert (
            record["documents"][0]["original_url"]
            == "http://inspire-afs-web.cern.ch/var/data/files/g97/1940001/content.pdf%3B2"
        )
예제 #2
0
def test_orcid_push_disabled_on_migrate_from_mirror(
    inspire_app, enable_orcid_push_feature
):
    record_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "dummy.xml")
    )

    with patch(
        "inspirehep.orcid.domain_models.OrcidPusher"
    ) as mock_orcid_pusher, patch(
        "inspirehep.orcid.push_access_tokens"
    ) as mock_push_access_tokens:
        mock_push_access_tokens.get_access_tokens.return_value.remote_account.extra_data[
            "orcid"
        ] = "0000-0002-1825-0097"
        mock_push_access_tokens.get_access_tokens.return_value.access_token = "mytoken"

        migrate_from_file(record_fixture_path)
        mock_orcid_pusher.assert_not_called()

    prod_record = LegacyRecordsMirror.query.filter(
        LegacyRecordsMirror.recid == 12345
    ).one()
    assert prod_record.valid

    assert current_app.config["FEATURE_FLAG_ENABLE_ORCID_PUSH"]
예제 #3
0
def test_migrate_from_mirror_doesnt_raise_on_job_records(inspire_app):
    record_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "1695012.xml"))
    migrate_from_file(record_fixture_path)
    job_rec = LegacyRecordsMirror.query.filter(
        LegacyRecordsMirror.recid == 1695012).one()

    assert job_rec.valid
예제 #4
0
def test_migrate_record_from_mirror_with_download_file_error_not_caused_by_invalid_cache(
        inspire_app, s3, redis, datadir):
    with patch.dict(
            current_app.config,
        {"LABS_AFS_HTTP_SERVICE": "http://inspire-afs-web.cern.ch/"}):
        redis.delete("afs_file_locations")
        raw_record_path = (datadir / "1313624.xml").as_posix()
        with requests_mock.Mocker() as mocker:
            mocker.get(
                "http://inspire-afs-web.cern.ch/var/data/files/g97/1940001/content.pdf%3B2",
                status_code=404,
            )
            migrate_from_file(raw_record_path)
            record_mirror = LegacyRecordsMirror.query.filter(
                LegacyRecordsMirror.recid == 1313624).one()
            assert record_mirror.error.startswith("DownloadFileError")
예제 #5
0
def test_migrate_record_from_mirror_uses_local_cache_for_afs_files(
        inspire_app, s3, redis, datadir):
    expected_key = "f43f40833edfd8227c4deb9ad05b321e"
    create_s3_bucket(expected_key)
    with patch.dict(
            current_app.config,
        {"LABS_AFS_HTTP_SERVICE": "http://inspire-afs-web.cern.ch/"}):
        redis.delete("afs_file_locations")
        raw_record_path = (datadir / "1313624.xml").as_posix()

        migrate_from_file(raw_record_path)
        assert redis.hlen("afs_file_locations") > 0

        migrate_from_file(raw_record_path)
        record = LiteratureRecord.get_record_by_pid_value("1313624")
        # No original_url as source is local file
        assert "original_url" not in record["documents"][0]
예제 #6
0
def test_migrate_from_mirror_doesnt_index_deleted_records(inspire_app):
    record_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "dummy.xml"))
    record_fixture_path_deleted = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "deleted_record.xml"))
    migrate_from_file(record_fixture_path)
    migrate_from_file(record_fixture_path_deleted)
    current_search.flush_and_refresh("records-hep")

    expected_record_lit_es_len = 1

    record_lit_uuid = LiteratureRecord.get_uuid_from_pid_value(12345)
    record_lit_es = LiteratureSearch().get_record(
        str(record_lit_uuid)).execute().hits
    record_lit_es_len = len(record_lit_es)

    assert expected_record_lit_es_len == record_lit_es_len
예제 #7
0
def test_migrate_from_mirror_doesnt_index_deleted_records(
        base_app, db, es_clear):
    record_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "dummy.xml"))
    record_fixture_path_deleted = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "deleted_record.xml"))
    migrate_from_file(record_fixture_path)
    migrate_from_file(record_fixture_path_deleted)
    es_clear.indices.refresh("records-hep")

    expected_record_lit_es_len = 1

    record_lit_uuid = LiteratureRecord.get_uuid_from_pid_value(12345)
    with pytest.raises(PIDDoesNotExistError):
        LiteratureRecord.get_uuid_from_pid_value(1234)
    record_lit_es = LiteratureSearch().get_record(
        str(record_lit_uuid)).execute().hits
    record_lit_es_len = len(record_lit_es)

    assert expected_record_lit_es_len == record_lit_es_len
예제 #8
0
def test_migrate_from_mirror_removes_record_from_es(inspire_app, datadir):
    data = orjson.loads((datadir / "dummy_record.json").read_text())
    create_record("lit", data=data)

    expected_record_lit_es_len = 1
    record_lit_uuid = LiteratureRecord.get_uuid_from_pid_value(12345)
    record_lit_es = LiteratureSearch().get_record(str(record_lit_uuid)).execute().hits
    record_lit_es_len = len(record_lit_es)
    assert expected_record_lit_es_len == record_lit_es_len

    record_deleted_fixture_path = pkg_resources.resource_filename(
        __name__, os.path.join("fixtures", "dummy_deleted.xml")
    )
    migrate_from_file(record_deleted_fixture_path)
    current_search.flush_and_refresh("records-hep")

    expected_record_lit_es_len = 0
    record_lit_uuid = LiteratureRecord.get_uuid_from_pid_value(12345)
    record_lit_es = LiteratureSearch().get_record(str(record_lit_uuid)).execute().hits
    record_lit_es_len = len(record_lit_es)
    assert expected_record_lit_es_len == record_lit_es_len