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'
)
评论列表
文章目录