Exemplo n.º 1
0
 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'])
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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'])
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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'])
Exemplo n.º 6
0
 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'])
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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'])
Exemplo n.º 10
0
 def test_namespace(self):
     'Locations namespace'
     chain = web.namespace('news') | web.match('/', 'index')
     self.assert_(web.locations(chain).keys(), ['news.index'])
Exemplo n.º 11
0
 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'))))
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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'])
Exemplo n.º 14
0
 def test_match(self):
     'Locations of web.match'
     self.assert_(web.locations(web.match('/', 'name')).keys(), ['name'])
Exemplo n.º 15
0
Arquivo: app.py Projeto: kalloc/mage
    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))
Exemplo n.º 16
0
 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'])
Exemplo n.º 17
0
 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'])
Exemplo n.º 18
0
 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'])
Exemplo n.º 19
0
 def test_namespace(self):
     'Locations namespace'
     chain = web.namespace('news') | web.match('/', 'index')
     self.assert_(web.locations(chain).keys(), ['news.index'])
Exemplo n.º 20
0
 def test_match(self):
     'Locations of web.match'
     self.assert_(web.locations(web.match('/', 'name')).keys(), ['name'])
Exemplo n.º 21
0
 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'])
Exemplo n.º 22
0
 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'))))
Exemplo n.º 23
0
Arquivo: app.py Projeto: unk2k/mage
    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))
Exemplo n.º 24
0
 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)