def testCreateRo(self): httpsession = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN) roid = "romanagertest-" + str(uuid.uuid4()) (status, reason, rouri, _) = ro_remote_metadata.createRO(httpsession, roid) if status == 409: log.debug("TestRemoteROMetadata: RO already exists %03d %s"%(status, reason)) self.remoteRo = ro_remote_metadata.ro_remote_metadata(ro_config, httpsession, rouri) return
def testGetAsZip(self): httpsession = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN) roid = "testGetAsZip" (_, _, rouri, _) = ro_remote_metadata.createRO(httpsession, roid) self.remoteRo = ro_remote_metadata.ro_remote_metadata(ro_config, httpsession, rouri) self.remoteRo.aggregateResourceInt("internal/1", "text/plain", "ipsum lorem") zipdata = ro_remote_metadata.getAsZip(rouri) zipfile = ZipFile(zipdata) self.assertEquals(len(zipfile.read("internal/1")), len("ipsum lorem"), "File size must be the same") self.assertTrue(len(zipfile.read(".ro/manifest.rdf")) > 0, "Size of manifest.rdf must be greater than 0") return
def testAddGetAggregatedResources(self): """ Test function that adds aggregated resources to a research object manifest """ httpsession = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN) roid = "romanagertest-" + str(uuid.uuid4()) (_, _, rouri, _) = ro_remote_metadata.createRO(httpsession, roid) self.remoteRo = ro_remote_metadata.ro_remote_metadata(ro_config, httpsession, rouri) def URIRef(path): return self.remoteRo.getComponentUriAbs(path) def verifyResources(resources): c = 0 for r in self.remoteRo.getAggregatedResources(): if not self.remoteRo.hasResourceType(r, RO.AggregatedAnnotation): c += 1 self.assertIn(r, resources) self.assertEqual(c, len(resources)) return self.remoteRo.aggregateResourceInt("internal/1", "text/plain", "ipsum lorem") self.remoteRo.reloadManifest() self.assertTrue(self.remoteRo.isAggregatedResource("internal/1")) self.assertFalse(self.remoteRo.isAggregatedResource("http://www.google.com")) verifyResources([ URIRef("internal/1") , URIRef(".ro/evo_info.ttl") ]) self.remoteRo.aggregateResourceExt("http://www.google.com") self.remoteRo.reloadManifest() self.assertTrue(self.remoteRo.isAggregatedResource("internal/1")) self.assertTrue(self.remoteRo.isAggregatedResource("http://www.google.com")) verifyResources([ URIRef("internal/1") , URIRef("http://www.google.com") , URIRef(".ro/evo_info.ttl") ]) self.remoteRo.deaggregateResource(URIRef("internal/1")) self.remoteRo.reloadManifest() self.assertFalse(self.remoteRo.isAggregatedResource("internal/1")) self.assertTrue(self.remoteRo.isAggregatedResource("http://www.google.com")) verifyResources([ URIRef("http://www.google.com") , URIRef(".ro/evo_info.ttl") ]) self.remoteRo.deaggregateResource(URIRef("http://www.google.com")) self.remoteRo.reloadManifest() self.assertFalse(self.remoteRo.isAggregatedResource("internal/1")) self.assertFalse(self.remoteRo.isAggregatedResource("http://www.google.com")) verifyResources([ URIRef(".ro/evo_info.ttl") ]) return
def testClassifyAggregatedResources(self): """ Test functions that identify external and internal resource """ httpsession = ROSRS_Session(ro_test_config.ROSRS_URI, ro_test_config.ROSRS_ACCESS_TOKEN) roid = "romanagertest-" + str(uuid.uuid4()) (_, _, rouri, _) = ro_remote_metadata.createRO(httpsession, roid) self.remoteRo = ro_remote_metadata.ro_remote_metadata(ro_config, httpsession, rouri) def URIRef(path): return self.remoteRo.getComponentUriAbs(path) self.remoteRo.aggregateResourceInt("internal/1", "text/plain", "ipsum lorem") self.remoteRo.aggregateResourceExt("http://www.google.com") self.assertTrue(self.remoteRo.isResourceInternal(URIRef("internal/1"))) self.assertFalse(self.remoteRo.isResourceExternal(URIRef("internal/1"))) self.assertFalse(self.remoteRo.isResourceInternal(URIRef("http://www.google.com"))) self.assertTrue(self.remoteRo.isResourceExternal(URIRef("http://www.google.com"))) return
def testPush(self): rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test push", "ro-testRoPush") localRo = ro_metadata(ro_config, rodir) localRo.addAggregatedResources(rodir, recurse=True) # localRo.aggregateResourceExt("http://www.example.org") roresource = "subdir1/subdir1-file.txt" # Add anotations for file ann1 = localRo.addSimpleAnnotation(roresource, "type", "Test file") ann2 = localRo.addSimpleAnnotation(roresource, "description", "File in test research object") ann3 = localRo.addSimpleAnnotation(roresource, "rdf:type", ROTERMS.resource) annotationsCnt = 0 deleteRO(self.rosrs, urlparse.urljoin(self.rosrs.baseuri(), "TestPushRO/")) (_,_,rouri,_) = createRO(self.rosrs, "TestPushRO") remoteRo = ro_remote_metadata(ro_test_config, self.rosrs, rouri) remoteRo.aggregateResourceExt("http://www.anotherexample.org") resourcesInt = ( [ rdflib.URIRef("README-ro-test-1") , rdflib.URIRef("minim.rdf") , rdflib.URIRef("subdir1/subdir1-file.txt") , rdflib.URIRef("subdir2/subdir2-file.txt") , rdflib.URIRef("filename%20with%20spaces.txt") , rdflib.URIRef("filename%23with%23hashes.txt") , rdflib.URIRef(ann1) , rdflib.URIRef(ann2) , rdflib.URIRef(ann3) ]) resourcesIntCnt = 0 for (action, resuri) in ro_rosrs_sync.pushResearchObject(localRo, remoteRo): log.debug("The following object has been pushed: %s (%s)"%(resuri, action)) # this assumes that the above is the only external resource if action == ro_rosrs_sync.ACTION_AGGREGATE_EXTERNAL: self.assertEqual(resuri, rdflib.URIRef("http://www.example.org"), "The external resource is pushed") self.assertTrue(localRo.isAggregatedResource(resuri), "Resource that is pushed is aggregated locally") elif action == ro_rosrs_sync.ACTION_AGGREGATE_INTERNAL: self.assertTrue(localRo.getComponentUriRel(resuri) in resourcesInt, "Resource that is pushed is aggregated locally") resourcesIntCnt += 1 elif action == ro_rosrs_sync.ACTION_DELETE: self.assertFalse(localRo.isAggregatedResource(resuri), "Resource that is deaggregated in ROSRS is not aggregated locally") self.assertEqual(resuri, rdflib.URIRef("http://www.anotherexample.org"), "The external resource is deaggregated (%s)"%resuri) elif action == ro_rosrs_sync.ACTION_AGGREGATE_ANNOTATION: self.assertTrue(localRo.isAnnotationNode(resuri), "Annotation that is pushed is aggregated locally (%s)"%(resuri)) annotationsCnt += 1 elif action == ro_rosrs_sync.ACTION_DELETE_ANNOTATION: self.assertFalse(localRo.isAnnotationNode(resuri), "Annotation that is deaggregated in ROSRS is not aggregated locally") pass elif action == ro_rosrs_sync.ACTION_ERROR: log.warn("Error, not necessarily a fail: %s"%resuri) else: self.fail("Unexpected action %s"%action) self.assertEqual(len(resourcesInt), resourcesIntCnt, "All internal resources were aggregated (should be %d was %d)"%(len(resourcesInt), resourcesIntCnt)) # 3 annotations + manifest which in RO manager also annotates the RO self.assertEqual(4, annotationsCnt, "All annotations were aggregated (should be %d was %d)"%(4, annotationsCnt)) for (action, resuri) in ro_rosrs_sync.pushResearchObject(localRo, remoteRo): if action == ro_rosrs_sync.ACTION_UPDATE_ANNOTATION: self.assertTrue(localRo.isAnnotationNode(resuri), "Annotations that is updated is aggregated locally (%s)"%(resuri)) elif action == ro_rosrs_sync.ACTION_UPDATE_OVERWRITE: # see https://jira.man.poznan.pl/jira/browse/WFE-671 self.assertTrue(resuri in [rdflib.URIRef(ann1), rdflib.URIRef(ann2), rdflib.URIRef(ann3)], "Annotation bodies can be uploaded twice") elif action == ro_rosrs_sync.ACTION_ERROR: log.warn("Error, not necessarily a fail: %s"%resuri) elif not action == ro_rosrs_sync.ACTION_SKIP: self.fail("Nothing else should be pushed again (%s, %s)"%(action, resuri)) # Clean up remoteRo.delete() self.deleteTestRo(rodir) return