Exemplo n.º 1
0
  def test_add_slash(self):
    view_paths = [
        (r"^/hello/$", "bad", ()),
        (r"^/winner/$", "good", ()),
        ]

    dispatcher = URLDispatcher(view_paths)

    assert ("good", {}) == dispatcher._parse_url("/winner")
Exemplo n.º 2
0
    def test_add_slash(self):
        view_paths = [
            (r"^/hello/$", "bad", ()),
            (r"^/winner/$", "good", ()),
        ]

        dispatcher = URLDispatcher(view_paths)

        assert ("good", {}) == dispatcher._parse_url("/winner")
Exemplo n.º 3
0
  def test_parse_number(self):
    view_paths = [
        (r"^/hello/$", "bad", ()),
        (r"^/winner/$", "bad", ()),
        (r"^/user/(\d+)/$", "good", ("user_id",)),
        ]

    dispatcher = URLDispatcher(view_paths)

    assert ("good", {"user_id" : '1234'}) == dispatcher._parse_url("/user/1234/")
Exemplo n.º 4
0
    def test_parse_number(self):
        view_paths = [
            (r"^/hello/$", "bad", ()),
            (r"^/winner/$", "bad", ()),
            (r"^/user/(\d+)/$", "good", ("user_id", )),
        ]

        dispatcher = URLDispatcher(view_paths)

        assert ("good", {
            "user_id": '1234'
        }) == dispatcher._parse_url("/user/1234/")
Exemplo n.º 5
0
    def test_call(self):
        def func(pipeline, environ, start_response):
            assert environ['pythia']['url_params']['user_id'] == '1234'
            return "func"

        view_paths = [
            (r"^/user/(\d+)/$", func, ("user_id", )),
        ]

        dispatcher = URLDispatcher(view_paths)

        environ = {"PATH_INFO": "/user/1234"}

        assert "func" == dispatcher(Pipeline(), environ, None)
Exemplo n.º 6
0
    def __init__(self, settings):
        self.settings = settings
        self.chain = self.settings.pre_views
        self.chain.append(URLDispatcher(self.settings.view_paths))
        loaders = {
            "pythia": PackageLoader('pythia', 'views/templates'),
            settings.app_pkg: PackageLoader(settings.app_pkg,
                                            settings.templates),
        }
        self.jinja_env = Environment(loader=PrefixLoader(loaders))
        self.jinja_env.globals['app_name'] = settings.app_name

        try:
            error_handler = ExceptionHandler(
                override_handlers=self.settings.error_handlers)
        except AttributeError:
            error_handler = ExceptionHandler()

        self.chain.insert(0, error_handler)