def test_doi_custom_suffix_format(self): provider = 'arhs' suffixes_valid = ['test_1', '01.025', 'doi-valid', '(ok)', 'Normal'] suffixes_invalid = [ '#test2', 'f/f/f', 'test_with_$', '&aaa', '!?+bbb', '_.-;)(', ';k;', 'super test' ] for suffix in suffixes_valid: doi = DOI(DOIControllerTest._TEST_CONFIG.doi_prefix, provider, suffix) self.assertTrue(doi is not None) self.assertEqual(doi.get_suffix_element(), suffix) for suffix in suffixes_invalid: self.assertRaises(Exception, DOI, DOIControllerTest._TEST_CONFIG.doi_prefix, provider, suffix)
def is_external_doi(self, doi_str): """ Check if the DOI is an external DOI. :param str doi_str: The DOI to check. :return boolean: True if the DOI isn't managed internally. """ try: doi = DOI.doi_from_string(doi_str) return not self._doi_controller.doi_exists(doi) except BaseException as exception: return True
def test_doi_create_custom_suffix(self): provider = 'arhs' suffix = "TEST_CUSTOM" doi = DOI(DOIControllerTest._TEST_CONFIG.doi_prefix, provider, suffix) DOIControllerTest._doi_controller.remove_all_doi( prefix=DOIControllerTest._TEST_CONFIG.doi_prefix, provider=provider, value=suffix) DOIControllerTest._doi_controller.set_doi_association(doi) self.assertTrue(DOIControllerTest._doi_controller.doi_exists(doi))
def test_update(self): prefix = DOIStorageTest._TEST_CONFIG.doi_prefix provider = DOIStorageTest._data['providers'][1] value = "10" uri = DOIStorageTest._data['uris'][3] doi1 = DOI(prefix, provider, value, None) # Insert a new DOI DOIStorageTest._storage.save(doi1) # Exist at this moment and could be the same as provided self.assertEquals( doi1, DOIStorageTest._storage.find_one(prefix=prefix, provider=provider, value=value)) # Update the DOI doi1.set_uri(uri) DOIStorageTest._storage.save(doi1) # Exist at this moment and could be the same as provided self.assertEquals(doi1, DOIStorageTest._storage.find_one(uri=uri))
def test_doi_assign_to_custom_suffix(self): provider = 'arhs' suffix = "TEST_CUSTOM" uri = 'URI.for.tests' DOIControllerTest._doi_controller.remove_association_by_uri(uri) doi = DOI(DOIControllerTest._TEST_CONFIG.doi_prefix, provider, suffix) if not DOIControllerTest._doi_controller.doi_exists(doi): DOIControllerTest._doi_controller.set_doi_association(doi) DOIControllerTest._doi_controller.set_doi_association(doi, uri) self.assertEqual(uri, DOIControllerTest._doi_controller.get_uri_by_doi(doi))
def assign_doi(self, doi_str, uri=None): """ Assign a URI to an existing. :param str doi_str: The DOI to associate. :param str uri: The uri of the element to associate. """ if self.is_external_doi(doi_str): return try: doi = DOI.doi_from_string(doi_str) self._doi_controller.set_doi_association(doi, uri) except BaseException as exception: error_message = 'DOI association failed: {0}'.format( exception.message) self._logger.error(error_message) raise DOIRegistrationException(error_message)
def test_insert(self): prefix = DOIStorageTest._TEST_CONFIG.doi_prefix provider = DOIStorageTest._data['providers'][0] value = "8" doi1 = DOI(prefix, provider, value) # Do not exist at this moment self.assertEquals( None, DOIStorageTest._storage.find_one(prefix=prefix, provider=provider, value=value)) # Insert the new DOI DOIStorageTest._storage.save(doi1) # Exist at this moment and could be the same as provided self.assertEquals( doi1, DOIStorageTest._storage.find_one(prefix=prefix, provider=provider, value=value))
def test_get_all_doi(self): prefix = DOIStorageTest._TEST_CONFIG.doi_prefix provider = DOIStorageTest._data['providers'][3] dois = [ DOI(prefix, provider, "6"), DOI(prefix, provider, "8"), DOI(prefix, provider, "9"), DOI(prefix, provider, "10"), DOI(prefix, provider, "11") ] # Save all new DOI for doi in dois: DOIStorageTest._storage.save(doi) # Get all DOI from the same provider entries = DOIStorageTest._storage.find(prefix=prefix, provider=provider) self.assertTrue(all(elem in entries for elem in dois)) self.assertFalse(DOI(prefix, 'vec', "6") in entries) self.assertFalse(DOI('--', provider, "6") in entries)
def to_doi_object(self): return DOI(self.prefix, self.provider, self.value, self.uri)