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)
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)
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)
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)
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)
def execute(next_process, handler, dependencies, **kwargs): fcn, params = router.to_handler(handler.request.path, dependencies, **kwargs) fcn(*params, **kwargs) next_process(dependencies, **kwargs)
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
def test_complete_path(self): fcn, params = router.to_handler("/pack/pack_handler/complete_path") self.assertEqual(pack_handler.complete_path, fcn)
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)
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)
def task_add_mock(url): cursor = router.to_handler(url)[1][0] tasks(cursor)
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)
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