def test_level_grouper(self):
        """ Test level grouper
        """
        text = self.inventory["urn:cts:latinLit:phi1294.phi002.perseus-lat2"]
        curated_references = level_grouper(
            text,
            lambda level: NautilusDummy.getReffs(
                'urn:cts:latinLit:phi1294.phi002.perseus-lat2', level=level),
            level=2,
            groupby=10)

        self.assertIn(('1.pr-1.9', '1.pr-1.9'), curated_references)
        self.assertIn(('2.pr-2.9', '2.pr-2.9'), curated_references)
        self.assertIn(('2.90-2.93', '2.90-2.93'), curated_references)
        """
            Second part of the test
        """

        curated_references = level_grouper(
            text,
            lambda level: NautilusDummy.getReffs(
                'urn:cts:latinLit:phi1294.phi002.perseus-lat2', level=level),
            level=3,
            groupby=10)

        self.assertIn(("1.pr.1-1.pr.10", "1.pr.1-1.pr.10"), curated_references)
        self.assertIn(("2.1.1-2.1.10", "2.1.1-2.1.10"), curated_references)
        self.assertIn(("2.1.11-2.1.12", "2.1.11-2.1.12"), curated_references)
 def test_first_passage(self):
     tests = 0
     uris = [
         ("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.1-1.pr.20"),
         ("urn:cts:latinLit:phi1318.phi001.perseus-unk2", "8.pr.1-8.pr.20"),
         ("urn:cts:farsiLit:hafez.divan.perseus-ger1", "1.1.1.1-1.1.1.4")
     ]
     app = Flask("Nemo")
     _ = self.make_nemo(app=app,
                        base_url="",
                        resolver=NautilusDummy,
                        original_breadcrumb=False,
                        chunker={
                            "default":
                            lambda x, y: level_grouper(x, y, groupby=20)
                        })
     client = app.test_client()
     for oId, psg in uris:
         r = client.get("/text/{}/passage".format(oId))
         self.assertIn("/text/{}/passage/{}/".format(oId, psg), r.location,
                       "check that the path changed")
         tests += 1
     self.assertEqual(
         tests, len(uris),
         "There should be as much ran tests as there is tests")
示例#3
0
    def runner(method, address, port, host, css, xslt, groupby, debug):
        resolver = None
        app = Flask(__name__)
        if method == "cts-api":
            resolver = HttpCtsResolver(HttpCtsRetriever(address))
        elif method == "cts-local":
            resolver = CtsCapitainsLocalResolver([address])
        if xslt is not None:
            xslt = {"default": xslt}
        # We set up Nemo
        nemo = Nemo(app=app,
                    name="nemo",
                    base_url="",
                    css=css,
                    transform=xslt,
                    resolver=resolver,
                    chunker={
                        "default":
                        lambda x, y: level_grouper(x, y, groupby=groupby)
                    })

        # We run the app
        app.debug = debug
        app.run(port=port, host=host)
        # For test purposes
        return nemo, app
    def setUp(self):
        TB_URI = "http://data.perseus.org/rdfvocab/treebank"

        app = Flask("Nemo")
        app.debug = True
        self.interface = SimpleQuery(
            [
                ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "treebanks/treebank1.xml", TB_URI),
                ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.5", "treebanks/treebank2.xml", TB_URI),
                ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "images/N0060308_TIFF_145_145.tif", "dc:image"),
                ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.2", "images/N0060308_TIFF_145_145.tif", "dc:image")
            ],
            resolver=Resolver(LocalRetriever(path="./tests/test_data/"))
        )
        self.arethusa = Arethusa(queryinterface=self.interface)
        app.debug = True
        nemo = Nemo(
            app=app,
            base_url="",
            retriever=NautilusDummy,
            chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
            plugins=[self.arethusa]
        )
        self.interface.process(nemo)
        self.client = app.test_client()
示例#5
0
    def chunker(text, getreffs):
        # We build a the citation type
        citation_types = get_citation_scheme(text)
        identifier = str(text.id)
        config = ChunkerConfig(1, "{passage}", 1)
        changed_config = False

        if identifier in hardcoded_systems:
            return hardcoded_systems[identifier]

        for identifier_regexp in identifier_regexps:
            if identifier_regexp.regexp.match(identifier):
                config = identifier_regexp.config
                changed_config = True

        if not changed_config:
            for citation_sytem in citation_sytems:
                if citation_sytem.system.split(",") == citation_types:
                    config = citation_sytem.config

        if config.group_by > 1:
            reffs = [
                r for r, _ in level_grouper(text, getreffs, config.level,
                                            config.group_by)
            ]
        else:
            reffs = getreffs(level=config.level)

        reffs = [(reff, config.name_template.format(passage=reff))
                 for reff in reffs]

        return reffs
    def test_caching_plugin_route(self):
        class ReplaceTemplate(PluginPrototype):
            ROUTES = [("/square/<int:x>", "r_square", ["GET"]),
                      ("/random", "r_random", ["GET"])]
            CACHED = ["r_square", "r_random"]

            def r_square(self, x):
                return "Square : %s" % (x * x)

            def r_random(self):
                return "%s" % randint(0, 900000)

        app = Flask("Nemo")
        _ = self.make_nemo(app=app,
                           base_url="",
                           resolver=NautilusDummy,
                           chunker={
                               "default":
                               lambda x, y: level_grouper(x, y, groupby=30)
                           },
                           plugins=[ReplaceTemplate("ThisIsMyName")])
        app.debug = True
        client = app.test_client()
        self.assertIn('Square : 100',
                      client.get("/square/10").data.decode(),
                      "There should square ")
        sets = [client.get("/random").data.decode() for _ in range(0, 50)]
        if isinstance(self, NemoTestBrowseWithCache):
            self.assertEqual(len(set(sets)), 1,
                             "Random has been cached and is not recomputed")
        else:
            self.assertGreater(len(set(sets)), 1,
                               "Random has been cached and is not recomputed")
示例#7
0
def scheme_grouper(text, getreffs):
    level = len(text.citation)
    groupby = 100 
    types = [citation.name for citation in text.citation]

    if 'word' in types:
        types = types[:types.index("word")]
    if str(text.id) == "urn:cts:latinLit:stoa0040.stoa062.opp-lat1":
        level, groupby = 1, 2
    elif types == ["vers", "mot"]:
        level, groupby = 1, 100
    elif types == ["book", "poem", "line"]:
        level, groupby = 2, 1
    elif types == ["book", "line"]:
        level, groupby = 2, 30
    elif types == ["book", "chapter"]:
        level, groupby = 2, 1
    elif types == ["book"]:
        level, groupby = 1, 1
    elif types == ["line"]:
        level, groupby = 1, 30
    elif types == ["chapter", "section"]:
        level, groupby = 2, 2
    elif types == ["chapter", "mishnah"]:
        level, groupby = 2, 1
    elif types == ["chapter", "verse"]:
        level, groupby = 2, 1
    elif "line" in types:
        groupby = 30
    return level_grouper(text, getreffs, level, groupby)
 def test_get_siblings(self):
     """ Test first passage
     """
     app = Flask("Nemo")
     nemo = Nemo(app=app,
                 base_url="",
                 resolver=NautilusDummy,
                 original_breadcrumb=False,
                 chunker={
                     "default": lambda x, y: level_grouper(x, y, groupby=20)
                 })
     # First range
     p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                          "1.pr.1-1.pr.20")
     l, r = nemo.get_siblings(
         "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.1-1.pr.20",
         p)
     self.assertEqual(l, None, "There should be nothing on the left")
     self.assertEqual(r, "1.pr.21-1.pr.22",
                      "Next passage should not be 20 long")
     # Second range
     p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                          "1.pr.21-1.pr.22")
     l, r = nemo.get_siblings(
         "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.21-1.pr.22",
         p)
     self.assertEqual(l, "1.pr.1-1.pr.20",
                      "There should be something on the left")
     self.assertEqual(r, "1.1.1-1.1.6",
                      "Next passage should not be 20 long")
     # Last range
     p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                          "14.223.1-14.223.2")
     l, r = nemo.get_siblings(
         "urn:cts:latinLit:phi1294.phi002.perseus-lat2",
         "14.223.1-14.223.2", p)
     self.assertEqual(l, "14.222.1-14.222.2",
                      "Previous passage does not have to be 20 long")
     self.assertEqual(r, None, "There should be nothing on the right")
     # Passage with unknown range
     p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                          "1.11.1-1.11.2")
     l, r = nemo.get_siblings(
         "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.11.1-1.11.2", p)
     self.assertEqual(
         l, ('1.10.3', '1.10.4'),
         "Passage should be computed specifically if texts have unknown range"
     )
     self.assertEqual(
         r, ("1.11.3", "1.11.4"),
         "Passage should be computed specifically if texts have unknown range"
     )
示例#9
0
def make_client(*args, **kwargs):
    app = Flask("Nemo")
    app.debug = True
    if len(args):
        nemo = Nemo(app=app,
                    base_url="",
                    resolver=NautilusDummy,
                    chunker={
                        "default": lambda x, y: level_grouper(x, y, groupby=30)
                    },
                    plugins=list(args),
                    **kwargs)
    else:
        nemo = Nemo(app=app,
                    base_url="",
                    resolver=NautilusDummy,
                    chunker={
                        "default": lambda x, y: level_grouper(x, y, groupby=30)
                    },
                    plugins=None,
                    **kwargs)
    return app.test_client()
示例#10
0
    def setUp(self):
        app = Flask("Nemo")
        app.debug = True
        self.nemo = self.make_nemo(
            app=app,
            base_url="",
            resolver=NautilusDummy,
            chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
            plugins=[CTSLeipzigUI("123google")],
            transform={
                "default": resource_filename("cts_leipzig_ui", "data/assets/static/xslt/epidocShort.xsl")
            },
        )

        self.client = app.test_client()
示例#11
0
    def setUp(self):

        app = Flask("Nemo")
        app.secret_key="Test"
        app.debug = True
        self.auth_url = "https://example.org/123/auth"
        self.oauth = NemoOauthPlugin(app,name='perseids',oauth_access_token_url="https://example.org/123/login",
                                     oauth_authorize_url=self.auth_url,
                                     oauth_base_api_url="https://example.org/123/api",
                                     oauth_key='api_key',oauth_scope='read',oauth_secret='api_secret')
        nemo = Nemo(
            app=app,
            base_url="",
            chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
            plugins=[self.oauth]
        )
        self.client = app.test_client()
示例#12
0
def generic_chunker(text, getreffs):
    # We build a the citation type
    citation_types = get_citation_scheme(text)
    if "poem" in citation_types:
        level = citation_types.index("poem") + 1
        level_name = "Poem"
        excerpt_length = 1
    else:
        level = len(citation_types)
        level_name = citation_types[-1]
        excerpt_length = 20

    if excerpt_length > 1:
        reffs = level_grouper(text, getreffs, level, excerpt_length)
    else:
        reffs = getreffs(level=level)
        reffs = [(str(reff), level_name + " " + str(reff)) for reff in reffs]

    return reffs
示例#13
0
def scheme_grouper(text, getreffs):
    level = len(text.citation)
    groupby = 5
    types = [citation.name for citation in text.citation]

    if types == ["book", "poem", "line"]:
        level, groupby = 2, 1
    elif types == ["book", "line"]:
        level, groupby = 2, 30
    elif types == ["book", "chapter"]:
        level, groupby = 2, 1
    elif types == ["book"]:
        level, groupby = 1, 1
    elif types == ["line"]:
        level, groupby = 1, 30
    elif types == ["chapter", "section"]:
        level, groupby = 2, 2
    elif "line" in types:
        groupby = 30
    return level_grouper(text, getreffs, level, groupby)
示例#14
0
    def test_cache_options(self):
        class ReplaceTemplate(PluginPrototype):
            TEMPLATES = {"main": "./tests/test_data/cache_templates/main"}

        app = Flask("Nemo")
        _ = self.make_nemo(app=app,
                           base_url="",
                           resolver=NautilusDummy,
                           chunker={
                               "default":
                               lambda x, y: level_grouper(x, y, groupby=30)
                           },
                           plugins=[ReplaceTemplate("ThisIsMyName")])
        app.debug = True
        client = app.test_client()
        self.assertIn('<title>I am A CONTAINER ! Isn\'t it sweet !</title>',
                      client.get("/").data.decode(),
                      "There should be the new title")
        self.assertIn("I AM NO LOGO",
                      client.get("/").data.decode(), "There should be no logo")
    def test_serving_overwritten_primary_assets(self):
        """ Ensure primary assets are served
        """
        app = Flask("Nemo")
        app.debug = True
        nemo = Nemo(
            app=app,
            base_url="",
            retriever=NautilusDummy,
            chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
            static_folder="tests/test_data/assets"
        )

        client = app.test_client()
        query_data = str(client.get("/assets/nemo/fake.png").data)
        self.assertIn("fake", query_data, "Primary Assets should be served when overwritting")

        self.assertEqual(
            client.get("/assets/nemo/css/theme.min.css").status_code, 404,
            "Old Primary Assets should not be served when overwritting"
        )
示例#16
0
    def test_serving_overwritten_primary_assets(self):
        """ Ensure primary assets are served
        """
        app = Flask("Nemo")
        app.debug = True
        nemo = self.make_nemo(app=app,
                              base_url="",
                              resolver=NautilusDummy,
                              chunker={
                                  "default":
                                  lambda x, y: level_grouper(x, y, groupby=30)
                              },
                              static_folder="tests/test_data/assets")

        client = app.test_client()
        query_data = str(client.get("/assets/nemo/fake.png").data)
        self.assertIn("fake", query_data,
                      "Primary Assets should be served when overwritting")

        self.assertEqual(
            client.get("/assets/nemo/css/theme.min.css").status_code, 404,
            "Old Primary Assets should not be served when overwritting")
    def setUp(self):
        app = Flask("Nemo")
        app.debug = True
        nemo = Nemo(
            app=app,
            base_url="",
            retriever=NautilusDummy,
            chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
            css=[
                "./tests/test_data/empty.css",
                "//foo.bar/test.css",
                "http://bar.foo/test.css",
                "https://super.secure/mypasswordin.css"
            ],
            js=[
                "./tests/test_data/empty.js",
                "//foo.bar/test.js",
                "http://bar.foo/test.js",
                "https://super.secure/mypasswordin.js"
            ],
        )

        self.client = app.test_client()
示例#18
0
    def setUp(self):
        app = Flask("Nemo")
        app.debug = True
        self.nemo = self.make_nemo(
            app=app,
            base_url="",
            resolver=NautilusDummy,
            chunker={
                "default": lambda x, y: level_grouper(x, y, groupby=30)
            },
            css=[
                "./tests/test_data/empty.css", "//foo.bar/test.css",
                "http://bar.foo/test.css",
                "https://super.secure/mypasswordin.css"
            ],
            js=[
                "./tests/test_data/empty.js", "//foo.bar/test.js",
                "http://bar.foo/test.js",
                "https://super.secure/mypasswordin.js"
            ],
        )

        self.client = app.test_client()
示例#19
0
 def test_first_passage(self):
     tests = 0
     uris = [
         ("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.1-1.pr.20"),
         ("urn:cts:latinLit:phi1318.phi001.perseus-unk2", "8.pr.1-8.pr.20"),
         ("urn:cts:farsiLit:hafez.divan.perseus-ger1", "1.1.1.1-1.1.1.4")
     ]
     app = Flask("Nemo")
     _ = self.make_nemo(
         app=app,
         base_url="",
         resolver=NautilusDummy,
         original_breadcrumb=False,
         chunker={"default": lambda x, y: level_grouper(x, y, groupby=20)}
     )
     client = app.test_client()
     for oId, psg in uris:
         r = client.get("/text/{}/passage".format(oId))
         self.assertIn(
             "/text/{}/passage/{}/".format(oId, psg), r.location,
             "check that the path changed"
         )
         tests += 1
     self.assertEqual(tests, len(uris), "There should be as much ran tests as there is tests")
示例#20
0
from nemo_arethusa_plugin import Arethusa
from flask_nemo.query.interface import SimpleQuery
from capitains_nautilus.mycapytain import NautilusRetriever

TB_URI = "http://data.perseus.org/rdfvocab/treebank"
NautilusDummy = NautilusRetriever(
    folders=[
        "./tests/test_data/latinLit"
    ]
)

app = Flask("Nemo")
app.debug = True
query = SimpleQuery(
    [
        ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "treebanks/treebank1.xml", TB_URI),
        ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.5", "treebanks/treebank2.xml", TB_URI),
        ("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "images/N0060308_TIFF_145_145.tif", "dc:image")
    ],
    resolver=Resolver(LocalRetriever(path="./tests/test_data/"))
)
nemo = Nemo(
    app=app,
    base_url="",
    retriever=NautilusDummy,
    chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
    plugins=[Arethusa(queryinterface=query)]
)
query.process(nemo)
app.run()