def test_metadata_references_items_empty(): schema = LiteratureReferencesSchemaJSONUIV1() dump = {'metadata': {'titles': [{'title': 'Jessica Jones'}]}} expected = {'metadata': {'references': []}} result = schema.dumps(dump).data assert expected == json.loads(result)
def test_references_schema_without_references(): schema = LiteratureReferencesSchemaJSONUIV1() record = { 'metadata': { 'titles': [ { 'title': 'Jessica Jones', }, ], }, } expected = {'metadata': {'references': []}} result = json.loads(schema.dumps(record).data) assert expected == result
def test_references_schema_missing_data(): schema = LiteratureReferencesSchemaJSONUIV1() record = { 'metadata': { 'references': [ { 'reference': { 'book_series': [ { 'title': 'Cool Book Serie' }, ] }, }, ], }, } expected = {'metadata': {'references': []}} result = json.loads(schema.dumps(record).data) assert expected == result
def test_references_schema_missing_data(): schema = LiteratureReferencesSchemaJSONUIV1() record = { 'metadata': { 'references': [ { 'reference': { 'dois': [ '10.1088/1361-6633/aa5514', ], 'arxiv_eprint': '1607.06746', 'collaborations': [ 'LHCb', ] }, }, ], }, } expected = {'metadata': {'references': []}} result = json.loads(schema.dumps(record).data) assert expected == result
def test_references_schema_without_record(): schema = LiteratureReferencesSchemaJSONUIV1() record = { 'metadata': { 'references': [ { 'reference': { 'title': { 'title': 'Luke Cage', }, 'authors': [ { 'full_name': 'Hahn, F.' }, { 'full_name': 'Smith, J.', 'inspire_roles': ['supervisor'], }, ], 'label': '388', 'misc': [ 'NA62: Technical Design Document, Dec.', ], 'publication_info': { 'year': 2010, }, 'dois': [ '10.1088/1361-6633/aa5514', ], 'arxiv_eprint': '1607.06746', 'collaborations': [ 'LHCb', ], 'urls': [{ 'value': 'http://sf2a.eu/semaine-sf2a/2013/proceedings/' }], }, }, ] } } expected = { 'metadata': { 'references': [ { 'label': '388', 'titles': [ { 'title': 'Luke Cage', }, ], 'authors': [ { 'full_name': 'Hahn, F.', 'first_name': 'F.', 'last_name': 'Hahn', }, ], }, ] } } result = json.loads(schema.dumps(record).data) assert expected == result
def test_references_schema_with_record(isolated_app): schema = LiteratureReferencesSchemaJSONUIV1() cited_record = { 'control_number': 123, 'titles': [ { 'title': 'Jessica Jones', }, ], 'authors': [ { 'full_name': 'Frank Castle', }, { 'full_name': 'Smith, Jim', 'inspire_roles': ['editor'], }, { 'full_name': 'Jimmy', 'inspire_roles': ['supervisor'], }, ], 'dois': [ { 'value': '10.1088/1361-6633/aa5514', }, ], 'publication_info': [ { 'artid': '046201', 'journal_issue': '4', 'journal_recid': 1214416, 'journal_record': { '$ref': 'http://labs.inspirehep.net/api/journals/1214416' }, 'journal_title': 'Rept.Prog.Phys.', 'journal_volume': '80', 'year': 2017, }, ], 'arxiv_eprints': [ { 'value': '1607.06746', }, ], 'urls': [{ 'value': 'http://sf2a.eu/semaine-sf2a/2013/proceedings/' }], 'collaborations': [{ 'value': 'LHCb', }], } TestRecordMetadata.create_from_kwargs(json=cited_record) record = { 'metadata': { 'references': [{ 'record': { '$ref': 'http://labs.inspirehep.net/api/literature/123' }, 'reference': { 'authors': [{ 'full_name': 'Yamanaka, T.' }], 'label': '389', 'misc': ['The J-PARC KOTO experiment 006'], 'publication_info': { 'artid': '02B006', 'journal_title': 'PTEP', 'journal_volume': '2012', 'year': 2012, } } }, { 'reference': { 'authors': [{ 'full_name': 'Jessica Jones' }], 'label': '1', 'misc': ['The J-PARC KOTO experiment 006'], 'publication_info': { 'artid': '02B006', 'journal_volume': '2012', 'year': 2012, } } }, { 'reference': { 'authors': [{ 'full_name': 'Luke Cage' }], 'label': '2', 'publication_info': { 'journal_title': 'PTEP', 'year': 2012, } } }], }, } expected = { 'metadata': { 'references': [ { 'control_number': 123, 'titles': [ { 'title': 'Jessica Jones', }, ], 'label': '389', 'authors': [ # only first 10 authors and supervisors are returned { 'full_name': 'Frank Castle', 'first_name': 'Frank Castle', }, { 'full_name': 'Smith, Jim', 'first_name': 'Jim', 'last_name': 'Smith', 'inspire_roles': ['editor'], }, ], 'publication_info': [ { 'journal_title': 'Rept.Prog.Phys.', 'journal_volume': '80', 'artid': '046201', 'year': 2017, 'journal_issue': '4', }, ], }, { 'authors': [{ 'full_name': 'Jessica Jones', 'first_name': 'Jessica Jones', }], 'label': '1', }, { 'authors': [{ 'full_name': 'Luke Cage', 'first_name': 'Luke Cage', }], 'label': '2', 'publication_info': [ { 'journal_title': 'PTEP', 'year': 2012, }, ], } ] } } result = json.loads(schema.dumps(record).data) assert expected == result