示例#1
0
 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()
示例#2
0
 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_target_expand(self):
     """ Ensure existing method and default behaviour
     """
     anno = AnnotationResource(
         *self.params_2
     )
     self.assertEqual(
         anno.expand(), [],
         "Default annotation should expand to an eempty list"
     )
示例#4
0
 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")
示例#5
0
 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")
    def test_read(self):
        """ Ensure existing method and default behaviour

        See the mocked resolver at the beginning of the file
        """
        anno = AnnotationResource(
            *self.params_2
        )
        self.assertEqual(
            anno.read(), anno.uri+" has been read",
            "Default annotation should expand to an empty list"
        )
        self.assertEqual(
            anno.mimetype, "mimetype",
            ".read() should update mimetype"
        )
示例#7
0
 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_target_alias(self):
     """ Ensure alias class can be overwritten
     """
     anno = AnnotationResource(
         *self.params_2
     )
     self.assertIsInstance(
         anno.target, WTarget,
         "Target should be built through annotation alias class target_class param"
     )
class MockQueryInterface(QueryPrototype):
    ANNOTATION = AnnotationResource(
        "uri",
        ("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1"),
        "http://foo.bar/treebank",
        resolver=None,  # Overwriting this one for the purpose of the test
        mimetype="application/xml",
        slug="treebank")
    ANNOTATION2 = AnnotationResource(
        "uri2",
        ("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "2"),
        "http://foo.bar/treebank",
        resolver=None,  # Overwriting this one for the purpose of the test
        mimetype="application/json",
        slug="treebank")

    def getAnnotations(self,
                       targets,
                       wildcard=".",
                       include=None,
                       exclude=None,
                       limit=None,
                       start=1,
                       expand=False,
                       **kwargs):
        if targets == None:
            return 2, [type(self).ANNOTATION, type(self).ANNOTATION2]
        else:
            return 1, [type(self).ANNOTATION]

    def getResource(self, sha):
        annotation = type(self).ANNOTATION
        if sha == "abc":
            annotation.read = lambda: Response(
                "a", headers={"Content-Type": "text/plain"})
            annotation.read = lambda: Response(
                "a", headers={"Content-Type": "text/plain"})
        else:
            annotation.__mimetype__ = "application/xml"
            annotation.read = lambda: "123"
        return annotation
 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)
示例#11
0
    def __init__(self, annotations, resolver=None):
        super(SimpleQuery, self).__init__(None)
        self._annotations = []
        self._nemo = None
        self._resolver = resolver

        for resource in annotations:
            if isinstance(resource, tuple):
                target, body, type_uri = resource
                self._annotations.append(
                    AnnotationResource(body, target, type_uri, self._resolver))
            else:
                self._annotations.append(resource)
 def test_init_and_properties(self):
     """ Ensure init values are taken into account
     """
     anno = AnnotationResource(
         *self.params_1
     )
     self.assertEqual(
         anno.mimetype, "application/xml",
         "Mimetype should be set with init params"
     )
     self.assertEqual(
         anno.slug, "treebank",
         "Slug should be set with init params"
     )
     self.assertEqual(
         anno.sha, "a076083ce9233ea6bb5263109d05d0780261c992c83c0a5787d79d9f62c71266",
         "Sha should be set with init params"
     )
     self.assertEqual(
         anno.type_uri, "http://foo.bar/treebank",
         "Type URI should be set with init params"
     )
     self.assertEqual(
         anno.uri, "http://localhost",
         "URI should be set with init params"
     )
     self.assertEqual(
         str(anno.target.objectId), "urn:cts:latinLit:phi1294.phi002.perseus-lat2",
         "Target should be set with init params"
     )
     self.assertIsInstance(
         anno.target, Target,
         "Target alias should be used"
     )
     self.assertEqual(
         anno.expandable, False,
         "Default annotation resource are not expandable"
     )