def testAddGetAnnotationValues(self): rodir = self.createTestRo(testbase, "data/ro-test-1", "Test get annotation values", "ro-testRoAnnotate") roresource = "subdir1/subdir1-file.txt" # Add anotations for file ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "type", "Test file") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "description", "File in test research object") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "rdf:type", ROTERMS.resource) # Retrieve the anotations values = ro_annotation._getAnnotationValues(ro_config, rodir, ".", "title") self.assertEquals(values.next(), rdflib.Literal('Test get annotation values')) self.assertRaises(StopIteration, values.next) values = ro_annotation._getAnnotationValues(ro_config, rodir, ".", "rdf:type") self.assertEquals(values.next(), RO.ResearchObject) self.assertRaises(StopIteration, values.next) values = ro_annotation._getAnnotationValues(ro_config, rodir, roresource, "type") self.assertEquals(values.next(), rdflib.Literal('Test file')) self.assertRaises(StopIteration, values.next) values = ro_annotation._getAnnotationValues(ro_config, rodir, roresource, "description") self.assertEquals(values.next(), rdflib.Literal('File in test research object')) self.assertRaises(StopIteration, values.next) values = ro_annotation._getAnnotationValues(ro_config, rodir, roresource, "rdf:type") self.assertEquals(values.next(), ROTERMS.resource) self.assertRaises(StopIteration, values.next) # Clean up self.deleteTestRo(rodir) return
def testAddGetRoAnnotations(self): rodir = self.createTestRo(testbase, "data/ro-test-1", "Test add RO annotation", "ro-testRoAnnotate") roresource = "." # Add anotations for RO ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "type", "Research Object") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "note", "Research object created for annotation testing") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "description", "Added description") # Retrieve the anotations annotations = ro_annotation._getRoAnnotations(rodir) rouri = ro_manifest.getRoUri(rodir) expected_annotations = ( [ (rouri, DCTERMS.description, rdflib.Literal('Test add RO annotation')) , (rouri, DCTERMS.title, rdflib.Literal('Test add RO annotation')) , (rouri, DCTERMS.created, rdflib.Literal('unknown')) , (rouri, DCTERMS.creator, rdflib.Literal('Test User')) , (rouri, DCTERMS.identifier, rdflib.Literal('ro-testRoAnnotate')) , (rouri, RDF.type, RO.ResearchObject) , (rouri, DCTERMS.type, rdflib.Literal('Research Object')) , (rouri, ROTERMS.note, rdflib.Literal('Research object created for annotation testing')) , (rouri, DCTERMS.description, rdflib.Literal('Added description')) ]) for i in range(9+4): # Annotations + aggregations next = annotations.next() #log.debug("Next %s"%(repr(next))) if ( next not in expected_annotations and next[1] != DCTERMS.created and next[1] != ORE.aggregates ): self.assertTrue(False, "Not expected (%d) %s"%(i, repr(next))) self.assertRaises(StopIteration, annotations.next) self.deleteTestRo(rodir) return
def testAddGetAllAnnotations(self): rodir = self.createTestRo(testbase, "data/ro-test-1", "Test get all annotations", "ro-testRoAnnotate") roresource = "subdir1/subdir1-file.txt" # Add anotations for file ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "type", "Test file") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "description", "File in test research object") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "note", "Research object file created for annotation testing") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "title", "Test file in RO") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "created", "2011-12-07") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "rdf:type", ROTERMS.resource) # Retrieve the file anotations annotations = ro_annotation.getAllAnnotations(rodir) rouri = ro_manifest.getRoUri(rodir) resourceuri = ro_manifest.getComponentUri(rodir, roresource) log.debug("resourceuri: %s"%(resourceuri)) expected_annotations = ( [ (rouri, DCTERMS.description, rdflib.Literal('Test get all annotations')) , (rouri, DCTERMS.title, rdflib.Literal('Test get all annotations')) , (rouri, DCTERMS.created, rdflib.Literal('unknown')) , (rouri, DCTERMS.creator, rdflib.Literal('Test User')) , (rouri, DCTERMS.identifier, rdflib.Literal('ro-testRoAnnotate')) , (rouri, RDF.type, RO.ResearchObject) , (resourceuri, DCTERMS.type, rdflib.Literal('Test file')) , (resourceuri, DCTERMS.description, rdflib.Literal('File in test research object')) , (resourceuri, ROTERMS.note, rdflib.Literal('Research object file created for annotation testing')) , (resourceuri, DCTERMS.title, rdflib.Literal('Test file in RO')) , (resourceuri, DCTERMS.created, rdflib.Literal('2011-12-07')) , (resourceuri, RDF.type, ROTERMS.resource) ]) for i in range(12+1+6): # Annotations + aggregations next = annotations.next() #log.debug("Next %s"%(repr(next))) if ( next not in expected_annotations and next[1] != DCTERMS.created and next[1] != ORE.aggregates ): self.assertTrue(False, "Not expected (%d) %s"%(i, repr(next))) self.assertRaises(StopIteration, annotations.next) self.deleteTestRo(rodir) return
def testRemoveGetFileAnnotations(self): rodir = self.createTestRo(testbase, "data/ro-test-1", "Test remove file annotation", "ro-testRoAnnotate") roresource = "subdir1/subdir1-file.txt" # Add anotations for file ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "type", "Test file") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "description", "File in test research object") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "note", "Research object file created for annotation testing") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "title", "Test file in RO") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "created", "2011-12-07") ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource, "rdf:type", ROTERMS.resource) # Remove annotations ro_annotation._removeSimpleAnnotation(ro_config, rodir, roresource, "description", "File in test research object") ro_annotation._removeSimpleAnnotation(ro_config, rodir, roresource, "note", None) # Retrieve the file anotations annotations = ro_annotation._getFileAnnotations(rodir, roresource) resourceuri = ro_manifest.getComponentUri(rodir, roresource) log.debug("resourceuri: %s"%(resourceuri)) expected_annotations = ( [ (resourceuri, DCTERMS.type, rdflib.Literal('Test file')) , (resourceuri, DCTERMS.title, rdflib.Literal('Test file in RO')) , (resourceuri, DCTERMS.created, rdflib.Literal('2011-12-07')) , (resourceuri, RDF.type, ROTERMS.resource) ]) for i in range(4): next = annotations.next() #log.debug("Next %s"%(repr(next))) if ( next not in expected_annotations): self.assertTrue(False, "Not expected (%d) %s"%(i, repr(next))) self.assertRaises(StopIteration, annotations.next) self.deleteTestRo(rodir) return