extras_routes_test.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码
def test_with_variables_name_and_handler(self):
        router = webapp2.Router([
            PathPrefixRoute('/user/<username:\w+>', [
                HandlerPrefixRoute('apps.users.', [
                    NamePrefixRoute('user-', [
                        webapp2.Route('/', 'UserOverviewHandler', 'overview'),
                        webapp2.Route(
                            '/profile', 'UserProfileHandler', 'profile'),
                        webapp2.Route(
                            '/projects', 'UserProjectsHandler', 'projects'),
                    ]),
                ]),
            ])
        ])

        path = '/user/calvin/'
        match = ((), {'username': 'calvin'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-overview', match[0], match[1]),
            path
        )

        path = '/user/calvin/profile'
        match = ((), {'username': 'calvin'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-profile', match[0], match[1]),
            path
        )

        path = '/user/calvin/projects'
        match = ((), {'username': 'calvin'})
        self.assertEqual(router.match(webapp2.Request.blank(path))[1:], match)
        self.assertEqual(
            router.build(webapp2.Request.blank('/'),
                         'user-projects', match[0], match[1]),
            path
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号