extras_routes_test.py 文件源码

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

项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码
def test_simple(self):
        router = webapp2.Router([
            DomainRoute('<subdomain>.<:.*>', [
                webapp2.Route('/foo', 'FooHandler', 'subdomain-thingie'),
            ])
        ])

        self.assertRaises(
            webapp2.exc.HTTPNotFound,
            router.match, webapp2.Request.blank('/foo'))

        match = router.match(
            webapp2.Request.blank(
                'http://my-subdomain.app-id.appspot.com/foo'))
        self.assertEqual(match[1:], ((), {'subdomain': 'my-subdomain'}))

        match = router.match(
            webapp2.Request.blank(
                'http://another-subdomain.app-id.appspot.com/foo'))
        self.assertEqual(match[1:], ((), {'subdomain': 'another-subdomain'}))

        url = router.build(
            webapp2.Request.blank('/'),
            'subdomain-thingie', (),
            {'_netloc': 'another-subdomain.app-id.appspot.com'}
        )
        self.assertEqual(
            url,
            'http://another-subdomain.app-id.appspot.com/foo'
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号