test_08_CheckAndFix_base.py 2.91 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
# -*- coding: utf-8 -*-
"""test_08_CheckAndFix_base

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

"""
import pytest
import requests

from harvest_tools.checkandfix import CheckAndFix, CheckException
from invenio_tools import load_record


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


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


def test_constructor(svc):
    assert svc.reg_institute == \
        "^Marseille, CPPM|"\
        "^CPPM, Marseille|"\
        "^Centre de Physique des Particules de Marseille \(CPPM\)"


def test_is_bad_oai(svc, reccds):
    assert not svc.is_bad_oai_used(reccds)


def test_temporary_record(svc, reccds):

    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}

    r = requests.get("http://inspirehep.net/search", params=payload)
    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)


def test_authors(svc, reccds):
    assert svc.authors(reccds) is None


def test__get_author_rescue_list(svc, reccds):
    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"]


def test_my_affiliation(svc, reccds):
    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)


def test_collaboration(svc, reccds):
    assert svc.collaboration(reccds) is None