Пример #1
0
    def test_nested_cases_with_prefixes(self):
        'Reverse with nested web.cases with web.prefixes'
        chain = web.cases(
            web.match('/', 'index'),
            web.prefix('/docs') | web.cases(web.match('/<int:id>', 'doc'),
                                            web.match('/list', 'docs')),
            web.prefix('/news') | web.cases(web.match('/<int:id>', 'news'),
                                            web.match('/list', 'newslist')))

        r = web.Reverse.from_handler(chain)
        self.assertEqual(r('index'), '/')
        self.assertEqual(r('docs'), '/docs/list')
        self.assertEqual(r('newslist'), '/news/list')
        self.assertEqual(r('doc', id=1), '/docs/1')
        self.assertEqual(r('news', id=1), '/news/1')
Пример #2
0
    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')
Пример #3
0
    def test_nested_cases_with_prefixes(self):
        'Reverse with nested web.cases with web.prefixes'
        chain = web.cases(
                web.match('/', 'index'),
                web.prefix('/docs') | web.cases(
                    web.match('/<int:id>', 'doc'),
                    web.match('/list', 'docs')),
                web.prefix('/news') | web.cases(
                    web.match('/<int:id>', 'news'),
                    web.match('/list', 'newslist')))

        r = web.Reverse.from_handler(chain)
        self.assertEqual(r('index'), '/')
        self.assertEqual(r('docs'), '/docs/list')
        self.assertEqual(r('newslist'), '/news/list')
        self.assertEqual(r('doc', id=1), '/docs/1')
        self.assertEqual(r('news', id=1), '/news/1')
Пример #4
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)
Пример #5
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)
Пример #6
0
    def test_prefix_leaf(self):
        '''Simple prefix'''

        def handler(env, data, nx):
            self.assertEqual(env.request.prefixed_path, '/item')
            return Response()

        app = web.cases(
            web.match('/', 'index'),
            web.prefix('/docs') | web.cases(
                web.match('/', 'docs') | handler,
                web.match('/item', 'doc') | handler,
                web.prefix('/tags') | web.cases(
                    web.match('/', 'tags') | handler,
                    web.match('/tag', 'tag') | handler)))

        self.assertEqual(web.ask(app, '/docs/item').status_int, 200)
Пример #7
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)
Пример #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)
Пример #9
0
    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')
Пример #10
0
    def test_prefix_root(self):
        '''Prefix root'''

        def handler(env, data, nx):
            self.assertEqual(env.request.prefixed_path, '/')
            return Response()

        app = web.cases(
            web.match('/', 'index') | handler,
            web.prefix('/docs') | web.cases(
                web.match('/', 'docs') | handler,
                web.match('/item', 'doc') | handler,
                web.prefix('/tags') | web.cases(
                    web.match('/', 'tags') | handler,
                    web.match('/tag', 'tag') | handler)))

        self.assertEqual(web.ask(app, '/docs'), None)
        self.assertEqual(web.ask(app, '/docs/').status_int, 200)
        self.assertEqual(web.ask(app, '/docs/tags'), None)
        self.assertEqual(web.ask(app, '/docs/tags/').status_int, 200)
        self.assertEqual(web.ask(app, '/docs/tags/asdasd'), None)
Пример #11
0
    def test_unicode(self):
        '''Routing rules with unicode'''
        # XXX move to urltemplate and reverse tests?
        app = web.cases(
            web.prefix(u'/հայերեն') | web.cases(
                web.match(u'/%', 'percent') | (lambda e,d,n: Response())
            )
        )
        encoded = '/%D5%B0%D5%A1%D5%B5%D5%A5%D6%80%D5%A5%D5%B6/%25'

        self.assertEqual(web.Reverse.from_handler(app)('percent'), encoded)
        self.assertEqual(web.Reverse.from_handler(app)('percent').get_readable(), u'/հայերեն/%')

        self.assertNotEqual(web.ask(app, encoded), None)

        # ???
        # rctx have prefixes, so we need new one
        self.assertEqual(web.ask(app, encoded).status_int, 200)
Пример #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)
Пример #13
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)
Пример #14
0
    try:
        return next_handler(env, data)
    finally:
        env.db.close()


app = web.handler(config) | web.cases(
    static,
    auth.login_handler | template.render_to('login'),
    auth.logout_handler,

    auth | web.cases(
        web.match('/', 'dashboard') | views.dashboard,

        web.prefix('/issue') | web.cases(
            web.match('/<int:issue>', 'issue') | issue.get | web.cases(
                web.method('get'),
                web.method('post') | auth.login_required | issue.update,
                ) | template.render_to('issue'),
            ),

        web.prefix('/proj') | web.cases(
            web.match('', 'create-project') | auth.login_required | project.create,
            web.prefix('/<int:proj>') | project.get | web.cases(
                web.match('', 'project') | template.render_to('proj'),
                web.match('/update', 'update-project') | project.update,
                web.match('/issue', 'create-issue') | issue.create,
                )
            ),