Ejemplo n.º 1
0
def test_get_note_not_article_not_in_proceedings():
    record = InspireRecord({})

    not_article_not_in_proceedings = Bibtex(record)
    not_article_not_in_proceedings.entry_type = 'not-article'

    assert not_article_not_in_proceedings._get_note() is None
Ejemplo n.º 2
0
def test_get_booktitle_not_in_proceedings():
    record = InspireRecord({})

    not_in_proceedings = Bibtex(record)
    not_in_proceedings.entry_type = 'not-inproceedings'
    not_in_proceedings.original_entry = 'not-inproceedings'

    assert not_in_proceedings._get_booktitle() is None
Ejemplo n.º 3
0
def test_get_year_from_thesis_an_empty_obj():
    record = InspireRecord({
        'thesis': {}
    })

    thesis_an_empty_list = Bibtex(record)
    thesis_an_empty_list.original_entry = 'thesis'

    expected = ''
    result = thesis_an_empty_list._get_year()

    assert expected == result
Ejemplo n.º 4
0
def test_get_year_from_thesis_one_date():
    record = InspireRecord({
        'thesis': {'date': '2008'}
    })

    thesis_one_date = Bibtex(record)
    thesis_one_date.original_entry = 'thesis'

    expected = '2008'
    result = thesis_one_date._get_year()

    assert expected == result
Ejemplo n.º 5
0
def test_get_booktitle_from_generate_booktitle(g_b):
    # TODO: mock the actual generate_booktitle output.
    g_b.return_value = 'foo bar baz'

    record = InspireRecord({})

    in_proceedings = Bibtex(record)
    in_proceedings.entry_type = 'inproceedings'

    expected = '{foo bar baz}'
    result = in_proceedings._get_booktitle()

    assert expected == result
Ejemplo n.º 6
0
def test_get_year_from_thesis_an_empty_obj_but_preprint_date():
    record = InspireRecord({
        'preprint_date': '1998-04-30',
        'thesis': {}
    })

    thesis_an_empty_list_but_preprint_date = Bibtex(record)
    thesis_an_empty_list_but_preprint_date.original_entry = 'thesis'

    expected = '1998'
    result = thesis_an_empty_list_but_preprint_date._get_year()

    assert expected == result
Ejemplo n.º 7
0
def test_get_year_from_thesis_an_empty_obj_but_imprints():
    record = InspireRecord({
        'imprints': [{'date': '2015-12-04'}],
        'thesis': {}
    })

    thesis_an_empty_list_but_imprints = Bibtex(record)
    thesis_an_empty_list_but_imprints.original_entry = 'thesis'

    expected = '2015'
    result = thesis_an_empty_list_but_imprints._get_year()

    assert expected == result
Ejemplo n.º 8
0
def test_get_year_from_thesis_two_dates():
    record = Record({
        'thesis': [
            {'date': '2008'},
            {'date': '2015'}
        ]
    })

    thesis_two_dates = Bibtex(record)
    thesis_two_dates.original_entry = 'thesis'

    expected = '2015'
    result = thesis_two_dates._get_year()

    assert expected == result
Ejemplo n.º 9
0
def test_get_entry_type_bookchapter_no_pubinfo():
    bookchapter_no_pubinfo = InspireRecord({
        'collections': [
            {'primary': 'bookchapter'}
        ]
    })

    expected = ('inbook', 'inbook')
    result = Bibtex(bookchapter_no_pubinfo)._get_entry_type()

    assert expected == result
Ejemplo n.º 10
0
def test_get_url_one_url_not_to_an_image():
    one_url_not_to_an_image = InspireRecord({
        'urls': [
            {'value': 'http://link.aps.org/abstract/PRL/V19/P1264'}
        ]
    })

    expected = 'http://link.aps.org/abstract/PRL/V19/P1264'
    result = Bibtex(one_url_not_to_an_image)._get_url()

    assert expected == result
Ejemplo n.º 11
0
def test_get_eprint_arxiv_field_starts_with_arxiv():
    starts_with_arxiv = InspireRecord({
        'arxiv_eprints': [
            {'value': 'arXiv:1512.01381'}
        ]
    })

    expected = '1512.01381'
    result = Bibtex(starts_with_arxiv)._get_eprint()

    assert expected == result
Ejemplo n.º 12
0
def test_get_entry_type_published_no_pubinfo():
    published_no_pubinfo = InspireRecord({
        'collections': [
            {'primary': 'published'}
        ]
    })

    expected = ('article', 'article')
    result = Bibtex(published_no_pubinfo)._get_entry_type()

    assert expected == result
Ejemplo n.º 13
0
def test_get_number_publication_info_a_list_one_issue():
    publication_info_a_list_one_issue = InspireRecord({
        'publication_info': [
            {'journal_issue': '5'}
        ]
    })

    expected = '5'
    result = Bibtex(publication_info_a_list_one_issue)._get_number()

    assert expected == result
Ejemplo n.º 14
0
def test_get_url_urls_without_value():
    urls_without_url = InspireRecord({
        'urls': [
            {'not-value': 'foo'}
        ]
    })

    expected = ''
    result = Bibtex(urls_without_url)._get_url()

    assert expected == result
Ejemplo n.º 15
0
def test_get_url_one_url_to_an_image():
    one_url_to_an_image = InspireRecord({
        'urls': [
            {'value': 'foo.jpg'}
        ]
    })

    expected = ''
    result = Bibtex(one_url_to_an_image)._get_url()

    assert expected == result
Ejemplo n.º 16
0
def test_get_volume_from_book_series_one_volume():
    book_series_one_volume = InspireRecord({
        'book_series': [
            {'volume': '11'}
        ]
    })

    expected = '11'
    result = Bibtex(book_series_one_volume)._get_volume()

    assert expected == result
Ejemplo n.º 17
0
def test_get_address_a_list_of_imprints_with_one_place_not_a_list():
    a_list_of_imprints_with_one_place_not_a_list = {
        'imprints': [{
            'place': 'Piscataway, USA'
        }]
    }

    expected = 'Piscataway, USA'
    result = Bibtex(
        a_list_of_imprints_with_one_place_not_a_list)._get_address()

    assert expected == result
Ejemplo n.º 18
0
def test_get_organization_with_a_list_of_imprints_selects_first_with_a_publisher(
):
    a_list_of_imprints_with_a_publisher = {
        'imprints': [{}, {
            'publisher': 'Cambridge University Press'
        }]
    }

    expected = 'Cambridge University Press'
    result = Bibtex(a_list_of_imprints_with_a_publisher)._get_organization()

    assert expected == result
Ejemplo n.º 19
0
def test_get_volume_from_publication_info_actually_from_book_series():
    publication_info_actually_from_book_series = Record({
        'publication_info': [],
        'book_series': [{
            'volume': '11'
        }]
    })

    expected = '11'
    result = Bibtex(publication_info_actually_from_book_series)._get_volume()

    assert expected == result
Ejemplo n.º 20
0
def test_get_author_two_authors_with_fullnames():
    two_authors_with_fullnames = InspireRecord({
        'authors': [
            {'full_name': 'Englert, F.'},
            {'full_name': 'Brout, R.'}
        ]
    })

    expected = ['Englert, F.', 'Brout, R.']
    result = Bibtex(two_authors_with_fullnames)._get_author()

    assert expected == result
Ejemplo n.º 21
0
def test_get_collaboration_with_a_list_of_collaboration_selects_first():
    a_list_of_collaboration = Record(
        {'collaboration': [{
            'value': 'ATLAS'
        }, {
            'value': 'CMS'
        }]})

    expected = 'ATLAS'
    result = Bibtex(a_list_of_collaboration)._get_collaboration()

    assert expected == result
Ejemplo n.º 22
0
def test_get_archive_prefix_some_arxiv_eprints():
    some_arxiv_eprints = Record({
        'arxiv_eprints': [{
            u'categories': [u'hep-th'],
            u'value': u'hep-th/9709220'
        }]
    })

    expected = 'arXiv'
    result = Bibtex(some_arxiv_eprints)._get_archive_prefix()

    assert expected == result
Ejemplo n.º 23
0
def test_get_year_from_publication_info_a_list_from_preprint_date():
    publication_info_a_list_from_preprint_date = InspireRecord({
        'publication_info': [],
        'preprint_date': [
            '2015-12-04'
        ]
    })

    expected = '2015'
    result = Bibtex(publication_info_a_list_from_preprint_date)._get_year()

    assert expected == result
Ejemplo n.º 24
0
def test_get_title_with_a_list_of_titles_selectes_first():
    a_list_of_titles = InspireRecord({
        'titles': [
            {'title': 'Broken Symmetries and the Masses of Gauge Bosons'},
            {'title': 'BROKEN SYMMETRIES AND THE MASSES OF GAUGE BOSONS.'}
        ]
    })

    expected = 'Broken Symmetries and the Masses of Gauge Bosons'
    result = Bibtex(a_list_of_titles)._get_title()

    assert expected == result
Ejemplo n.º 25
0
def test_get_editor_non_first_author_has_editor_role():
    non_first_author_has_editor_role = InspireRecord({
        'authors': [
            {'full_name': 'Englert, F.'},
            {
                'full_name': 'Brout, R.',
                'role': 'ed.'
            }
        ]
    })

    assert Bibtex(non_first_author_has_editor_role)._get_editor() is None
Ejemplo n.º 26
0
def test_get_note_publication_info_a_list_one_el():
    publication_info_a_list_one_el = Record({
        'publication_info': [{
            'note': 'Erratum',
            'journal_title': 'Phys.Rev.'
        }]
    })

    expected = ''
    result = Bibtex(publication_info_a_list_one_el)._get_note()

    assert expected == result
Ejemplo n.º 27
0
def test_get_note_publication_info_a_list_not_a_note_with_year():
    publication_info_a_list_not_a_note_with_year = Record(
        {'publication_info': [{
            'year': '2015'
        }, {
            'year': '2015'
        }]})

    expected = '[(2015)]'
    result = Bibtex(publication_info_a_list_not_a_note_with_year)._get_note()

    assert expected == result
Ejemplo n.º 28
0
def test_get_year_from_publication_info_a_list_from_imprints():
    publication_info_a_list_from_imprints = Record({
        'publication_info': [],
        'imprints': [{
            'date': '2015-12-04'
        }]
    })

    expected = '2015'
    result = Bibtex(publication_info_a_list_from_imprints)._get_year()

    assert expected == result
Ejemplo n.º 29
0
def test_get_author_one_author_with_full_name_a_list():
    one_author_with_full_name_a_list = Record({
        'authors': [{
            'full_name':
            ['Goldstone, Jeffrey', 'Salam, Abdus', 'Weinberg, Steven']
        }]
    })

    expected = ['Goldstone, Jeffreyand Salam, Abdusand Weinberg, Steven']
    result = Bibtex(one_author_with_full_name_a_list)._get_author()

    assert expected == result
Ejemplo n.º 30
0
def test_get_journal_publication_info_a_list_one_journal_title_a_list():
    publication_info_a_list_one_journal_title_a_list = Record({
        'publication_info': [{
            'journal_title': ['Acta Phys.Polon.', 'Nucl.Phys.']
        }]
    })

    expected = 'Nucl.Phys.'
    result = Bibtex(
        publication_info_a_list_one_journal_title_a_list)._get_journal()

    assert expected == result
Ejemplo n.º 31
0
def test_get_address_a_list_of_imprints_with_two_places():
    a_list_of_imprints_with_two_places = Record(
        {'imprints': [{
            'place': 'Moscow'
        }, {
            'place': 'Russia'
        }]})

    expected = 'Moscow'
    result = Bibtex(a_list_of_imprints_with_two_places)._get_address()

    assert expected == result
Ejemplo n.º 32
0
def test_get_isbn_two_isbns_one_a_list():
    two_isbns_one_a_list = InspireRecord({
        'isbns': [
            {'value': ['978-3-319-17544-7', '978-3-319-17545-4']},
            {'value': '978-94-010-2276-7'}
        ]
    })

    expected = '978-3-319-17544-7, 978-94-010-2276-7'
    result = Bibtex(two_isbns_one_a_list)._get_isbn()

    assert expected == result
Ejemplo n.º 33
0
def test_get_year_from_imprints_two_dates():
    imprints_two_dates = Record(
        {'imprints': [{
            'date': '1998-04-30'
        }, {
            'date': '2015-12-04'
        }]})

    expected = '2015'
    result = Bibtex(imprints_two_dates)._get_year()

    assert expected == result
Ejemplo n.º 34
0
def test_get_year_from_preprint_date_two_dates():
    preprint_date_two_dates = InspireRecord({
        'preprint_date': [
            '1998-04-30',
            '2015-12-04'
        ]
    })

    expected = '1998'
    result = Bibtex(preprint_date_two_dates)._get_year()

    assert expected == result
Ejemplo n.º 35
0
def test_get_volume_from_publication_info_one_with_volume_JHEP():
    publication_info_a_list_one_with_volume_JHEP = Record({
        'publication_info': [{
            'journal_title': 'JHEP',
            'journal_volume': '1511'
        }]
    })

    expected = '11'
    result = Bibtex(publication_info_a_list_one_with_volume_JHEP)._get_volume()

    assert expected == result
Ejemplo n.º 36
0
    def serialize_search(self, pid_fetcher, search_result, links=None,
                         item_links_factory=None):
        """Serialize a search result.
        :param pid_fetcher: Persistent identifier fetcher.
        :param search_result: Elasticsearch search result.
        :param links: Dictionary of links to add to response.
        """
        records = []
        for hit in search_result['hits']['hits']:
            records.append(Bibtex(record=hit['_source']).format())

        return "\n".join(records)
Ejemplo n.º 37
0
def test_get_volume_from_book_series_two_volumes():
    book_series_two_volumes = Record(
        {'book_series': [{
            'volume': '11'
        }, {
            'volume': '5'
        }]})

    expected = '5'
    result = Bibtex(book_series_two_volumes)._get_volume()

    assert expected == result
Ejemplo n.º 38
0
def test_get_pages_publication_info_one_page():
    publication_info_one_page = {
        'publication_info': [{
            'page_start': '585',
            'page_end': '587'
        }]
    }

    expected = '585-587'
    result = Bibtex(publication_info_one_page)._get_pages()

    assert expected == result