def test_check_original_status(self):
     """ This test just check that by default, the value we use are not in the directory
     """
     client = make_client()
     query_data = str(client.get("/").data)
     self.assertNotIn('<script src="//foo.bar/test.js"></script>',
                      query_data, "Templates should not have it by default")
    def test_plugin_assets_in_templates(self):
        client = make_client(PluginAssets(name="One"))
        query_data = str(client.get("/").data)

        jss = [
            "//foo.bar/test.js", "http://bar.foo/test.js",
            "https://super.secure/mypasswordin.js"
        ]
        assert_length_js = len(jss)
        for js in jss:
            self.assertIn('<script src="{0}"></script>'.format(js), query_data,
                          "Templates should correctly link external js")
            assert_length_js -= 1
        self.assertEqual(assert_length_js, 0,
                         "All js file should have been checked")

        csss = [
            "//foo.bar/test.css", "http://bar.foo/test.css",
            "https://super.secure/mypasswordin.css"
        ]
        assert_length_js = len(csss)
        for css in csss:
            self.assertIn('<link rel="stylesheet" href="{0}">'.format(css),
                          query_data,
                          "Templates should correctly link external css")
            assert_length_js -= 1
        self.assertEqual(assert_length_js, 0,
                         "All css files should have been checked")

        self.assertIn(
            '<link rel="stylesheet" href="/assets/nemo.secondary/css/empty.css">',
            query_data, "Secondary Internal CSS should be linked")
        self.assertIn(
            '<script src="/assets/nemo.secondary/js/empty.js"></script>',
            query_data, "Secondary Internal JS should be retrieved")
Example #3
0
    def test_plugin_clear(self):
        """ Test that passage page contains what is relevant : text and next passages """
        plugin = PluginClearRoute(name="normal")
        client = make_client(plugin)

        req = client.get(
            "/text/urn:cts:farsiLit:hafez.divan.perseus-eng1/passage/1.1")
        self.assertEqual(404, req.status_code,
                         "Original routes should not exist anymore")
        query_data = make_client(self.plugin_normal)\
            .get("/doubletext/urn:cts:farsiLit:hafez.divan.perseus-eng1/urn:cts:farsiLit:hafez.divan.perseus-ger1/1.1")\
            .data.decode()
        self.assertIn(
            'Ho ! Saki, pass around and offer the bowl (of love for God)',
            query_data, "English text should be displayed")
        self.assertIn('Finstere Schatten der Nacht!', query_data,
                      "German text should be displayed")
Example #4
0
 def test_plugin_change_render(self):
     """ Check that the augmenting render function works and is correctly plugged
     """
     query_data = make_client(self.plugin_normal)\
         .get("/text/urn:cts:farsiLit:hafez.divan.perseus-eng1/passage/1.1")\
         .data.decode()
     self.assertIn('Other label', query_data,
                   "French Translation should be displayed")
Example #5
0
 def test_page_works(self):
     """ Test that passage page contains what is relevant : text and next passages"""
     query_data = make_client(self.plugin_normal)\
         .get("/doubletext/urn:cts:farsiLit:hafez.divan.perseus-eng1/urn:cts:farsiLit:hafez.divan.perseus-ger1/1.1")\
         .data.decode()
     self.assertIn(
         'Ho ! Saki, pass around and offer the bowl (of love for God)',
         query_data, "English text should be displayed")
     self.assertIn('Finstere Schatten der Nacht!', query_data,
                   "German text should be displayed")
    def test_prevent_clearing_assets(self):
        client = make_client(PluginClearAssets(),
                             prevent_plugin_clearing_assets=True)
        query_data = str(client.get("/assets/nemo/css/theme.min.css").data)
        self.assertIn(
            "body, html", query_data,
            "Nemo Primary Assets should be not served when prevent is on")

        self.assertEqual(
            client.get("/assets/nemo/plugin.css").status_code, 404,
            "Plugin Primary Assets should not be served when prevent is on")
    def test_serving_assets(self):
        """ Ensure plugins assets are served
        """
        client = make_client(PluginAssets())
        query_data = str(
            client.get("/assets/nemo.secondary/css/empty.css").data)
        self.assertIn(".empty {", query_data, "Local CSS File should be read")

        query_data = str(client.get("/assets/nemo.secondary/js/empty.js").data)
        self.assertIn("var empty = True;", query_data,
                      "Local JS File should be read")

        query_data = str(
            client.get("/assets/nemo.secondary/static/fake.png").data)
        self.assertIn("fake", query_data, "Local Static should be read")
Example #8
0
    def test_template_overwrite(self):
        """ Checks that overwriting original templates works
        """
        class PluginTemplate(PluginPrototype):
            TEMPLATES = {"main": "tests/test_data/plugin_templates_main/main"}

        client = make_client(PluginTemplate())
        query_data = client.get(
            "/text/urn:cts:farsiLit:hafez.divan.perseus-eng1/passage/1.1"
        ).data.decode()
        self.assertIn('I am A CONTAINER !', query_data,
                      "Container should have been overwritten")
        query_data = client.get(
            "/collections/urn:cts:farsiLit:hafez").data.decode()
        self.assertIn(
            'I am A CONTAINER !', query_data,
            "Container should have been overwritten on a second page as well")
Example #9
0
    def test_plugin_clear_with_error(self):
        """
            When clearing routes, we need to ensure Flask fails to run
            if there is still some other routes call
        """
        class TempPlugin(PluginClearRoute):
            TEMPLATES = copy(PluginRoute.TEMPLATES)
            ROUTE_TEMPLATES = copy(PluginRoute.ROUTE_TEMPLATES)

        plugin = TempPlugin(name="normal")
        client = make_client(plugin)

        with self.assertRaises(
                werkzeug.routing.BuildError,
                msg="Call to other routes in templates should fail to build"):
            client.get(
                "/doubletext/urn:cts:farsiLit:hafez.divan.perseus-eng1/urn:cts:farsiLit:hafez.divan.perseus-ger1/1.1"
            )
    def test_clearing_assets(self):
        client = make_client(PluginClearAssets())
        query_data = str(
            client.get("/assets/nemo.secondary/css/empty.css").data)
        self.assertIn(".empty {", query_data,
                      "Local Secondary CSS File should be read")

        query_data = str(client.get("/assets/nemo.secondary/js/empty.js").data)
        self.assertIn("var empty = True;", query_data,
                      "Local Secondary JS File should be read")

        query_data = str(client.get("/assets/nemo/plugin.css").data)
        self.assertIn(".pluginstuff", 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):
     self.ann_plugin = AnnotationsApiPlugin(
         name="testplugin", queryinterface=MockQueryInterface(lambda x: x))
     self.client = make_client(self.ann_plugin)
     self.maxDiff = 50000
 def setUp(self):
     self.ann_plugin = AnnotationsApiPlugin(
         name="testplugin", queryinterface=QueryPrototype(lambda x: x))
     self.client = make_client(self.ann_plugin)