コード例 #1
0
    def test_retrieve_resource(self):
        """ Ensure LocalRetriever actually get resource
        """
        ret = LocalRetriever(path="./tests/test_data")
        uris = [
            ("../test_data/empty.js", "var empty = True;",
             "application/javascript", False),
            ("assets/fake.png", "fake", "image/png", True),
        ]
        i = len(uris)
        for uri, content, mime, sendfile in uris:
            i -= 1
            if sendfile:
                with patch("flask_nemo.query.resolve.send_file",
                           return_value=content) as patched:
                    data, mimetype = ret.read(uri)
                    patched.assert_called_with(ret.__absolute__(uri))
            else:
                data, mimetype = ret.read(uri)

            self.assertIn(data, content, "Content of the file should be read")

            self.assertEqual(mimetype, mime,
                             "Mime should be correctly guessed")

        self.assertEqual(i, 0, "All tests should have been run")
コード例 #2
0
    def test_matching(self):
        """ Test the Local retriever matching
        """
        localretriever = LocalRetriever(path="./tests/test_data")
        tests = [("urn:cts:latinLit:phi1294:phi002.perseus-lat2", False,
                  "URN should not match"),
                 ("http://foo.com/bar", False, "URL should not match"),
                 ("../test_data/empty.js", True, "File match and exists"),
                 ("assets/fake.png", True, "File match and exists"),
                 ("./something.html", False, "File is not in path"),
                 ("../setup.py", False, "File out of path should not match"),
                 ("something.html", False, "File does not exist")]
        i = len(tests)
        for uri, matching, msg in tests:
            i -= 1

            self.assertEqual(localretriever.match(uri), matching, msg)

        self.assertEqual(i, 0, "All tests should have been run")
コード例 #3
0
 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)
コード例 #4
0
 def setUp(self):
     self.resolver = Resolver(CTSRetriever(resolver=NautilusDummy),
                              HTTPRetriever(),
                              LocalRetriever(path="./tests/test_data"))