def test_canonicalize_xml_element(self): parser = etree.XMLParser(remove_blank_text=True) xml_string = """ <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work" xmlns:superfluous="http://127.0.0.1"> <work:title> <common:title><![CDATA[A <Dissertation>]]></common:title> </work:title> <work:type>dissertation</work:type> </work:work> """ xml_parsed1 = etree.fromstring(xml_string, parser) xml_string = """ <work:work xmlns:work="http://www.orcid.org/ns/work" xmlns:common="http://www.orcid.org/ns/common"> <!-- I'm a comment, strip me --> <work:title> <common:title>A <Dissertation></common:title> </work:title> <work:type>dissertation</work:type> </work:work> """ xml_parsed2 = etree.fromstring(xml_string, parser) assert (_OrcidHasher(mock.Mock())._canonicalize_xml_element( xml_parsed1) == _OrcidHasher( mock.Mock())._canonicalize_xml_element(xml_parsed2))
def test_format_thesis(app, api_client): response = api_client.get('/literature/1395663') assert response.status_code == 200 phdthesis = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common: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</common:title> </work:title> <work:type>dissertation</work:type> <work:url>http://inspirehep.net/record/1395663</work:url> <work:contributors> <work:contributor> <work:credit-name>Mankuzhiyil, Nijil</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( phdthesis['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_canonicalize_xml_element(self): parser = etree.XMLParser(remove_blank_text=True) xml_string = """ <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work" xmlns:superfluous="http://127.0.0.1"> <work:title> <common:title><![CDATA[A <Dissertation>]]></common:title> </work:title> <work:type>dissertation</work:type> </work:work> """ xml_parsed1 = etree.fromstring(xml_string, parser) xml_string = """ <work:work xmlns:work="http://www.orcid.org/ns/work" xmlns:common="http://www.orcid.org/ns/common"> <!-- I'm a comment, strip me --> <work:title> <common:title>A <Dissertation></common:title> </work:title> <work:type>dissertation</work:type> </work:work> """ xml_parsed2 = etree.fromstring(xml_string, parser) assert (_OrcidHasher(mock.Mock())._canonicalize_xml_element(xml_parsed1) == _OrcidHasher(mock.Mock())._canonicalize_xml_element(xml_parsed2))
def test_format_book(app, api_client): response = api_client.get('/literature/736770') assert response.status_code == 200 book = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common:title>Differential geometry and Lie groups for physicists</common:title> </work:title> <work:type>book</work:type> <common:publication-date> <common:year>2011</common:year> <common:month>03</common:month> <common:day>03</common:day> </common:publication-date> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>736770</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/736770</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>isbn</common:external-id-type> <common:external-id-value>9780521187961</common:external-id-value> </common:external-id> <common:external-id> <common:external-id-type>isbn</common:external-id-type> <common:external-id-value>9780521845076</common:external-id-value> </common:external-id> <common:external-id> <common:external-id-type>isbn</common:external-id-type> <common:external-id-value>9780511242960</common:external-id-value> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/736770</work:url> <work:contributors> <work:contributor> <work:credit-name>Fecko, M.</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( book['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_format_proceedings(app, api_client): response = api_client.get('/literature/701585') assert response.status_code == 200 proceedings = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common:title>HERA and the LHC: A Workshop on the implications of HERA for LHC physics: Proceedings Part A</common:title> </work:title> <work:type>edited-book</work:type> <common:publication-date> <common:year>2005</common:year> </common:publication-date> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>701585</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/701585</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>arxiv</common:external-id-type> <common:external-id-value>hep-ph/0601012</common:external-id-value> <common:external-id-url>http://arxiv.org/abs/hep-ph/0601012</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/701585</work:url> <work:contributors> <work:contributor> <work:credit-name>De Roeck, A.</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>editor</work:contributor-role> </work:contributor-attributes> </work:contributor> <work:contributor> <work:credit-name>Jung, H.</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>additional</work:contributor-sequence> <work:contributor-role>editor</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( proceedings['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_format_thesis_with_author_orcid(app, api_client): response = api_client.get('/literature/1395663') assert response.status_code == 200 phdthesis = json.loads(response.data) phdthesis['metadata']['authors'][0]['ids'] = [ { 'schema': 'ORCID', 'value': '0000-0002-1825-0097', } ] phdthesis['metadata']['authors'][0]['emails'] = ['*****@*****.**'] expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common: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</common:title> </work:title> <work:type>dissertation</work:type> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>1395663</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/1395663</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/1395663</work:url> <work:contributors> <work:contributor> <common:contributor-orcid> <common:uri>http://orcid.org/0000-0002-1825-0097</common:uri> <common:path>0000-0002-1825-0097</common:path> <common:host>orcid.org</common:host> </common:contributor-orcid> <work:credit-name>Mankuzhiyil, Nijil</work:credit-name> <work:contributor-email>[email protected]</work:contributor-email> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( phdthesis['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_format_article(app, api_client): response = api_client.get('/literature/4328') assert response.status_code == 200 article = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common:title>Partial Symmetries of Weak Interactions</common:title> </work:title> <work:journal-title>Nucl.Phys.</work:journal-title> <work:type>journal-article</work:type> <common:publication-date> <common:year>1961</common:year> </common:publication-date> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>4328</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/4328</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>doi</common:external-id-type> <common:external-id-value>10.1016/0029-5582(61)90469-2</common:external-id-value> <common:external-id-url>http://dx.doi.org/10.1016/0029-5582(61)90469-2</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/4328</work:url> <work:contributors> <work:contributor> <work:credit-name>Glashow, S.L.</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( article['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_format_conference_paper(app, api_client): response = api_client.get('/literature/524480') assert response.status_code == 200 inproceedings = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common:title>CMB anisotropies: A Decadal survey</common:title> </work:title> <work:journal-title>4th RESCEU International Symposium on Birth and Evolution of the Universe</work:journal-title> <work:type>conference-paper</work:type> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>524480</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/524480</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>arxiv</common:external-id-type> <common:external-id-value>astro-ph/0002520</common:external-id-value> <common:external-id-url>http://arxiv.org/abs/astro-ph/0002520</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/524480</work:url> <work:contributors> <work:contributor> <work:credit-name>Hu, Wayne</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( inproceedings['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def test_format_book_chapter(app, api_client): response = api_client.get('/literature/1375491') assert response.status_code == 200 inbook = json.loads(response.data) expected = xml_parse(""" <work:work xmlns:common="http://www.orcid.org/ns/common" xmlns:work="http://www.orcid.org/ns/work"> <work:title> <common:title>Supersymmetry</common:title> </work:title> <work:type>book-chapter</work:type> <common:publication-date> <common:year>2015</common:year> </common:publication-date> <common:external-ids> <common:external-id> <common:external-id-type>other-id</common:external-id-type> <common:external-id-value>1375491</common:external-id-value> <common:external-id-url>http://inspirehep.net/record/1375491</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>doi</common:external-id-type> <common:external-id-value>10.1007/978-3-319-15001-7_10</common:external-id-value> <common:external-id-url>http://dx.doi.org/10.1007/978-3-319-15001-7_10</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> <common:external-id> <common:external-id-type>arxiv</common:external-id-type> <common:external-id-value>1506.03091</common:external-id-value> <common:external-id-url>http://arxiv.org/abs/1506.03091</common:external-id-url> <common:external-id-relationship>self</common:external-id-relationship> </common:external-id> </common:external-ids> <work:url>http://inspirehep.net/record/1375491</work:url> <work:contributors> <work:contributor> <work:credit-name>Bechtle, Philip</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>first</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> <work:contributor> <work:credit-name>Plehn, Tilman</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>additional</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> <work:contributor> <work:credit-name>Sander, Christian</work:credit-name> <work:contributor-attributes> <work:contributor-sequence>additional</work:contributor-sequence> <work:contributor-role>author</work:contributor-role> </work:contributor-attributes> </work:contributor> </work:contributors> </work:work> """) result = OrcidConverter( inbook['metadata'], url_pattern='http://inspirehep.net/record/{recid}', ).get_xml() assert valid_against_schema(result) assert xml_compare(expected, result) assert _OrcidHasher(mock.Mock())._hash_xml_element(expected) == _OrcidHasher(mock.Mock())._hash_xml_element(result)
def setup(self): factory = TestRecordMetadata.create_from_file( __name__, 'test_orcid_hasher_record.json') self.record = factory.record_metadata self.hash_value = 'sha1:ede49b12e11f5284fdced7596a28791ddf32c8fc' self.hasher = _OrcidHasher(factory.inspire_record)
def setup(self): factory = TestRecordMetadata.create_from_file(__name__, 'test_orcid_hasher_record.json') self.record = factory.record_metadata self.hash_value = 'sha1:acbc7dad4fd46e0deb60d6681c244a67e4be2543' self.hasher = _OrcidHasher(factory.inspire_record)