예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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)
예제 #12
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
예제 #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)
예제 #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)
예제 #15
0
 def task_add_mock(url):
     cursor = router.to_handler(url)[1][0]
     tasks(cursor)
예제 #16
0
 def task_add_mock(url):
     cursor = router.to_handler(url)[1][0]
     tasks(cursor)
예제 #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)
예제 #18
0
 def test_complete_path(self):
     fcn, params = router.to_handler("/pack/pack_handler/complete_path")
     self.assertEqual(pack_handler.complete_path, fcn)
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #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)