test_02_record_factory.py 6.67 KB
Newer Older
1
"""test_02_record_factory
2

3 4
    * Test tools to introspect the type of record.
    * Test tools to upcast the Record from the JSON object.
5
    * Test tools to get / add conference data.
6 7

"""
8 9 10 11
from store_tools.base import (is_conference,
                              is_institute,
                              is_thesis)

12
from store_tools.factory import (add_conference_data,
13
                                 build_record,
14
                                 build_store,
15 16 17 18 19 20
                                 get_conference_data)

from store_tools.recordconf import RecordConf
from store_tools.recordinst import RecordInst
from store_tools.recordpubli import RecordPubli
from store_tools.recordthesis import RecordThesis
21 22


23 24
# ............................................................................
#
LE GAC Renaud's avatar
LE GAC Renaud committed
25
# Conference proceeding and talk
26
#
27 28
def test_get_conference_data_cds_02001():
    """get the conference data from cds.cern.ch.
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

    the map of identifiers and keys is the following:

        +------------------+--------------+-----------|
        |                  | cds          | inspire   |
        +------------------+--------------+-----------|
        | proceeding recid | 1411352      | 1089237   |
        | conference recid | 1181092      | 980401    |
        | conference key   | rome20101206 | C10-12-06 |
        +------------------+--------------+-----------|

    """
    # by id
    recjson1 = get_conference_data("cds.cern.ch", conf_id=1181092)
    assert recjson1["recid"] == 1181092
    assert recjson1["meeting_name"][0]["coference_code"] == "rome20101206"

    # by keys
    recjson2 = get_conference_data("cds.cern.ch", key="rome20101206")
    assert recjson2["recid"] == 1181092
    assert recjson2["meeting_name"][0]["coference_code"] == "rome20101206"

    assert recjson1 == recjson2


54 55 56 57 58 59 60 61 62 63 64 65 66 67
def test_get_conference_data_ins_02002():
    """get the conference data from inspirehep.net.

    the map of identifiers and keys is the following:

        +------------------+--------------+-----------|
        |                  | cds          | inspire   |
        +------------------+--------------+-----------|
        | proceeding recid | 1411352      | 1089237   |
        | conference recid | 1181092      | 980401    |
        | conference key   | rome20101206 | C10-12-06 |
        +------------------+--------------+-----------|

    """
68
    # by id
69 70 71
    recjson1 = get_conference_data("inspirehep.net", conf_id=980401)
    assert recjson1["control_number"] == 980401
    assert recjson1["cnum"] == "C10-12-06"
72 73

    # by key
74 75 76
    recjson2 = get_conference_data("inspirehep.net", key="C10-12-06")
    assert recjson2["control_number"] == 980401
    assert recjson2["cnum"] == "C10-12-06"
77 78


79
def test_add_conference_data_cds_02003():
80

81
    store = build_store("cds.cern.ch")
82 83 84 85
    recjson = store.get_record(1411352)

    add_conference_data(recjson)
    assert "meeting_name" in recjson
LE GAC Renaud's avatar
LE GAC Renaud committed
86
    assert "meeting_note" in recjson
87
    assert recjson["meeting_name"][0]["coference_code"] == "rome20101206"
LE GAC Renaud's avatar
LE GAC Renaud committed
88 89 90 91 92

    assert recjson["meeting_note"]["url"] == \
        "http://www.roma1.infn.it/discrete10"

    assert recjson["meeting_note"]["recid"] == 1181092
93

LE GAC Renaud's avatar
LE GAC Renaud committed
94

95
def test_add_conference_data_cds_02004():
LE GAC Renaud's avatar
LE GAC Renaud committed
96 97 98 99
    # ........................................................................
    #
    # EXCEPTION
    #
100
    store = build_store("cds.cern.ch")
LE GAC Renaud's avatar
LE GAC Renaud committed
101 102 103 104 105 106 107 108 109 110 111 112

    # no conference URL
    recjson = store.get_record(2258914)
    add_conference_data(recjson)
    assert recjson["meeting_note"]["url"] == ""

    # several conference URLs (home page, proceeding)
    recjson = store.get_record(2270940)
    add_conference_data(recjson)
    assert recjson["meeting_note"]["url"] == \
        "http://indico.ihep.ac.cn/event/5221/overview"

LE GAC Renaud's avatar
LE GAC Renaud committed
113

114 115
def test_add_conference_data_ins_02005():

116
    store = build_store("inspirehep.net", shelf="literature")
117 118 119 120 121 122 123 124 125 126 127 128 129 130
    recjson = store.get_record(1089237)

    add_conference_data(recjson)
    assert "meeting_name" in recjson
    assert "meeting_note" in recjson
    assert recjson["meeting_name"][0]["coference_code"] == "C10-12-06"

    assert recjson["meeting_note"]["url"] == \
        "http://www.roma1.infn.it/discrete10"

    assert recjson["meeting_note"]["recid"] == 980401


def test_conference_cds_02006():
LE GAC Renaud's avatar
LE GAC Renaud committed
131

132
    store = build_store("cds.cern.ch")
LE GAC Renaud's avatar
LE GAC Renaud committed
133 134 135 136 137 138 139 140 141 142
    recjson = store.get_record(1411352)

    assert is_conference(recjson)
    assert not is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordConf)


143
def test_conference_ins_02007():
LE GAC Renaud's avatar
LE GAC Renaud committed
144

145
    store = build_store("inspirehep.net", shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
146 147 148 149 150 151 152 153 154 155
    recjson = store.get_record(1276938)

    assert is_conference(recjson)
    assert not is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordConf)


156
def test_talk_cds_02008():
LE GAC Renaud's avatar
LE GAC Renaud committed
157

158
    store = build_store("cds.cern.ch")
LE GAC Renaud's avatar
LE GAC Renaud committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172
    recjson = store.get_record(2239092)

    assert is_conference(recjson)
    assert not is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordConf)

# ............................................................................
#
# Institute
#

173
# v1.4.0: remove 02009 testing obsolete add_affiliation_keys
LE GAC Renaud's avatar
LE GAC Renaud committed
174 175


176
def test_institute_ins_02010():
LE GAC Renaud's avatar
LE GAC Renaud committed
177
    """CPPM"""
178
    store = build_store("inspirehep.net", shelf="institutions")
LE GAC Renaud's avatar
LE GAC Renaud committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192
    recjson = store.get_record(902989)

    assert not is_conference(recjson)
    assert is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordInst)


# ............................................................................
#
# Article, ...
#
193
def test_article_cds_02011():
LE GAC Renaud's avatar
LE GAC Renaud committed
194 195
    """Precision luminosity measurements at LHCb"""

196
    store = build_store("cds.cern.ch")
LE GAC Renaud's avatar
LE GAC Renaud committed
197 198 199 200 201 202 203 204 205 206
    recjson = store.get_record(1951625)

    assert not is_conference(recjson)
    assert not is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordPubli)


207
def test_article_inspirehep_02012():
LE GAC Renaud's avatar
LE GAC Renaud committed
208 209
    """Precision luminosity measurements at LHCb"""

210
    store = build_store("inspirehep.net", shelf="literature")
LE GAC Renaud's avatar
LE GAC Renaud committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224
    recjson = store.get_record(1319638)

    assert not is_conference(recjson)
    assert not is_institute(recjson)
    assert not is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordPubli)


# ............................................................................
#
# Thesis
#
225
def test_thesis_cds_02013():
LE GAC Renaud's avatar
LE GAC Renaud committed
226

227
    store = build_store("cds.cern.ch")
LE GAC Renaud's avatar
LE GAC Renaud committed
228 229 230 231 232 233 234 235
    recjson = store.get_record(1632177)

    assert not is_conference(recjson)
    assert not is_institute(recjson)
    assert is_thesis(recjson)

    record = build_record(recjson)
    assert isinstance(record, RecordThesis)