test_10_CheckAndFix_article.py 3.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
# -*- coding: utf-8 -*-
"""test_10_CheckAndFix_article

    * Test CheckAndFix methods for article:
        - format_editor
        - publisher
        - paper_reference
        - submitted
        - format_author
        - get_my_authors

    * Same article in cds.cern.ch and inspirehep.net
      Phys. Rev. D 95 (2017) 052005

"""
import pytest
from harvest_tools.checkandfix import CheckAndFix
from invenio_tools import load_record


@pytest.fixture(scope="module")
def reccds():
    return load_record("cds.cern.ch", 2242641)


@pytest.fixture(scope="module")
def recins():
    return load_record("inspirehep.net", 1509922)


@pytest.fixture(scope="module")
def svc():
    return CheckAndFix()


def test_format_editor(svc, reccds, recins):

    # cds
    assert reccds.paper_editor() == "Phys. Rev. D"
    assert reccds.paper_volume() == "95"

    svc.format_editor(reccds)

    assert reccds.paper_editor() == "Phys. Rev. D"
    assert reccds.paper_volume() == "95"

    # inspire
    assert recins.paper_editor() == "Phys.Rev."
    assert recins.paper_volume() == "D95"

    svc.format_editor(recins)

    assert recins.paper_editor() == "Phys. Rev. D"
    assert recins.paper_volume() == "95"


def test_publisher(svc, reccds):
    assert svc.publisher(reccds) is None


def test_paper_reference(svc, reccds):

    # check recovery procedure using DOI
    # remove the publisher and volume information
    paper_ref = reccds.paper_reference()

    reccds["publication_info"].loc[0, ["title", "volume"]] = ["", ""]
    svc.paper_reference(reccds)

    assert reccds.paper_reference() == paper_ref


def test_submitted(svc, reccds, recins):

    assert recins.submitted() == "2017-01-19"

77
    assert reccds.submitted() == "19 Jan 2017"
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    svc.submitted(reccds)
    assert reccds.submitted() == "2017-01-19"

    # test the case 19 01 2017
    reccds[u"prepublication"][u"date"] = "19 01 2017"
    svc.submitted(reccds)
    assert reccds.submitted() == "2017-01-19"

    # test the case 2017
    reccds[u"prepublication"][u"date"] = "2017"
    svc.submitted(reccds)
    assert reccds.submitted() == "2017-01"


def test_format_authors(svc, reccds):

    authors = reccds.authors_as_list()

    assert len(authors) == reccds["number_of_authors"]
    assert authors[0] == u"Aaij, Roel"
    assert authors[1] == u"Adeva, Bernardo"
    assert authors[344] == u"Koopman, Rose"
    assert authors[-1] == u"Zucchelli, Stefano"

    svc.format_authors(reccds, fmt="F. Last")
    authors = reccds.authors_as_list()

    assert authors[0] == u"R. Aaij"
    assert authors[1] == u"B. Adeva"
    assert authors[344] == u"R. Koopman"
    assert authors[-1] == u"S. Zucchelli"


def test_get_my_authors(svc, reccds):

    svc.format_authors(reccds, fmt="F. Last")
    assert svc.get_my_authors(reccds, sep=u"|", sort=True) is None

    my_authors = reccds.my_authors.encode("utf-8")

    assert my_authors == "J. Arnau Romeu|E. Aslanides|J. Cogan|" \
                         "K. De Bruyn|R. Le Gac|O. Leroy|" \
                         "G. Mancinelli|M. Martin|A. Mordà|" \
                         "J. Serrano|A. Tayduganov|A. Tsaregorodtsev"