def test_import_article_doi_already_in_inspire(base_app, db, es):
    doi_value = faker.doi()
    data = {"dois": [{"value": doi_value}]}
    data = faker.record("lit", with_control_number=True, data=data)
    LiteratureRecord.create(data)

    with pytest.raises(ExistingArticleError):
        import_article(doi_value)
def test_import_article_arxiv_id_already_in_inspire(base_app, db, es):
    arxiv_value = faker.arxiv()
    data = {"arxiv_eprints": [{"value": arxiv_value}]}
    data = faker.record("lit", with_control_number=True, data=data)
    LiteratureRecord.create(data)

    with pytest.raises(ExistingArticleError):
        import_article(f"arXiv:{arxiv_value}")
Example #3
0
def import_article_view(identifier):
    try:
        article = import_article(identifier)
        return jsonify({"data": literature_v1.dump(article)})

    except ExistingArticleError as e:
        message, recid = e.args
        return jsonify(message=str(message), recid=str(recid)), 409

    except ImportArticleNotFoundError as e:
        LOGGER.exception("Exception in import_article_view", exception=e)
        return jsonify(message=str(e)), 404

    except ImportParsingError as e:
        LOGGER.exception("Exception in import_article_view", exception=e)
        return jsonify(message="The article has an invalid format."), 500

    except UnknownImportIdentifierError:
        return jsonify(
            message=f"{identifier} is not a recognized identifier."), 400

    except RequestException as e:
        LOGGER.exception("Exception in import_article_view", exception=e)
        return (
            jsonify(
                message=
                "There was an error when importing metadata. Please try again later or fill the form manually."
            ),
            502,
        )
Example #4
0
def import_article_view(identifier):
    try:
        article = import_article(identifier)
        return jsonify({"data": literature_v1.dump(article)})

    except ExistingArticleError as e:
        return jsonify(message=str(e)), 409

    except ImportArticleError as e:
        return jsonify(message=str(e)), 404

    except ImportConnectionError as e:
        return jsonify(message=str(e)), 502

    except ImportParsingError as e:
        return jsonify(message=f"The article has an invalid format.\n{e}"), 500

    except UnknownImportIdentifierError:
        return jsonify(
            message=f"{identifier} is not a recognized identifier."), 400
def test_import_article_bad_doi(base_app):
    with pytest.raises(UnknownImportIdentifierError):
        import_article("doi:Th1s1s/n0taD01")
def test_import_article_bad_arxiv_id(base_app):
    with pytest.raises(UnknownImportIdentifierError):
        import_article("bad_arXiv:1207.7214")