예제 #1
0
def test_literature_record_publication_information_handles_missing_fields():
    record = LiteratureRecord({
        'publication_info': [
            {
                'journal_title': 'Astropart.Phys.',
                'year': 2018,
                'pubinfo_freetext': 'Symmetry 10, 287 (2018)',
            },
            {
                'cnum': 'C93-07-01',
                'conference_recid': 968950,
                'conference_record': {
                    '$ref': 'http://labs.inspirehep.net/api/conferences/968950'
                },
            },
        ],
    })

    expected = [
        {
            'journal_title': 'Astropart.Phys.',
            'year': '2018',
            'pubinfo_freetext': 'Symmetry 10, 287 (2018)',
        },
    ]

    assert expected == record.publication_information
예제 #2
0
def test_publication_info_with_pub_info_and_conf_info(r_r, mock_replace_refs):
    with_title = '2005 International Linear Collider Workshop (LCWS 2005)'
    conf_rec = {'$ref': 'http://x/y/976391'}
    parent_rec = {'$ref': 'http://x/y/706120'}

    r_r.side_effect = mock_replace_refs(with_title, [(conf_rec, 976391),
                                                     (parent_rec, 706120)])

    with_pub_info_and_conf_info = LiteratureRecord({
        'publication_info': [{
            'journal_title': 'eConf',
            'journal_volume': 'C050318'
        }, {
            'conference_record': conf_rec,
            'parent_record': parent_rec
        }]
    })

    expected = {
        'conf_info':
        '(<a href="/record/706120">Proceedings</a> of <a '
        'href="/record/976391">\n  2005 International Linear '
        'Collider Workshop (LCWS 2005)</a>)',
        'pub_info': ['<i>eConf</i> C050318']
    }
    result = publication_info(with_pub_info_and_conf_info)

    assert expected == result
예제 #3
0
def test_publication_info_an_empty_list():
    an_empty_list = LiteratureRecord({'publication_info': []})

    expected = {}
    result = publication_info(an_empty_list)

    assert expected == result
예제 #4
0
def test_publication_info_from_conference_recid_and_parent_recid(
        r_r, mock_replace_refs):
    conf_rec = {'$ref': 'http://x/y/976391'}
    parent_rec = {'$ref': 'http://x/y/1402672'}
    with_title = '2005 International Linear Collider Workshop (LCWS 2005)'

    r_r.side_effect = mock_replace_refs(with_title, [(conf_rec, 976391),
                                                     (parent_rec, 1402672)])

    with_conference_recid_and_parent_recid = LiteratureRecord({
        'publication_info': [{
            'conference_record': conf_rec,
            'parent_record': parent_rec
        }]
    })

    expected = {
        'conf_info':
        'Published in <a href="/record/1402672">proceedings</a> '
        'of <a href="/record/976391">2005 International Linear '
        'Collider Workshop (LCWS 2005)</a>'
    }
    result = publication_info(with_conference_recid_and_parent_recid)

    assert expected == result
예제 #5
0
def _get_ui_metadata(record):
    """Record extra metadata for the UI.

    Args:
        record(dict): the record.

    Returns:
        dict: the extra metadata.
    """
    # FIXME: Deprecated, must be removed once the new UI is released
    display = {}
    record = LiteratureRecord(record)
    if 'references' in record:
        display['number_of_references'] = len(record['references'])
    if 'earliest_date' in record:
        display['date'] = format_date(record['earliest_date'])
    if 'publication_info' in record:
        display['publication_info'] = record.publication_information
        display['conference_info'] = record.conference_information
    if 'authors' in record:
        display['number_of_authors'] = len(record['authors'])
    if 'external_system_identifiers' in record:
        display['external_system_identifiers'] = \
            record.external_system_identifiers
    display['admin_tools'] = record.admin_tools

    return display
예제 #6
0
def test_publication_info_from_conference_recid_and_parent_recid_with_pages(
        r_r, mock_replace_refs):
    with_title = '50th Rencontres de Moriond on EW Interactions and Unified Theories'
    conf_rec = {'$ref': 'http://x/y/1331207'}
    parent_rec = {'$ref': 'http://x/y/1402672'}

    r_r.side_effect = mock_replace_refs(with_title, [(conf_rec, 1331207),
                                                     (parent_rec, 1402672)])

    with_conference_recid_and_parent_recid_and_pages = LiteratureRecord({
        'publication_info': [{
            'conference_record': conf_rec,
            'parent_record': parent_rec,
            'page_start': '515',
            'page_end': '518'
        }]
    })

    expected = {
        'conf_info':
        'Published in <a href="/record/1402672">proceedings</a> '
        'of <a href="/record/1331207">50th Rencontres de Moriond '
        'on EW Interactions and Unified Theories</a>, pages\n  '
        '515-518'
    }
    result = publication_info(with_conference_recid_and_parent_recid_and_pages)

    assert expected == result
예제 #7
0
def test_literature_record_external_system_identifiers():
    record = LiteratureRecord({
        'external_system_identifiers': [
            {
                'schema': 'DESY',
                'value': 'D04-00213',
            },
            {
                'schema': 'ADS',
                'value': '2004PrPh...52..200K',
            },
            {
                'schema': 'ADS',
                'value': '2006PhR...429..121K',
            },
            {
                'schema': 'SPIRES',
                'value': 'SPIRES-5682037',
            },
        ],
    })

    expected = [
        {
            'url_link': 'http://adsabs.harvard.edu/abs/2004PrPh...52..200K',
            'url_name': 'ADS Abstract Service',
        },
    ]
    result = record.external_system_identifiers

    assert expected == result
예제 #8
0
def test_publication_info_a_list_of_one_element():
    a_list_of_one_element = LiteratureRecord(
        {'publication_info': [{
            'journal_title': 'Int.J.Mod.Phys.'
        }]})

    expected = {'pub_info': ['<i>Int.J.Mod.Phys.</i>']}
    result = publication_info(a_list_of_one_element)

    assert expected == result
예제 #9
0
def test_publication_info_from_journal_title_and_year():
    with_journal_title_and_year = LiteratureRecord(
        {'publication_info': [{
            'journal_title': 'Eur.Phys.J.',
            'year': 2015
        }]})

    expected = {'pub_info': ['<i>Eur.Phys.J.</i> (2015)']}
    result = publication_info(with_journal_title_and_year)

    assert expected == result
예제 #10
0
def test_publication_info_from_pubinfo_freetext():
    with_pubinfo_freetext = LiteratureRecord({
        'publication_info': [{
            'pubinfo_freetext':
            'Phys. Rev. 127 (1962) 965-970'
        }]
    })

    expected = {'pub_info': ['Phys. Rev. 127 (1962) 965-970']}
    result = publication_info(with_pubinfo_freetext)

    assert expected == result
예제 #11
0
def test_publication_info_from_journal_title_and_journal_issue():
    with_journal_title_and_journal_issue = LiteratureRecord({
        'publication_info': [{
            'journal_title': 'JINST',
            'journal_issue': '02'
        }]
    })

    expected = {'pub_info': ['<i>JINST</i> 02, ']}
    result = publication_info(with_journal_title_and_journal_issue)

    assert expected == result
예제 #12
0
def test_publication_info_from_journal_title_and_pages_artid():
    with_journal_title_and_pages_artid = LiteratureRecord({
        'publication_info': [{
            'journal_title': 'Astrophys.J.',
            'page_start': '525'
        }]
    })

    expected = {'pub_info': ['<i>Astrophys.J.</i> 525']}
    result = publication_info(with_journal_title_and_pages_artid)

    assert expected == result
예제 #13
0
def test_publication_info_from_journal_title_and_journal_volume():
    with_journal_title_and_journal_volume = LiteratureRecord({
        'publication_info': [{
            'journal_title': 'JHEP',
            'journal_volume': '1508'
        }]
    })

    expected = {'pub_info': ['<i>JHEP</i> 1508']}
    result = publication_info(with_journal_title_and_journal_volume)

    assert expected == result
예제 #14
0
def test_literature_record_publication_information_no_journal_title_or_pubinfo_freetext(
):
    record = LiteratureRecord({
        'publication_info': [
            {
                'cnum': 'C93-07-01',
                'conference_recid': 968950,
                'conference_record': {
                    '$ref': 'http://labs.inspirehep.net/api/conferences/968950'
                },
            },
        ],
    })

    assert not record.publication_information
예제 #15
0
def test_literature_record_external_system_identifiers_handles_kekscan():
    record = LiteratureRecord({
        'external_system_identifiers': [
            {
                'schema': 'DESY',
                'value': 'D04-00213',
            },
            {
                'schema': 'CDS',
                'value': '2231692',
            },
            {
                'schema': 'CDS',
                'value': '2232052',
            },
            {
                'schema': 'HAL',
                'value': 'in2p3-01394924',
            },
            {
                'schema': 'KEKSCAN',
                'value': '200727065',
            },
        ],
    })

    expected = [
        {
            'url_link': 'http://cds.cern.ch/record/2231692',
            'url_name': 'CERN Document Server',
        },
        {
            'url_link': 'https://hal.archives-ouvertes.fr/in2p3-01394924',
            'url_name': 'HAL Archives Ouvertes',
        },
        {
            'url_link':
            'https://lib-extopc.kek.jp/preprints/PDF/2007/0727/0727065.pdf',
            'url_name': 'KEK scanned document',
        },
    ]
    result = record.external_system_identifiers

    assert expected == result
예제 #16
0
def get_display_fields(record):
    """
    Add extra fields used for display by client application.

    Jinja2 filters can be applied here to format certain fields.
    """
    display = {}
    record = LiteratureRecord(record)
    if 'references' in record:
        display['number_of_references'] = len(record['references'])
    if 'earliest_date' in record:
        display['date'] = format_date(record['earliest_date'])
    if 'publication_info' in record:
        display['publication_info'] = record.publication_information
        display['conference_info'] = record.conference_information
    if 'authors' in record:
        display['number_of_authors'] = len(record['authors'])

    return display
예제 #17
0
def test_publication_info_from_not_conference_recid_and_parent_recid():
    without_conference_recid_with_parent_recid = LiteratureRecord({
        'publication_info': [{
            'parent_record': {
                '$ref': 'http://x/y/720114'
            }
        }]
    })

    expected = {
        'conf_info':
        'Published in <a href="/record/720114">proceedings</a> '
        'of 2005 International Linear Collider Physics and '
        'Detector Workshop and 2nd ILC Accelerator Workshop '
        '(Snowmass 2005)'
    }
    result = publication_info(without_conference_recid_with_parent_recid)

    assert expected == result
예제 #18
0
def test_publication_info_with_pub_info_and_conf_info_not_found(r_r):
    conf_rec = {'$ref': 'http://x/y/976391'}
    parent_rec = {'$ref': 'http://x/y/706120'}

    r_r.return_value = None

    with_pub_info_and_conf_info = LiteratureRecord({
        'publication_info': [{
            'journal_title': 'eConf',
            'journal_volume': 'C050318'
        }, {
            'conference_record': conf_rec,
            'parent_record': parent_rec
        }]
    })

    expected = {'pub_info': ['<i>eConf</i> C050318']}
    result = publication_info(with_pub_info_and_conf_info)

    assert expected == result
예제 #19
0
def test_publication_info_from_conference_recid_and_not_parent_recid(
        r_r, mock_replace_refs):
    with_title = '20th International Workshop on Deep-Inelastic Scattering and Related Subjects'
    conf_rec = {'$ref': 'http://x/y/1086512'}

    r_r.side_effect = mock_replace_refs(with_title, [(conf_rec, 1086512)])

    with_conference_recid_without_parent_recid = LiteratureRecord(
        {'publication_info': [{
            'conference_record': conf_rec
        }]})

    expected = {
        'conf_info':
        'Contribution to <a href="/record/1086512">20th '
        'International Workshop on Deep-Inelastic Scattering '
        'and Related Subjects</a>'
    }
    result = publication_info(with_conference_recid_without_parent_recid)

    assert expected == result
예제 #20
0
def test_literature_record_external_system_identifiers():
    record = LiteratureRecord({
        'external_system_identifiers': [
            {
                'schema': 'DESY',
                'value': 'D04-00213',
            },
            {
                'schema': 'ADS',
                'value': '2004PrPh...52..200K',
            },
            {
                'schema': 'ADS',
                'value': '2006PhR...429..121K',
            },
            {
                'schema': 'SPIRES',
                'value': 'SPIRES-5682037',
            },
        ],
    })

    expected = [
        {
            'schema': 'DESY',
            'value': 'D04-00213',
        },
        {
            'schema': 'ADS',
            'value': '2004PrPh...52..200K',
        },
        {
            'schema': 'SPIRES',
            'value': 'SPIRES-5682037',
        },
    ]
    result = record.external_system_identifiers

    assert expected == result
예제 #21
0
def test_publication_info_a_list_of_two_elements():
    a_list_of_two_elements = LiteratureRecord({
        'publication_info': [{
            'journal_volume': '8',
            'journal_title': 'JINST',
            'artid': 'P09009',
            'year': 2013
        }, {
            'journal_volume': '8',
            'journal_title': 'JINST',
            'page_start': '9009',
            'year': 2013
        }]
    })

    expected = {
        'pub_info':
        ['<i>JINST</i> 8 (2013) P09009', '<i>JINST</i> 8 (2013) 9009']
    }
    result = publication_info(a_list_of_two_elements)

    assert expected == result
예제 #22
0
def test_literature_record_publication_information_with_pubinfo_freetext():
    record = LiteratureRecord({
        'publication_info': [
            {
                'pubinfo_freetext': 'Symmetry 10, 287 (2018)',
            },
            {
                'cnum': 'C93-07-01',
                'conference_recid': 968950,
                'conference_record': {
                    '$ref': 'http://labs.inspirehep.net/api/conferences/968950'
                },
            },
        ],
    })

    expected = [
        {
            'pubinfo_freetext': 'Symmetry 10, 287 (2018)',
        },
    ]

    assert expected == record.publication_information
예제 #23
0
def test_literature_record_publication_information_with_journal_title():
    record = LiteratureRecord({
        'publication_info': [
            {
                'artid': '128',
                'journal_issue': '7',
                'journal_title': 'Astropart.Phys.',
                'journal_volume': '103',
                'material': 'erratum',
                'page_end': '48',
                'page_start': '41',
                'year': '2018',
            },
            {
                'cnum': 'C93-07-01',
                'conference_recid': 968950,
                'conference_record': {
                    '$ref': 'http://labs.inspirehep.net/api/conferences/968950'
                },
            },
        ],
    })

    expected = [
        {
            'artid': '128',
            'journal_issue': '7',
            'journal_title': 'Astropart.Phys.',
            'journal_volume': '103',
            'material': 'erratum',
            'page_end': '48',
            'page_start': '41',
            'year': '2018',
        },
    ]

    assert expected == record.publication_information
예제 #24
0
def publication_info(record):
    """Display inline publication and conference information.

    The record is a LiteratureRecord instance
    """
    if not isinstance(record, LiteratureRecord):
        record = LiteratureRecord(record)
    result = {}
    pub_infos = []
    if 'publication_info' in record:
        for pub_info in record.publication_information:
            pub_info_html = render_macro_from_template(
                name="pub_info",
                template="inspirehep_theme/format/record/Publication_info.tpl",
                ctx=pub_info)
            if pub_info_html:
                pub_infos.append(pub_info_html)

        if pub_infos:
            result['pub_info'] = pub_infos

        # Conference info line
        for conf_info in record.conference_information:
            if conf_info.get('conference_recid') and conf_info.get(
                    'parent_recid'):
                if result:
                    result['conf_info'] = render_macro_from_template(
                        name="conf_with_pub_info",
                        template=
                        "inspirehep_theme/format/record/Conference_info_macros.tpl",
                        ctx={
                            'parent_recid': conf_info.get('parent_recid'),
                            'conference_recid':
                            conf_info.get('conference_recid'),
                            'conference_title':
                            conf_info.get('conference_title'),
                        })
                    break
                else:
                    result['conf_info'] = render_macro_from_template(
                        name="conf_without_pub_info",
                        template=
                        "inspirehep_theme/format/record/Conference_info_macros.tpl",
                        ctx={
                            'parent_recid': conf_info.get('parent_recid'),
                            'conference_recid':
                            conf_info.get('conference_recid'),
                            'conference_title':
                            conf_info.get('conference_title'),
                            'page_start': conf_info.get('page_start'),
                            'page_end': conf_info.get('page_end'),
                            'artid': conf_info.get('artid'),
                        })
                    break
            elif conf_info.get(
                    'conference_recid') and not conf_info.get('parent_recid'):
                result['conf_info'] = render_macro_from_template(
                    name="conference_only",
                    template=
                    "inspirehep_theme/format/record/Conference_info_macros.tpl",
                    ctx={
                        'conference_recid': conf_info.get('conference_recid'),
                        'conference_title': conf_info.get('conference_title'),
                        'pub_info': bool(result.get('pub_info')),
                    })
            elif conf_info.get(
                    'parent_recid') and not conf_info.get('conference_recid'):
                result['conf_info'] = render_macro_from_template(
                    name="proceedings_only",
                    template=
                    "inspirehep_theme/format/record/Conference_info_macros.tpl",
                    ctx={
                        'parent_recid': conf_info.get('parent_recid'),
                        'parent_title': conf_info.get('parent_title'),
                        'pub_info': bool(result.get('pub_info')),
                    })

    return result
예제 #25
0
def test_literature_record_publication_information_no_publication_info():
    record = LiteratureRecord({})

    assert not record.publication_information