class TestResolverWithRetriever(TestCase): """ Ensure retrievers stacks well """ def setUp(self): self.resolver = Resolver(CTSRetriever(resolver=NautilusDummy), HTTPRetriever(), LocalRetriever(path="./tests/test_data")) def test_stack(self): uris = [("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "CTS Retriever should be resolved", CTSRetriever), ("http://foo.com/bar", "HTTP retriever should match the URI", HTTPRetriever), ("../test_data/empty.js", "Local Retriever should match complex URIs", LocalRetriever), ("assets/fake.png", "Local Retriever should match simple URIs", LocalRetriever)] i = len(uris) for uri, msg, type_retriever in uris: self.assertEqual(type(self.resolver.resolve(uri)), type_retriever, msg) i -= 1 self.assertEqual(i, 0, "All tests have been run") def test_stack_fails(self): """ Ensure that it still raises for unaccepted """ with self.assertRaises(UnresolvableURIError, msg="Not safe file should fail"): self.resolver.resolve("../setup.py")
def setUp(self): self.fakegetreffs = lambda x: x self.retrieverproto = RetrieverPrototype() self.resolver = Resolver(self.retrieverproto) self.fakeurn = MyCapytain.common.reference.URN( "urn:cts:greekLit:tlg0012.tlg001.perseus-grc1") self.faketarget = self.fakeurn
def setUp(self): self.resolver = Resolver(LocalRetriever(path="./tests/test_data/")) self.one = (URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1"), "interface/treebanks/treebank1.xml", "dc:treebank") self.two = (URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.5"), "interface/treebanks/treebank2.xml", "dc:treebank") self.three = (URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1"), "interface/images/N0060308_TIFF_145_145.tif", "dc:image") self.four = AnnotationResource( "interface/researchobject/researchobject.json", type_uri="dc:researchobject", target=URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr.1"), resolver=self.resolver) self.one_anno = AnnotationResource(self.one[1], type_uri=self.one[2], target=self.one[0], resolver=self.resolver) self.two_anno = AnnotationResource(self.two[1], type_uri=self.two[2], target=self.two[0], resolver=self.resolver) self.three_anno = AnnotationResource(self.three[1], type_uri=self.three[2], target=self.three[0], resolver=self.resolver) self.fourth_anno = AnnotationResource( self.three[1], type_uri=self.three[2], target=("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1-2"), resolver=self.resolver) self.app = Flask("app") logger = logging.getLogger('my-logger') logger.propagate = False self.nautilus = CtsCapitainsLocalResolver( ["tests/test_data/interface/latinLit"], logger=logger) self.nemo = Nemo(app=self.app, resolver=self.nautilus, base_url="") self.query = SimpleQuery( [self.one, self.two, self.three, self.four], # List of annotations self.resolver) self.query.process(self.nemo)
def setUp(self): self.resolver = Resolver( RetrieverMock ) self.params_1 = [ "http://localhost", URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2"), "http://foo.bar/treebank", self.resolver, Target, "application/xml", "treebank" ] self.params_2 = [ "http://localhost1", {"urn": URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2")}, "http://foo.bar/treebank1", self.resolver, WTarget, "application/xml1", "treebank1" ]
def setUp(self): self.resolver = Resolver(CTSRetriever(resolver=NautilusDummy), HTTPRetriever(), LocalRetriever(path="./tests/test_data"))
class TestQuery(TestCase): """ Test query """ def setUp(self): self.fakegetreffs = lambda x: x self.retrieverproto = RetrieverPrototype() self.resolver = Resolver(self.retrieverproto) self.fakeurn = MyCapytain.common.reference.URN( "urn:cts:greekLit:tlg0012.tlg001.perseus-grc1") self.faketarget = self.fakeurn def test_query_prototype(self): """ Test that the query prototype returns nothing """ self.assertEqual( (0, []), QueryPrototype(self.fakegetreffs).getAnnotations(self.fakeurn)) def test_query_prototype_get_resource(self): """ Test that the query prototype returns nothing """ self.assertEqual(None, QueryPrototype(self.fakegetreffs).getResource("any")) def test_retriever_prototype_read(self): """ Test that the retriever prototype reads nothing """ self.assertEqual( (None, "text/xml"), self.retrieverproto.read("http://example.org"), "Default response when there is nothing is a None object for prototype" ) def test_retriever_prototype_match(self): """ Test that the retriever prototype matches nothing """ self.assertEqual(False, RetrieverPrototype().match("http://example.org")) def test_resolver(self): """ Test that the default resolver, configured with retriever prototype, raises an exception on resolve """ with self.assertRaises(UnresolvableURIError, msg="Default resolver should raise exception"): self.resolver.resolve("http://example.org") def test_target_urn(self): """ Test that a target returns its urn property """ self.assertEqual(str(self.fakeurn), Target(self.fakeurn).objectId) def test_target_json(self): """Default target have a string as json representation""" self.assertEqual( Target("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.2.3").to_json(), { "source": "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "selector": { "type": "FragmentSelector", "conformsTo": "http://ontology-dts.org/terms/subreference", "value": "1.2.3" } }, "Default target have a string as json representation") def test_annotation_resource_read(self): """ Test that an annotation resource with default resolver raises an exception on read """ annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) with self.assertRaises(UnresolvableURIError): annotation.read() def test_annotation_resource_expand(self): """ Test that an annotation resource expands to empty list """ annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertEqual([], annotation.expand(), "Expand should return a list") def test_annotation_resource_expandable_property(self): """ Test that an annotation resource is not expandable """ annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertFalse(annotation.expandable, msg="Default annotation should not be expandable") def test_annotation_resource_uri_property(self): """ Test that an annotation resource returns its uri """ annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertEqual("http://example.org/annotation", annotation.uri, "Annotation uri property should read correctly") def test_annotation_resource_type_uri_property(self): """ Test that an annotation resource returns its uri type""" annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertEqual("http://data.perseus.org/rdfvocab/fake", annotation.type_uri, "Annotation type_uri should read correctly") def test_annotation_resource_sha_property(self): """ Test that an annotation resource returns its uri type""" annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertEqual( "fb6737b46ba8b9d8cd7d486c348275c07b017bbb748a63c673a9b685acf0a859", annotation.sha, "Annotation sha should be stable") def test_annotation_resource_slug_property(self): """ Test that an annotation resource returns its slug""" annotation = AnnotationResource( "http://example.org/annotation", self.faketarget, "http://data.perseus.org/rdfvocab/fake", self.resolver) self.assertEqual("annotation", annotation.slug, "Annotation slug should read correctly")
("urn:cts:aperire:delver.init.opp-lat1:6.1", "http://sosol.perseids.org/sosol/dmm_api/item/TreebankCite/36281", "http://data.perseus.org/rdfvocab/treebank"), ("urn:cts:aperire:delver.init.opp-lat1:6.2", "http://sosol.perseids.org/sosol/dmm_api/item/TreebankCite/36282", "http://data.perseus.org/rdfvocab/treebank"), ("urn:cts:aperire:delver.init.opp-lat1:7.1", "http://sosol.perseids.org/sosol/dmm_api/item/TreebankCite/36283", "http://data.perseus.org/rdfvocab/treebank"), ("urn:cts:aperire:delver.init.opp-lat1:7.2", "http://sosol.perseids.org/sosol/dmm_api/item/TreebankCite/36284", "http://data.perseus.org/rdfvocab/treebank"), ("urn:cts:aperire:delver.init.opp-lat1:8.1", "http://sosol.perseids.org/sosol/dmm_api/item/TreebankCite/36521", "http://data.perseus.org/rdfvocab/treebank")], resolver=Resolver(HTTPRetriever())) # We set up Nemo nemo = Nemo(app=app, name="nemo", base_url="", api_url="/api/cts", retriever=nautilus.retriever, plugins=[Arethusa(queryinterface=query), AperireUI()], chunker={"default": lesson_chunker}, transform={ "default": resource_filename("aperire_ui", "data/assets/static/xslt/epidocShort.xsl") })