当前位置: 首页>>代码示例>>Python>>正文


Python Brubeck.add_route_rule方法代码示例

本文整理汇总了Python中brubeck.request_handling.Brubeck.add_route_rule方法的典型用法代码示例。如果您正苦于以下问题:Python Brubeck.add_route_rule方法的具体用法?Python Brubeck.add_route_rule怎么用?Python Brubeck.add_route_rule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brubeck.request_handling.Brubeck的用法示例。


在下文中一共展示了Brubeck.add_route_rule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRequestHandling

# 需要导入模块: from brubeck.request_handling import Brubeck [as 别名]
# 或者: from brubeck.request_handling.Brubeck import add_route_rule [as 别名]
class TestRequestHandling(unittest.TestCase):
    """
    a test class for brubeck's request_handler
    """

    def setUp(self):
        """ will get run for each test """
        config = {
            'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
            'msg_conn': WSGIConnection()
        }
        self.app = Brubeck(**config)
    ##
    ## our actual tests( test _xxxx_xxxx(self) ) 
    ##
    def test_add_route_rule_method(self):
	# Make sure we have no routes
        self.assertEqual(hasattr(self.app,'_routes'),False)

        # setup a route
        self.setup_route_with_method()

        # Make sure we have some routes
        self.assertEqual(hasattr(self.app,'_routes'),True)

        # Make sure we have exactly one route
        self.assertEqual(len(self.app._routes),1)

    def test_init_routes_with_methods(self):
        # Make sure we have no routes
        self.assertEqual(hasattr(self.app, '_routes'), False)

        # Create a tuple with routes with method handlers
        routes = [ (r'^/', simple_handler_method), (r'^/brubeck', simple_handler_method) ]
        # init our routes
        self.app.init_routes( routes )

        # Make sure we have two routes
        self.assertEqual(len(self.app._routes), 2)

    def test_init_routes_with_objects(self):
        # Make sure we have no routes
        self.assertEqual(hasattr(self.app, '_routes'), False)

        # Create a tuple of routes with object handlers
        routes = [(r'^/', SimpleWebHandlerObject), (r'^/brubeck', SimpleWebHandlerObject)]
        self.app.init_routes( routes )

        # Make sure we have two routes
        self.assertEqual(len(self.app._routes), 2)

    def test_init_routes_with_objects_and_methods(self):
        # Make sure we have no routes
        self.assertEqual(hasattr(self.app, '_routes'), False)

        # Create a tuple of routes with a method handler and an object handler
        routes = [(r'^/', SimpleWebHandlerObject), (r'^/brubeck', simple_handler_method)]
        self.app.init_routes( routes )

        # Make sure we have two routes
        self.assertEqual(len(self.app._routes), 2)

    def test_add_route_rule_object(self):
        # Make sure we have no routes
        self.assertEqual(hasattr(self.app,'_routes'),False)
        self.setup_route_with_object()

        # Make sure we have some routes
        self.assertEqual(hasattr(self.app,'_routes'),True)

        # Make sure we have exactly one route
        self.assertEqual(len(self.app._routes),1)

    def test_brubeck_handle_request_with_object(self):
        # set up our route
        self.setup_route_with_object()

        # Make sure we get a handler back when we request one
        message = MockMessage(path='/')
        handler = self.app.route_message(message)
        self.assertNotEqual(handler,None)

    def test_brubeck_handle_request_with_method(self):
        # We ran tests on this already, so assume it works
        self.setup_route_with_method()

        # Make sure we get a handler back when we request one
        message = MockMessage(path='/')
        handler = self.app.route_message(message)
        self.assertNotEqual(handler,None)

    def test_cookie_handling(self):
        # set our cookie key and values
        cookie_key = 'my_key'
        cookie_value = 'my_secret'

        # encode our cookie
        encoded_cookie = cookie_encode(cookie_value, cookie_key)

        # Make sure we do not contain our value (i.e. we are really encrypting)
#.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:brubeck,代码行数:103,代码来源:test_request_handling.py


注:本文中的brubeck.request_handling.Brubeck.add_route_rule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。