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_prefix_and_cases(self): 'Locations of web.cases with prefix' chain = web.prefix('/news') | web.cases(web.match('/', 'index'), web.match('/docs', 'docs')) for k in ('index', 'docs'): self.assert_(web.locations(chain).keys(), [k]) self.assert_('builders' in web.locations(chain)[k]) self.assertEqual(len(web.locations(chain)[k]['builders']), 2)
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_prefix_and_cases(self): 'Locations of web.cases with prefix' chain = web.prefix('/news') | web.cases( web.match('/', 'index'), web.match('/docs', 'docs')) for k in ('index', 'docs'): self.assert_(web.locations(chain).keys(), [k]) self.assert_('builders' in web.locations(chain)[k]) self.assertEqual(len(web.locations(chain)[k]['builders']), 2)
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_nested_cases(self): 'Locations of nested web.cases' chain = web.cases( web.match('/', 'index'), web.cases( web.match('/docs', 'docs'))) self.assert_(web.locations(chain).keys(), ['index', 'docs'])
def test_mix(self): 'Loactions mix' chain = web.prefix('/items') | web.cases( web.match('/', 'index'), web.prefix('/news') | web.namespace('news') | web.cases( web.match('/', 'index'), web.match('/<int:id>', 'item')), web.prefix('/docs') | web.namespace('docs') | web.cases( web.match('/', 'index'), web.match('/<int:id>', 'item'))) locations = web.locations(chain) self.assertEqual( locations.keys(), ['index', 'docs.index', 'docs.item', 'news.item', 'news.index']) self.assertEqual(len(locations['index']['builders']), 2) self.assertEqual(len(locations['news.index']['builders']), 3) self.assertEqual(len(locations['news.item']['builders']), 3) self.assertEqual(len(locations['docs.index']['builders']), 3) self.assertEqual(len(locations['docs.item']['builders']), 3)
def test_mix(self): 'Loactions mix' chain = web.prefix('/items') | web.cases( web.match('/', 'index'), web.prefix('/news') | web.namespace('news') | web.cases( web.match('/', 'index'), web.match('/<int:id>', 'item')), web.prefix('/docs') | web.namespace('docs') | web.cases( web.match('/', 'index'), web.match('/<int:id>', 'item'))) locations = web.locations(chain) self.assertEqual(locations.keys(), ['index', 'docs.index', 'docs.item', 'news.item', 'news.index']) self.assertEqual(len(locations['index']['builders']), 2) self.assertEqual(len(locations['news.index']['builders']), 3) self.assertEqual(len(locations['news.item']['builders']), 3) self.assertEqual(len(locations['docs.index']['builders']), 3) self.assertEqual(len(locations['docs.item']['builders']), 3)
def test_namespace_and_cases(self): 'Locations namespace with web.cases' chain = web.namespace('news') | web.cases( web.match('/', 'index'), web.match('/docs', 'docs')) self.assertEqual(web.locations(chain).keys(), ['news.index', 'news.docs'])
def test_namespace(self): 'Locations namespace' chain = web.namespace('news') | web.match('/', 'index') self.assert_(web.locations(chain).keys(), ['news.index'])
def test_match_dublication(self): 'Raise error on same url names' self.assertRaises( ValueError, lambda: web.locations( web.cases(web.match('/', 'index'), web.match( '/index', 'index'))))
def test_prefix(self): 'Locations of web.match with prefix' chain = web.prefix('/news') | web.match('/', 'index') self.assert_(web.locations(chain).keys(), ['index']) self.assert_('builders' in web.locations(chain)['index']) self.assertEqual(len(web.locations(chain)['index']['builders']), 2)
def test_nested_cases(self): 'Locations of nested web.cases' chain = web.cases(web.match('/', 'index'), web.cases(web.match('/docs', 'docs'))) self.assert_(web.locations(chain).keys(), ['index', 'docs'])
def test_match(self): 'Locations of web.match' self.assert_(web.locations(web.match('/', 'name')).keys(), ['name'])
env.url_for_static = static.construct_reverse() env.template = template env.db = db_maker() env.cache = memcache_client try: return next_handler(env, data) finally: env.db.close() app = web.handler(environment) | web.cases( auth.login_handler | h.render_to('login.html'), auth.logout_handler, # API match('/api/posts', 'api-posts') | web.cases( ctype(ctype.xml) | h.posts_paginator | h.to_xml, ctype(ctype.json) | h.posts_paginator | h.to_json, ), auth | web.cases( match('/', 'posts') | h.posts_paginator | h.render_to('posts.html'), match('/<int:id>', 'post') | h.post_by_id | h.render_to('post.html'), prefix('/posts') | auth.login_required | web.cases( match('/add', 'add-post') | h.post_form | h.render_to('add_post.html'), match('/edit/<int:id>', 'edit-post') | h.edit_post | h.render_to('add_post.html'), match('/delete/<int:id>', 'del-post') | h.del_post | h.render_to('del_post.html') ) ), ) url_for = web.Reverse(web.locations(app))
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_namespace_with_empty_name(self): 'Namespaces with empty url name' chain = web.namespace('news') | web.match('/', '') self.assert_(web.locations(chain).keys(), ['news'])
def test_namespace_and_cases(self): 'Locations namespace with web.cases' chain = web.namespace('news') | web.cases(web.match('/', 'index'), web.match('/docs', 'docs')) self.assertEqual( web.locations(chain).keys(), ['news.index', 'news.docs'])
def test_namespace(self): 'Locations namespace' chain = web.namespace('news') | web.match('/', 'index') self.assert_(web.locations(chain).keys(), ['news.index'])
def test_match(self): 'Locations of web.match' self.assert_(web.locations(web.match('/', 'name')).keys(), ['name'])
def test_namespace_with_empty_name(self): 'Namespaces with empty url name' chain = web.namespace('news') | web.match('/', '') self.assert_(web.locations(chain).keys(), ['news'])
def test_match_dublication(self): 'Raise error on same url names' self.assertRaises(ValueError, lambda: web.locations( web.cases( web.match('/', 'index'), web.match('/index', 'index'))))
env.url_for_static = static.construct_reverse() env.template = template env.db = db_maker() env.cache = memcache_client try: return next_handler(env, data) finally: env.db.close() app = web.handler(environment) | web.cases( auth.login_handler | h.render_to('login.html'), auth.logout_handler, # API match('/api/posts', 'api-posts') | web.cases( ctype(ctype.xml) | h.posts_paginator | h.to_xml, ctype(ctype.json) | h.posts_paginator | h.to_json, ), auth | web.cases( match('/', 'posts') | h.posts_paginator | h.render_to('posts.html'), match('/<int:id>', 'post') | h.post_by_id | h.render_to('post.html'), prefix('/posts') | auth.login_required | web.cases( match('/add', 'add-post') | h.post_form | h.render_to('add_post.html'), match('/edit/<int:id>', 'edit-post') | h.edit_post | h.render_to('add_post.html'), match('/delete/<int:id>', 'del-post') | h.del_post | h.render_to('del_post.html') ) ), ) url_for = web.Reverse(web.locations(app))
def test_prefix(self): 'Locations of web.match with prefix' chain = web.prefix('/news') | web.match('/', 'index') self.assert_(web.locations(chain).keys(), ['index']) self.assert_('builders' in web.locations(chain)['index']) self.assertEqual(len(web.locations(chain)['index']['builders']), 2)