Example #1
0
    def view(self):
        from PyLucid.urls import urls
        self.context["urlpatterns"] = urls
        
        
        # FIXME: This part should be merged into URLs.py, because it's used
        # in a simillar way in show_internals/app_info.py !
        from PyLucid.system.URLs import URLs
        URLs = URLs(self.context)
        
        max_len = max([len(key) for key in URLs])
        line = "%%%ss: '%%s'\n" % max_len

        URLs_info = ""
        for url, key in sorted([(url, key) for key,url in URLs.items()]):
            URLs_info += line % (key, url)
        
        self.context["URLs_info"] = URLs_info


        return self._render(url_info_template)
Example #2
0
 def setUp(self):
     context = get_fake_context()
     self.URLs = URLs(context)
Example #3
0
class UrlsTestCase(tests.TestCase):
    def setUp(self):
        context = get_fake_context()
        self.URLs = URLs(context)

    def test_asserts(self):
        """
        Check the defaults
        """
        self.assertEqual(
            self.URLs["adminBase"], "/%s" % settings.ADMIN_URL_PREFIX
        )
        self.assertEqual(
            self.URLs["hostname"], "http://unitest_HTTP_HOST_fake"
        )
        self.assertEqual(self.URLs["scriptRoot"], "/")
        self.assertEqual(self.URLs["host"], "unitest_HTTP_HOST_fake")
        self.assertEqual(
            self.URLs["absoluteIndex"], "http://unitest_HTTP_HOST_fake/"
        )
        self.assertEqual(self.URLs["docRoot"], "/")
        self.assertEqual(self.URLs["cwd"], os.getcwdu())

    def test_command_base(self):
        self.assertEqual(
            self.URLs.get_command_base(), "/%s/1" % settings.COMMAND_URL_PREFIX
        )

    def test_commandLink(self):
        prefix = "/%s/1" % settings.COMMAND_URL_PREFIX
        self.assertEqual(
            self.URLs.commandLink("plugin_name", "method_name"),
            "%s/plugin_name/method_name/" % prefix
        )
        self.assertEqual(
            self.URLs.commandLink(
                "plugin_name", "method_name", args="parm1"
            ),
            "%s/plugin_name/method_name/parm1/" % prefix
        )
        self.assertEqual(
            self.URLs.commandLink(
                "plugin_name", "method_name", args=("parm1", "parm2")
            ),
            "%s/plugin_name/method_name/parm1/parm2/" % prefix
        )
        self.assertEqual(
            self.URLs.commandLink(
                "plugin_name", "method_name", args=["parm1", "parm2"]
            ),
            "%s/plugin_name/method_name/parm1/parm2/" % prefix
        )
        self.assertEqual(
            self.URLs.commandLink(
                "plugin_name", "method_name", args=1
            ),
            "%s/plugin_name/method_name/1/" % prefix
        )
        self.assertEqual(
            self.URLs.commandLink(
                "plugin_name", "method_name", args=("1",2,3)
            ),
            "%s/plugin_name/method_name/1/2/3/" % prefix
        )


    def test_methodLink(self):
        prefix = "/%s/1/plugin_name" % settings.COMMAND_URL_PREFIX
        self.URLs.current_plugin = "plugin_name"
        self.assertEqual(
            self.URLs.methodLink("method_name"),
            "%s/method_name/" % prefix
        )
        self.assertEqual(
            self.URLs.methodLink("method_name", args="parm1"),
            "%s/method_name/parm1/" % prefix
        )
        self.assertEqual(
            self.URLs.methodLink("method_name", args=["parm1", "parm2"]),
            "%s/method_name/parm1/parm2/" % prefix
        )

    def test_adminLink(self):
        prefix= "/%s" % settings.ADMIN_URL_PREFIX
        self.assertEqual(
            self.URLs.adminLink("test1"),
            "%s/test1/" % prefix
        )
        self.assertEqual(
            self.URLs.adminLink([1,2,3]),
            "%s/1/2/3/" % prefix
        )

    def test_make_absolute_url(self):
        prefix = self.URLs["hostname"]
        self.assertEqual(
            self.URLs.make_absolute_url("test1"),
            "%s/test1/" % prefix
        )
        self.assertEqual(
            self.URLs.make_absolute_url(["test1", "test2"]),
            "%s/test1/test2/" % prefix
        )

    def test_non_ascii(self):
        """
        unicode test
        """
        self.URLs.current_plugin = "plugin_name"
        self.assertEqual(
            self.URLs.methodLink(u"test\xe4\xf6\xfc\xdf"),
            u'/_command/1/plugin_name/test%C3%A4%C3%B6%C3%BC%C3%9F/'
        )
        self.assertEqual(
            self.URLs.methodLink("method_name", args=u"test\xe4\xf6\xfc\xdf"),
            u'/_command/1/plugin_name/method_name/test%C3%A4%C3%B6%C3%BC%C3%9F/'
        )