本文整理匯總了Python中router.Router.all_callables方法的典型用法代碼示例。如果您正苦於以下問題:Python Router.all_callables方法的具體用法?Python Router.all_callables怎麽用?Python Router.all_callables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類router.Router
的用法示例。
在下文中一共展示了Router.all_callables方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RouterTest
# 需要導入模塊: from router import Router [as 別名]
# 或者: from router.Router import all_callables [as 別名]
class RouterTest(unittest.TestCase):
def setUp(self):
self.router = Router()
def tearDown(self):
self.router = None
def test_register_with_not_callable(self):
self.assertRaises(
RouterException, self.router.register, '/', '10', ['GET'])
def test_register_with_callable_and_legal_path(self):
self.router.register('/', just_a_callable, ['GET'])
self.assertIn(just_a_callable, self.router.methods['GET'])
def test_call_magic_method(self):
self.router.register('/', just_a_callable, ['GET'])
r = self.router('/')
self.assertEqual(r, (just_a_callable, None))
def test_register_with_callable_and_illegal_path(self):
self.assertRaises(
RouterException, self.router.register, '$$', just_a_callable, ['GET'])
def test_get_with_illegal_methods(self):
self.router.register('/', just_a_callable, ['GET'])
self.assertRaises(RouterException, self.router.get, '/', 'REMOVE')
def test_get_with_legal_methods_one_slash(self):
self.router.register('/', just_a_callable, ['GET'])
self.assertEqual((just_a_callable, None), self.router.get('/'))
def test_get_with_legal_methods_two_slash(self):
self.router.register('/post/about', just_a_callable, ['GET'])
self.assertEqual(
(just_a_callable, None), self.router.get('/post/about'))
def test_get_with_int_args(self):
self.router.register('/show/<int:id>', just_a_callable, ['GET'])
self.assertEqual(
(just_a_callable, {'id': '1'}), self.router.get('/show/1'))
def test_url_for_with_not_callable(self):
self.assertRaises(RouterException, self.router.url_for, '10')
def test_url_for_with_no_args_rule(self):
self.router.register('/post', just_a_callable, ['GET'])
self.assertEqual('/post', self.router.url_for(just_a_callable))
def test_url_for_with_args_rule_but_no_args_provided(self):
self.router.register('/post/<int:id>', just_a_callable, ['GET'])
self.assertRaises(
RouterException, self.router.url_for, just_a_callable)
def test_url_for_with_args_rule_and_args_provided(self):
self.router.register('/post/<int:id>', just_a_callable, ['GET'])
self.assertEqual(
'/post/1', self.router.url_for(just_a_callable, id='1'))
def test_url_for_with_no_matched_rule(self):
self.router.register('/post', just_a_callable, ['GET'])
self.assertRaises(
RouterException, self.router.url_for, another_callable)
def test_all_callable(self):
self.router.register('/', just_a_callable, ['GET'])
r = self.router.all_callables()
self.assertEqual(set(r), set([just_a_callable]))
self.router.register('/post', another_callable, ['GET'])
r = self.router.all_callables()
self.assertEqual(set(r), set([another_callable, just_a_callable]))