def test_rest_create_public_mock(): """Test creating DOI""" prefix = '10.1234' example_json43 = 'data/datacite-v4.3-full-example.json' example_metadata = load_json_path(example_json43) url = 'https://github.com/inveniosoftware/datacite' data = {"data": {"id": prefix+"/1", "attributes": {"url": url}}} responses.add( responses.POST, "{0}dois".format(RESTURL), json=data, status=201, ) d = get_rest(username='******', password='******', prefix=prefix) doi = d.public_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix url = 'https://github.com/inveniosoftware' data = {"data": {"id": prefix+"/1", "attributes": {"publisher": "Invenio", "url": url}}} responses.add( responses.PUT, "{0}dois/{1}/1".format(RESTURL, prefix), json=data, status=200, ) metadata = {'publisher': 'Invenio'} new_metadata = d.update_doi(doi, metadata) assert new_metadata['publisher'] == 'Invenio' new_metadata = d.update_doi(doi, url=url) assert new_metadata['url'] == url
def test_rest_create_private_mock(): """Test creating private DOI""" example_json43 = 'data/4.3/datacite-example-dataset-v4.json' example_metadata = load_json_path(example_json43) prefix = '10.1234' url = 'https://github.com/inveniosoftware/datacite' data = { "data": { "id": prefix + "/1", "attributes": { "state": "registered", "url": url } } } responses.add( responses.POST, "{0}dois".format(RESTURL), json=data, status=201, ) responses.add( responses.GET, "{0}dois/{1}/1".format(RESTURL, prefix), json=data, status=200, ) # test_mode=False because we already introduced a fake url # with RESTURL variable d = get_rest(username='******', password='******', prefix=prefix) doi = d.private_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix datacite_metadata = d.metadata_get(doi) assert datacite_metadata['state'] == 'registered' data = { "data": { "id": prefix + "/1", "attributes": { "state": "findable", "url": url } } } responses.add( responses.PUT, "{0}dois/{1}/1".format(RESTURL, prefix), json=data, status=200, ) new_metadata = d.show_doi(doi) assert new_metadata['state'] == 'findable'
def test_rest_create_public(example_json43): """Test creating DOIs with all example metadata""" example_metadata = load_json_path(example_json43) url = 'https://github.com/inveniosoftware/datacite' username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) doi = d.public_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix metadata = {'publisher': 'Invenio'} new_metadata = d.update_doi(doi, metadata) assert new_metadata['publisher'] == 'Invenio' url = 'https://github.com/inveniosoftware' new_metadata = d.update_doi(doi, url=url) assert new_metadata['url'] == url
def test_rest_create_private(): """Test creating private DOI""" example_json43 = 'data/4.3/datacite-example-dataset-v4.json' example_metadata = load_json_path(example_json43) url = 'https://github.com/inveniosoftware/datacite' username, password, prefix = get_credentials() d = get_rest(username=username, password=password, prefix=prefix, with_fake_url=False) doi = d.private_doi(example_metadata, url) datacite_prefix = doi.split('/')[0] assert datacite_prefix == prefix datacite_metadata = d.get_metadata(doi) assert datacite_metadata['state'] == 'registered' new_metadata = d.show_doi(doi) assert new_metadata['state'] == 'findable' new_metadata = d.hide_doi(doi) assert new_metadata['state'] == 'registered'
def test_example_json_validates(example_json42): """Test the example file validates against the JSON schema.""" example_json = load_json_path(example_json42) validator.validate(example_json)
def test_json_to_xml(example_xml42, example_json42, xsd42): """Test that example XML converts to example JSON.""" example_xml = load_xml_path(example_xml42) example_json = load_json_path(example_json42) xsd42.assertValid(etree.XML(example_xml.encode('utf8'))) xsd42.assertValid(etree.XML(tostring(example_json).encode('utf8')))