test_11_CheckAndFix_base.py 5.97 KB
Newer Older
LE GAC Renaud's avatar
LE GAC Renaud committed
1
"""test_11_CheckAndFix_base
2 3 4 5 6 7 8 9 10 11 12 13 14

    * Test CheckAndFix methods required by the Automaton base class.
        - constructor
        - is_bad_aoi
        - temporary_record
        - authors
        - my_affiliation
        - collaboration

"""
import pytest
import requests

LE GAC Renaud's avatar
LE GAC Renaud committed
15 16
from gluon import current
from harvest_tools.base import search_synonym
17
from harvest_tools.checkandfix import CheckAndFix, CheckException
18
from store_tools import load_record
19 20 21 22 23 24 25


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


26 27 28 29 30
@pytest.fixture(scope="module")
def recins():
    return load_record("inspirehep.net", 1319638, shelf="literature")


31 32 33 34 35
@pytest.fixture(scope="module")
def svc():
    return CheckAndFix()


LE GAC Renaud's avatar
LE GAC Renaud committed
36
def test_constructor_11001(svc):
37
    assert svc.reg_institute == \
38 39
        r"(^|\|)Marseille, CPPM($|\|)|" \
        r"(^|\|)CPPM, Marseille($|\|)|" \
40 41
        r"(^|\|)Centre de Physique des Particules de Marseille \(CPPM\)($|\|)|" \
        r"(^|\|)Aix Marseille Univ, CNRS/IN2P3, CPPM, Marseille, France($|\|)"
42 43


44 45 46 47 48
# ............................................................................
#
# cds.cern.ch record
#
def test_is_oai_cds_11010(svc, reccds):
49
    assert svc.is_oai(reccds)
50 51


52
def test_is_bad_oai_cds_11011(svc, reccds):
53 54 55
    assert not svc.is_bad_oai_used(reccds)


56
def test_temporary_record_cds_11012(svc, reccds):
57 58 59 60 61 62 63 64

    assert svc.temporary_record(reccds) is None

    # look for some temporarily record in inspirehep.net
    # using the MarcXML syntax
    # get a list of recids
    payload = {"p": "500__a:'*Temporary record*'", "of": "id", "rg": 10}

LE GAC Renaud's avatar
LE GAC Renaud committed
65
    r = requests.get("https://old.inspirehep.net/search", params=payload)
66 67 68 69 70 71 72 73
    li = r.json()

    # try with the oldest one to avoid issue with missing information, etc.
    with pytest.raises(CheckException):
        recins = load_record("inspirehep.net", li[-1])
        svc.temporary_record(recins)


74
def test_authors_cds_11013(svc, reccds):
75 76 77
    assert svc.authors(reccds) is None


78
def test__get_author_rescue_list_cds_11014(svc, reccds):
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    assert svc._get_author_rescue_list(reccds, 8, 7) == ["C. Adrover",
                                                         "S. Akar",
                                                         "E. Aslanides",
                                                         "J. Cogan",
                                                         "W. Kanso",
                                                         "R. Le Gac",
                                                         "O. Leroy",
                                                         "G. Mancinelli",
                                                         "E. Maurice",
                                                         "A. Morda",
                                                         "A. Mordà",
                                                         "M. Perrin-Terrin",
                                                         "M. Sapunov",
                                                         "J. Serrano",
                                                         "A. Tsaregorodtsev"]


96
def test_my_affiliation_cds_11015(svc, reccds):
97 98 99 100 101 102 103 104
    assert svc.my_affiliation(reccds, 8, 7) == "Marseille, CPPM"

    # a paper from NA62 -- no CPPM author
    recna62 = load_record("cds.cern.ch", 1434415)
    with pytest.raises(CheckException):
        svc.my_affiliation(recna62, id_project=8, id_team=7)


105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
def test_collaboration_cds_11016(svc, reccds):
    assert svc.collaboration(reccds) is None


# ............................................................................
#
# inspirehep.net record (March 2020 onward)
#
def test_is_oai_ins_11020(svc, recins):
    assert svc.is_oai(recins)


def test_is_bad_oai_ins_11021(svc, recins):
    assert not svc.is_bad_oai_used(recins)


def test_authors_ins_11023(svc, recins):
    assert svc.authors(recins) is None


def test__get_author_rescue_list_ins_11024(svc, recins):
    assert svc._get_author_rescue_list(recins, 8, 7) == ["C. Adrover",
                                                         "S. Akar",
                                                         "E. Aslanides",
                                                         "J. Cogan",
                                                         "W. Kanso",
                                                         "R. Le Gac",
                                                         "O. Leroy",
                                                         "G. Mancinelli",
                                                         "E. Maurice",
                                                         "A. Morda",
                                                         "A. Mordà",
                                                         "M. Perrin-Terrin",
                                                         "M. Sapunov",
                                                         "J. Serrano",
                                                         "A. Tsaregorodtsev"]


def test_my_affiliation_ins_11025(svc, recins):
    assert svc.my_affiliation(recins, 8, 7) == "Marseille, CPPM"

    # a paper from NA62 -- no CPPM author
    recna62 = load_record("cds.cern.ch", 1434415)
    with pytest.raises(CheckException):
        svc.my_affiliation(recna62, id_project=8, id_team=7)


def test_collaboration_ins_11026(svc, recins):
    assert svc.collaboration(recins) is None


# ............................................................................
#
# others
#
def test_search_synonym_11030():
LE GAC Renaud's avatar
LE GAC Renaud committed
161 162 163
    db = current.db

    # collaboration ANTARES, TANAMI (defined as synonym in the db)
164
    record = load_record("inspirehep.net", 1342250, shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
165 166 167 168 169 170 171 172 173

    colid = search_synonym(
        db.collaborations,
        "collaboration",
        record.collaboration())

    assert colid == 2

    # collaboration = ANTARES (defined as synonym in the db))
174
    record = load_record("inspirehep.net", 718872, shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
175 176 177 178 179 180 181 182

    colid = search_synonym(
        db.collaborations,
        "collaboration",
        record.collaboration())

    assert colid == 2