def test_get_note_publication_info_a_list_not_a_note_with_preprint(): publication_info_a_list_not_a_note_with_preprint = InspireRecord({ 'preprint_date': '2015-12-04', 'publication_info': [ {'journal_title': 'Acta Phys.Polon.'}, {'journal_title': 'Acta Phys.Polon.'} ] }) expected = '[Submitted to: Acta Phys. Polon.(2015)]' result = Bibtex(publication_info_a_list_not_a_note_with_preprint)._get_note() assert expected == result
def test_format_thesis(app): thesis = get_db_record('lit', 1395663) expected = u'''@phdthesis{Mankuzhiyil:2010jpa, author = "Mankuzhiyil, Nijil", title = "{MAGIC $\\gamma$-ray observations of distant AGN and a study of source variability and the extragalactic background light using FERMI and air Cherenkov telescopes}", school = "Udine U.", year = "2010", url = "https://magicold.mpp.mpg.de/publications/theses/NMankuzhiyil.pdf", SLACcitation = "%%CITATION = INSPIRE-1395663;%%" }''' result = Bibtex(thesis).format() assert expected == result
def test_get_note_publication_info_a_list_one_el(): publication_info_a_list_one_el = InspireRecord({ 'publication_info': [ { 'note': 'Erratum', 'journal_title': 'Phys.Rev.' } ] }) expected = '' result = Bibtex(publication_info_a_list_one_el)._get_note() assert expected == result
def test_get_entry_type_no_collections_one_valid_pubinfo(): no_collections_one_valid_pubinfo = Record({ 'publication_info': { 'journal_title': 'foo', 'journal_volume': 'bar', 'page_start': 'baz', 'year': 'quux' } }) expected = ('article', 'article') result = Bibtex(no_collections_one_valid_pubinfo)._get_entry_type() assert expected == result
def test_format_book(app): book = get_db_record('lit', 736770) expected = u'''@book{Fecko:2006zy, author = "Fecko, M.", title = "{Differential geometry and Lie groups for physicists}", publisher = "Cambridge University Press", year = "2011", ISBN = "978-0-521-18796-1, 978-0-521-84507-6, 978-0-511-24296-0", SLACcitation = "%%CITATION = INSPIRE-736770;%%" }''' result = Bibtex(book).format() assert expected == result
def test_get_volume_from_publication_info_one_with_volume_JHEP(): publication_info_a_list_one_with_volume_JHEP = InspireRecord({ '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
def test_get_entry_type_no_collections_second_pubinfo_valid(): no_collections_second_pubinfo_valid = Record({ 'publication_info': [{}, { 'journal_title': 'foo', 'journal_volume': 'bar', 'page_artid': 'baz', 'year': 'quux' }] }) expected = ('article', 'article') result = Bibtex(no_collections_second_pubinfo_valid)._get_entry_type() assert expected == result
def test_get_editor_first_author_has_editor_role(): first_author_has_editor_role = Record({ 'authors': [{ 'full_name': 'Englert, F.', 'role': 'ed.' }, { 'full_name': 'Brout, R.' }] }) expected = 'Englert, F.' result = Bibtex(first_author_has_editor_role)._get_editor() assert expected == result
def test_get_archive_prefix_some_arxiv_eprints(): some_arxiv_eprints = InspireRecord({ '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
def test_get_note_publication_info_a_list_not_a_note_with_pages(): publication_info_a_list_not_a_note_with_pages = InspireRecord({ 'publication_info': [ {'page_start': 'pp.2067', 'page_end': '2414'}, {'page_start': 'pp.2067', 'page_end': '2414'} ] }) expected = '[]' result = Bibtex(publication_info_a_list_not_a_note_with_pages)._get_note() assert expected == result
def test_get_pages_publication_info_two_pages(): publication_info_two_pages = InspireRecord({ 'publication_info': [ {'page_start': '585', 'page_end': '587'}, {'page_start': '508', 'page_end': '509'} ] }) expected = '585-587' result = Bibtex(publication_info_two_pages)._get_pages() assert expected == result
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)
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
def test_get_note_publication_info_a_list_two_els(): publication_info_a_list_two_els = { 'publication_info': [{ 'note': 'Erratum', 'journal_title': 'Phys.Rev.' }, { 'note': 'Erratum', 'journal_title': 'Phys.Rev.' }] } expected = '[Erratum: Phys. Rev.]' result = Bibtex(publication_info_a_list_two_els)._get_note() assert expected == result
def test_get_note_publication_info_a_list_a_note_with_pages(): publication_info_a_list_a_note_with_pages = Record({ 'publication_info': [{ 'note': 'Reprint', 'page_artid': '019903' }, { 'note': 'Reprint', 'page_artid': '019903' }] }) expected = '[Reprint: ,019903]' result = Bibtex(publication_info_a_list_a_note_with_pages)._get_note() assert expected == result
def test_get_note_publication_info_a_list_a_note_with_year(): publication_info_a_list_a_note_with_year = Record({ 'publication_info': [{ 'note': 'Erratum', 'year': '2015' }, { 'note': 'Erratum', 'year': '2015' }] }) expected = '[Erratum: (2015)]' result = Bibtex(publication_info_a_list_a_note_with_year)._get_note() assert expected == result
def test_get_note_publication_info_a_list_a_note_with_volume(): publication_info_a_list_a_note_with_volume = Record({ 'publication_info': [{ 'note': 'Addendum', 'journal_volume': 'D91' }, { 'note': 'Addendum', 'journal_volume': 'D91' }] }) expected = '[Addendum: D91]' result = Bibtex(publication_info_a_list_a_note_with_volume)._get_note() assert expected == result
def test_get_note_publication_info_a_list_a_note_with_issue(): publication_info_a_list_a_note_with_issue = Record({ 'publication_info': [{ 'note': 'Corrigendum', 'journal_issue': '1' }, { 'note': 'Corrigendum', 'journal_issue': '1' }] }) expected = '[Corrigendum: ,no.1]' result = Bibtex(publication_info_a_list_a_note_with_issue)._get_note() assert expected == result
def test_get_note_publication_info_a_list_a_note_with_title(): publication_info_a_list_a_note_with_title = Record({ 'publication_info': [{ 'note': 'Erratum', 'journal_title': 'Phys.Rev.' }, { 'note': 'Erratum', 'journal_title': 'Phys.Rev.' }] }) expected = '[Erratum: Phys. Rev.]' result = Bibtex(publication_info_a_list_a_note_with_title)._get_note() assert expected == result
def test_get_address_a_list_of_imprints_with_one_place_a_list(): a_list_of_imprints_with_one_place_a_list = InspireRecord({ 'imprints': [ { 'place': [ 'Moscow', 'Russia' ] } ] }) expected = 'Moscow' result = Bibtex(a_list_of_imprints_with_one_place_a_list)._get_address() assert expected == result
def test_get_pubnote_publication_info_a_list_get_kbr_keys_raises(self, g_k_k): # TODO: mock the actual invenio_knowledge API. g_k_k.side_effect = RuntimeError publication_info_a_list_one_with_everything = Record({ 'publication_info': [{ 'journal_title': 'Nucl.Phys.', 'journal_volume': '22', 'page_artid': '579-588' }] }) expected = '' result = Bibtex(publication_info_a_list_one_with_everything)._get_pubnote() assert expected == result
def test_get_pubnote_publication_info_a_list_one_with_everything(self, g_k_k): # TODO: mock the actual invenio_knowledge API. g_k_k.return_value = [['Nucl. Phys.']] publication_info_a_list_one_with_everything = Record({ 'publication_info': [{ 'journal_title': 'Nucl.Phys.', 'journal_volume': '22', 'page_artid': '579-588' }] }) expected = 'Nucl. Phys.,22,579' result = Bibtex(publication_info_a_list_one_with_everything)._get_pubnote() assert expected == result
def test_get_journal_publication_info_a_list_one_journal_title_a_list(): publication_info_a_list_one_journal_title_a_list = InspireRecord({ '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
def test_get_note_publication_info_a_list_not_a_note_with_volume_JHEP(): publication_info_a_list_not_a_note_with_volume_JHEP = Record({ 'publication_info': [{ 'journal_title': 'JHEP', 'journal_volume': '9712' }, { 'journal_title': 'JHEP', 'journal_volume': '9712' }] }) expected = '[JHEP12]' result = Bibtex( publication_info_a_list_not_a_note_with_volume_JHEP)._get_note() assert expected == result
def test_format_article(app): article = get_db_record('lit', 4328) expected = u'''@article{Glashow:1961tr, author = "Glashow, S. L.", title = "{Partial Symmetries of Weak Interactions}", journal = "Nucl. Phys.", volume = "22", year = "1961", pages = "579-588", doi = "10.1016/0029-5582(61)90469-2", SLACcitation = "%%CITATION = INSPIRE-4328;%%" }''' result = Bibtex(article).format() assert expected == result
def test_format_inproceeding(app): inproceeding = get_db_record('lit', 524480) expected = u'''@inproceedings{Hu:2000az, author = "Hu, Wayne", title = "{CMB anisotropies: A Decadal survey}", url = "http://alice.cern.ch/format/showfull?sysnb=2178340", year = "2", eprint = "astro-ph/0002520", archivePrefix = "arXiv", primaryClass = "astro-ph", SLACcitation = "%%CITATION = ASTRO-PH/0002520;%%" }''' result = Bibtex(inproceeding).format() assert expected == result
def convert_to_orcid(record): """ Converts a given record to a json containing the information that orcid needs. """ orcid_json = orcid_overdo.do(record) orcid_json['external-identifiers'] = { 'work-external-identifier': orcid_json['work_external_identifier'] } orcid_json.pop('work_external_identifier') orcid_json['citation'] = { 'citation': Bibtex(record).format(), 'citation-type': 'BIBTEX' } return orcid_json
def test_get_school_a_list_of_authors_with_one_affiliation_each(): a_list_of_authors_with_one_affiliation_each = Record({ 'authors': [{ 'affiliations': [{ 'value': 'Copenhagen U.' }] }, { 'affiliations': [{ 'value': 'Edinburgh U.' }] }] }) expected = 'Edinburgh U.' result = Bibtex(a_list_of_authors_with_one_affiliation_each)._get_school() assert expected == result
def test_get_pubnote_publication_info_a_list_one_with_title_and_pages_a_list_first_with_dash( self, g_k_k): # TODO: mock the actual invenio_knowledge API. g_k_k.return_value = [['Nucl. Phys.']] publication_info_a_list_one_with_title_and_pages_a_list = Record({ 'publication_info': [{ 'journal_title': 'Nucl.Phys.', 'page_artid': ['579-588', '550'] }] }) expected = 'Nucl.Phys.,,579' result = Bibtex(publication_info_a_list_one_with_title_and_pages_a_list )._get_pubnote() assert expected == result
def test_get_entry_type_one_collection_one_pubinfo(): one_collection_one_pubinfo = Record({ 'collections': [{ 'primary': 'conferencepaper' }], 'publication_info': [{ 'journal_title': 'foo', 'journal_volume': 'bar', 'page_artid': 'baz', 'year': 'quux' }] }) expected = ('article', 'inproceedings') result = Bibtex(one_collection_one_pubinfo)._get_entry_type() assert expected == result