test_01_store.py 3.26 KB
Newer Older
1 2
"""test_inveniostore

3 4
Test methods of the class InveniStore

5
"""
6 7
import pytest

8
from store_tools.exception import CdsException
9
from store_tools.factory import build_store
10 11


12
def test_build_store_exception_01001():
13
    with pytest.raises(CdsException):
14
        build_store("inspirehep", shelf="foo")
15 16 17


def test_get_ids_cds_01002():
18 19 20
    """Check the list of record ids for LHCb articles published in 2015.

    """
21
    store = build_store("cds.cern.ch")
22 23 24 25 26 27 28 29 30 31 32

    kwargs = {
        "f1": "year",
        "p1": "2015",
        "cc": "LHCb Papers",
        "m1": "r",
        "so": "d",
        "sf": "year"}

    rec_ids = store.get_ids(**kwargs)

LE GAC Renaud's avatar
LE GAC Renaud committed
33
    ref_2020_ids = {
34 35 36
        1750838, 1755550, 1951383, 1951424, 1955544, 1966993, 1967222,
        1967422, 1968989, 1969197, 1970675, 1970690, 1972201, 1975522,
        1975714, 1978281, 1978798, 1981106, 1983198, 1987883, 1996441,
LE GAC Renaud's avatar
LE GAC Renaud committed
37
        2000543, 2002385, 2003252, 2003792, 2003793, 2003794, 2004586,
38 39 40 41
        2004591, 2005510, 2007377, 2011387, 2012165, 2012990, 2014715,
        2014733, 2014836, 2016239, 2016711, 2019534, 2019536, 2020686,
        2021262, 2029609, 2029820, 2030417, 2033887, 2033891, 2038937,
        2040342, 2045144, 2047219, 2048426, 2048427, 2048812, 2049870,
LE GAC Renaud's avatar
LE GAC Renaud committed
42
        2055598, 2057916, 2059561, 2060452}
43

LE GAC Renaud's avatar
LE GAC Renaud committed
44
    assert set(rec_ids).difference(ref_2020_ids) == set()
LE GAC Renaud's avatar
LE GAC Renaud committed
45 46


47
def test_get_ids_ins_01003():
LE GAC Renaud's avatar
LE GAC Renaud committed
48 49 50
    """Check the list of record ids for LHCb articles published in 2010.

    """
LE GAC Renaud's avatar
LE GAC Renaud committed
51
    store = build_store("inspirehep.net", shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
52

LE GAC Renaud's avatar
LE GAC Renaud committed
53
    ids = store.get_ids(q="find cn lhcb and tc p and not tc c and date 2010")
LE GAC Renaud's avatar
LE GAC Renaud committed
54
    ref_2019_ids = {865584, 867355, 867647}
LE GAC Renaud's avatar
LE GAC Renaud committed
55

LE GAC Renaud's avatar
LE GAC Renaud committed
56
    assert set(ids) == ref_2019_ids
57 58 59


def test_get_ids_exception_01004():
60
    store = build_store("inspirehep.net", shelf="conferences")
LE GAC Renaud's avatar
LE GAC Renaud committed
61
    assert store.get_ids(q="find cn lhcb") == []
62 63 64


def test_get_record_cds_01005():
65
    store = build_store("cds.cern.ch")
66 67 68 69 70 71
    recjson = store.get_record(1951625)
    assert isinstance(recjson, dict)


def test_get_record_ins_none_01006():
    # old inspirehep interface
72
    store = build_store("inspirehep.net", shelf=None)
73 74 75 76 77 78
    recjson = store.get_record(1319638)
    assert isinstance(recjson, dict)


def test_get_record_ins_literature_01007():
    # old inspirehep interface (new one not yet available)
79
    store = build_store("inspirehep.net", shelf="literature")
80 81 82 83 84 85
    recjson = store.get_record(1319638)
    assert isinstance(recjson, dict)


def test_get_record_ins_conferences_01008():
    # new inspirehep interface for conferences
86
    store = build_store("inspirehep.net", shelf="conferences")
87
    recjson = store.get_record(980401)
LE GAC Renaud's avatar
LE GAC Renaud committed
88
    assert recjson["cnum"] == "C10-12-06"
89 90 91 92


def test_get_record_ins_institutions_01009():
    # old inspirehep interface (new one not yet available)
93
    store = build_store("inspirehep.net", shelf="institutions")
94 95 96 97
    recjson = store.get_record(902989)
    assert isinstance(recjson, dict)


98
def test_get_field_ins_01010():
99
    store = build_store("inspirehep.net", shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
100 101
    value = store.get_field(1319638, "citation_count")
    assert isinstance(value, int)
102 103 104 105


def test_search_ins_01011():
    # new inspirehep interface for conferences
106
    store = build_store("inspirehep.net", shelf="conferences")
LE GAC Renaud's avatar
LE GAC Renaud committed
107
    obj = store.search(q="cnum:C10-12-06")
108
    assert len(obj) == 1 and obj[0]["metadata"]["cnum"] == "C10-12-06"