def test_unicode(self): '''IRI tests''' app = web.subdomain(u'рф') | web.subdomain(u'сайт') | web.match('/', 'site') | (lambda e,d,n: Response() ) encoded = 'http://xn--80aswg.xn--p1ai/' self.assertEqual(web.Reverse.from_handler(app)('site').get_readable(), u'http://сайт.рф/') self.assertEqual(web.Reverse.from_handler(app)('site'), encoded) self.assertNotEqual(web.ask(app, encoded), None)
def test_host10(self): app = web.cases ( web.subdomain(u'bla') | web.match('/', 'bla') | (lambda e,d,n: Response(body='bla') ), web.subdomain(u'localhost') | web.match('/', 'localhost') | (lambda e,d,n: Response(body='localhost')) ) self.assertEqual(web.ask(app, 'http://bla/').body, 'bla') self.assertEqual(web.ask(app, '/').body, 'localhost')
def test_subdomain(self): 'Locations and subdomains' chain = web.subdomain('news') | web.match('/', 'index') self.assert_(web.locations(chain).keys(), ['index']) self.assert_('subdomains' in web.locations(chain)['index']) self.assertEqual(web.locations(chain)['index']['subdomains'], ['news'])
def test_subdomains_and_cases(self): 'Locations of web.cases with subdomains' chain = web.subdomain('news') | web.cases(web.match('/', 'index'), web.match('/docs', 'docs')) for k in ('index', 'docs'): self.assert_(web.locations(chain).keys(), [k]) self.assert_('subdomains' in web.locations(chain)[k]) self.assertEqual(web.locations(chain)[k]['subdomains'], ['news'])
def test_subdomains_and_cases(self): 'Locations of web.cases with subdomains' chain = web.subdomain('news') | web.cases( web.match('/', 'index'), web.match('/docs', 'docs')) for k in ('index', 'docs'): self.assert_(web.locations(chain).keys(), [k]) self.assert_('subdomains' in web.locations(chain)[k]) self.assertEqual(web.locations(chain)[k]['subdomains'], ['news'])
def test_subdomain(self): '''Subdomain filter''' def handler(env, data, nx): self.assertEqual(env.request.path, '/') return Response() app = web.subdomain('host') | web.cases( web.subdomain('') | web.match('/', 'index') | handler, web.subdomain('k') | web.cases( web.subdomain('l') | web.cases( web.match('/', 'l') | handler, ), web.subdomain('') | web.match('/', 'k') | handler)) self.assertEqual(web.ask(app, 'http://host/').status_int, 200) self.assertEqual(web.ask(app, 'http://k.host/').status_int, 200) self.assertEqual(web.ask(app, 'http://l.k.host/').status_int, 200) self.assertEqual(web.ask(app, 'http://x.l.k.host/').status_int, 200) self.assert_(web.ask(app, 'http://x.k.host/') is None) self.assert_(web.ask(app, 'http://lk.host/') is None) self.assert_(web.ask(app, 'http://mhost/') is None)
def test_unicode(self): 'Reverse with unicode' # various combinations of url parts containing unicode chain = web.subdomain(u'п') | web.cases( web.prefix(u'/з') | web.match('/', 'unicode1'), web.prefix(u'/з') | web.match('/<string:slug>', 'unicode2'), web.match(u'/д/<string:slug>', 'unicode3'), #regression web.match(u'/<string:slug1>/<string:slug2>', 'unicode4'), #regression ) r = web.Reverse.from_handler(chain) self.assertEqual(r('unicode1'), 'http://xn--o1a/%D0%B7/') self.assertEqual(r('unicode2', slug=u'ю'), 'http://xn--o1a/%D0%B7/%D1%8E') self.assertEqual(r('unicode3', slug=u'ю'), 'http://xn--o1a/%D0%B4/%D1%8E') self.assertEqual(r('unicode4', slug1=u'д', slug2=u'ю'), 'http://xn--o1a/%D0%B4/%D1%8E')