test_02_record_factory.py 6.99 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
"""test_02_record_factory
3

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

"""
9 10 11 12
from invenio_tools.base import (is_conference,
                                is_institute,
                                is_thesis)

LE GAC Renaud's avatar
LE GAC Renaud committed
13 14
from invenio_tools.factory import (add_affiliation_keys,
                                   add_conference_data,
15 16 17
                                   build_record,
                                   get_conference_data)

18
from invenio_tools.inveniostore import InvenioStore
19
from invenio_tools.record import Record
20 21 22 23 24 25
from invenio_tools.recordconf import RecordConf
from invenio_tools.recordinst import RecordInst
from invenio_tools.recordpubli import RecordPubli
from invenio_tools.recordthesis import RecordThesis


26 27
# ............................................................................
#
LE GAC Renaud's avatar
LE GAC Renaud committed
28
# Conference proceeding and talk
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 92 93 94 95 96 97 98 99 100 101 102
#
def test_get_conference_data():
    """ check the different approach to get the conference data
    using the same proceeding, in both store cds.cern.ch and 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 |
        +------------------+--------------+-----------|

    """
    # ........................................................................
    #
    # CDS
    #

    # 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

    # ........................................................................
    #
    # INSPIRE
    #

    # by id
    recjson3 = get_conference_data("inspirehep.net", conf_id=980401)
    assert recjson3["recid"] == 980401
    assert recjson3["meeting_name"][0]["coference_code"] == "C10-12-06"

    # by key
    recjson4 = get_conference_data("inspirehep.net", key="C10-12-06")
    assert recjson4["recid"] == 980401
    assert recjson4["meeting_name"][0]["coference_code"] == "C10-12-06"
    assert recjson3 == recjson4


def test_add_conference_data():
    """ check the different approach to get the conference data
    using the same proceeding, in both store cds.cern.ch and 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 |
        +------------------+--------------+-----------|

    """
    # ........................................................................
    #
    # CDS
    #
    store = InvenioStore("cds.cern.ch")
    recjson = store.get_record(1411352)

    add_conference_data(recjson)
    assert "meeting_name" in recjson
LE GAC Renaud's avatar
LE GAC Renaud committed
103
    assert "meeting_note" in recjson
104
    assert recjson["meeting_name"][0]["coference_code"] == "rome20101206"
LE GAC Renaud's avatar
LE GAC Renaud committed
105 106 107 108 109

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

    assert recjson["meeting_note"]["recid"] == 1181092
110 111 112 113 114 115 116 117 118 119

    # ........................................................................
    #
    # INSPIRE
    #
    store = InvenioStore("inspirehep.net")
    recjson = store.get_record(1089237)

    add_conference_data(recjson)
    assert "meeting_name" in recjson
LE GAC Renaud's avatar
LE GAC Renaud committed
120
    assert "meeting_note" in recjson
121
    assert recjson["meeting_name"][0]["coference_code"] == "C10-12-06"
LE GAC Renaud's avatar
LE GAC Renaud committed
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

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

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


def test_conference_cds():

    store = InvenioStore("cds.cern.ch")
    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)


def test_conference_inspirehep():

    store = InvenioStore("inspirehep.net")
    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)


def test_talk_cds():

    store = InvenioStore("cds.cern.ch")
    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
#
def test_add_affiliation_keys():
    """CPPM"""
    store = InvenioStore("inspirehep.net")
    recjson = store.get_record(902989)

    add_affiliation_keys(recjson)

    assert u"corporate_note" in recjson
    assert recjson[u"corporate_note"][u"identifier"] == "Marseille, CPPM"
    assert recjson[u"corporate_note"][u"futur_identifier"] == "CPPM, Marseille"


def test_institute():
    """CPPM"""
    store = InvenioStore("inspirehep.net")
    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, ...
#
def test_publi_cds():
    """Precision luminosity measurements at LHCb"""

    store = InvenioStore("cds.cern.ch")
    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)


def test_publi_inspirehep():
    """Precision luminosity measurements at LHCb"""

    store = InvenioStore("inspirehep.net")
    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
#
def test_thesis_cds():

    store = InvenioStore("cds.cern.ch")
    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)