Ejemplo n.º 1
0
    def test_req_resp_handler_vargs_kwargs_convention(self):
        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1",
            CONVENTION_PARAMS)
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1"], params)

        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
            CONVENTION_PARAMS)
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"],
                             params)

        fcn, params = router.to_handler(
            "/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
            CONVENTION_PARAMS,
            param1="blah",
            param2="foo")
        self.assertEqual(
            first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"],
                             params)
Ejemplo n.º 2
0
    def test_complete_path_with_params(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_params/1/%C3%A7ao%40%26%20")
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1", "çao@& "], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_params/1", param2=2)
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1"], params)
Ejemplo n.º 3
0
    def test_complete_path_with_params(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_params/1/%C3%A7ao%40%26%20")
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1", "çao@& "], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_params/1", param2=2)
        self.assertEqual(pack_handler.with_params, fcn)
        self.assertListEqual(["1"], params)
Ejemplo n.º 4
0
    def test_complete_path_with_varargs_and_kwargs(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1", blah=2)
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1/2")
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1/2/3")
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1", "2", "3"], params)
Ejemplo n.º 5
0
    def test_complete_path_with_varargs_and_kwargs(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1", blah=2)
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1/2")
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_kwargs/1/2/3")
        self.assertEqual(pack_handler.with_kwargs, fcn)
        self.assertListEqual(["1", "2", "3"], params)
Ejemplo n.º 6
0
    def test_req_resp_handler_vargs_kwargs_convention(self):
        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1", CONVENTION_PARAMS)
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1"], params)

        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
                                        CONVENTION_PARAMS)
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"], params)

        fcn, params = router.to_handler("/first_handler/fcn_req_resp_handler_default_vargs_kwargs/1/2/3",
                                        CONVENTION_PARAMS, param1="blah", param2="foo")
        self.assertEqual(first_handler.fcn_req_resp_handler_default_vargs_kwargs, fcn)
        self.assertListEqual([REQUEST, RESPONSE, HANDLER, "1", "2", "3"], params)
Ejemplo n.º 7
0
    def test_complete_path_with_defaults(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_defaults")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1/2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults", param1="1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)
Ejemplo n.º 8
0
    def test_complete_path_with_defaults(self):
        fcn, params = router.to_handler("/pack/pack_handler/with_defaults")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1/2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1", "2"], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults", param1="1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual([], params)

        fcn, params = router.to_handler("/pack/pack_handler/with_defaults/1", param2="2")
        self.assertEqual(pack_handler.with_defaults, fcn)
        self.assertListEqual(["1"], params)
Ejemplo n.º 9
0
def execute(next_process, handler, dependencies, **kwargs):
    fcn, params = router.to_handler(handler.request.path, dependencies, **kwargs)
    fcn(*params, **kwargs)
    next_process(dependencies, **kwargs)
Ejemplo n.º 10
0
 def set_up(self):
     fcn, path_args = router.to_handler(self.handler.request.path,
                                        self.dependencies,
                                        **self.request_args)
     self.dependencies['_fcn'] = fcn
     self.dependencies['_path_args'] = path_args
Ejemplo n.º 11
0
def execute(next_process, handler, dependencies, **kwargs):
    fcn, params = router.to_handler(handler.request.path, dependencies,
                                    **kwargs)
    fcn(*params, **kwargs)
    next_process(dependencies, **kwargs)
Ejemplo n.º 12
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
Ejemplo n.º 13
0
    def test_root(self):
        fcn, params = router.to_handler("/", CONVENTION_PARAMS)
        self.assertEqual(home.index, fcn)

        fcn, params = router.to_handler("/pack", CONVENTION_PARAMS)
        self.assertEqual(pack_home.index, fcn)
Ejemplo n.º 14
0
 def test_resp_handler_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_resp_handler/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_resp_handler, fcn)
     self.assertListEqual([RESPONSE, HANDLER, "1"], params)
Ejemplo n.º 15
0
 def task_add_mock(url):
     cursor = router.to_handler(url)[1][0]
     tasks(cursor)
Ejemplo n.º 16
0
 def task_add_mock(url):
     cursor = router.to_handler(url)[1][0]
     tasks(cursor)
Ejemplo n.º 17
0
 def test_req_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_request/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_request, fcn)
     self.assertListEqual([REQUEST, "1"], params)
Ejemplo n.º 18
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
Ejemplo n.º 19
0
    def test_root(self):
        fcn, params = router.to_handler("/", CONVENTION_PARAMS)
        self.assertEqual(home.index, fcn)

        fcn, params = router.to_handler("/pack", CONVENTION_PARAMS)
        self.assertEqual(pack_home.index, fcn)
Ejemplo n.º 20
0
 def assert_error_msg(self, path, msg):
     try:
         router.to_handler(path)
     except PathNotFound, e:
         self.assertTrue(e.message.find(msg) != -1, 'error msg should contain ' + msg)
         return
Ejemplo n.º 21
0
 def test_resp_handler_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_resp_handler/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_resp_handler, fcn)
     self.assertListEqual([RESPONSE, HANDLER, "1"], params)
Ejemplo n.º 22
0
 def set_up(self):
     fcn, path_args = router.to_handler(self.handler.request.path, self.dependencies, **self.request_args)
     self.dependencies['_fcn'] = fcn
     self.dependencies['_path_args'] = path_args
Ejemplo n.º 23
0
 def test_req_convention(self):
     fcn, params = router.to_handler("/first_handler/fcn_request/1", CONVENTION_PARAMS)
     self.assertEqual(first_handler.fcn_request, fcn)
     self.assertListEqual([REQUEST, "1"], params)