Exemplo n.º 1
0
 def testSplitLeaf(self):
     r = Route('bla/foo/<id>/pluto/leaf')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path, '/bla/foo/<id>/pluto/')
     self.assertEqual(l.path, '/leaf')
Exemplo n.º 2
0
 def testSplitLeaf(self):
     r = Route('bla/foo/<id>/pluto/leaf')
     p,l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path,'/bla/foo/<id>/pluto/')
     self.assertEqual(l.path,'/leaf')
Exemplo n.º 3
0
 def testIntVariable(self):
     r = Route('<int:id>/')
     self.assertEqual(str(r),'/<int:id>/')
     self.assertEqual(r.arguments,set(['id']))
     self.assertEqual(r.breadcrumbs,((True,'id'),))
     self.assertEqual(r.match('35/'),{'id':35})
     self.assertEqual(r.url(id = 1), '/1/')
     self.assertRaises(ValueError,lambda : r.url(id = 'bla'))
Exemplo n.º 4
0
 def testAddDirLeaf(self):
     r = Route('bla/')
     self.assertFalse(r.is_leaf)
     r2 = Route('foo')
     self.assertTrue(r2.is_leaf)
     r3 = r + r2
     self.assertEqual(r3.rule, 'bla/foo')
     self.assertTrue(r3.is_leaf)
Exemplo n.º 5
0
 def testSplitDir(self):
     r = Route('bla/foo/<id>/pluto/')
     self.assertEqual(r.level,4)
     p,l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path,'/bla/foo/<id>/')
     self.assertEqual(l.path,'/pluto/')
Exemplo n.º 6
0
 def testSplitDir(self):
     r = Route('bla/foo/<id>/pluto/')
     self.assertEqual(r.level, 4)
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path, '/bla/foo/<id>/')
     self.assertEqual(l.path, '/pluto/')
Exemplo n.º 7
0
 def testIntVariable(self):
     r = Route('<int:id>/')
     self.assertEqual(str(r), '/<int:id>/')
     self.assertEqual(r.arguments, set(['id']))
     self.assertEqual(r.breadcrumbs, ((True, 'id'), ))
     self.assertEqual(r.match('35/'), {'id': 35})
     self.assertEqual(r.url(id=1), '/1/')
     self.assertRaises(ValueError, lambda: r.url(id='bla'))
Exemplo n.º 8
0
 def testPathVaiable(self):
     r = Route('bla/<path:rest>', defaults = {'rest':''})
     self.assertEqual(r.arguments,set(['rest']))
     self.assertEqual(r.level,2)
     self.assertTrue(r.is_leaf)
     self.assertEqual(r.match('bla/a/b/c.html'),{'rest':'a/b/c.html'})
     self.assertEqual(r.match('bla/'),{'rest':''})
     self.assertEqual(r.url(rest = 'a/'), '/bla/a/')
     self.assertEqual(r.url(), '/bla/')
Exemplo n.º 9
0
 def testSimple(self):
     r = Route('bla/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level,1)
     self.assertEqual(len(r.arguments),0)
     self.assertEqual(r.rule,'bla/')
     self.assertEqual(r.match('bla/'),{})
     self.assertEqual(r.match('bladdd/'),None)
     self.assertEqual(r.match('bla/another/'),{'__remaining__':'another/'})
Exemplo n.º 10
0
 def testRoot(self):
     r = Route('/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule,'')
     r = Route('////')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule,'')
     self.assertEqual(r.match(''),{})
     self.assertEqual(r.match('bee/'),{'__remaining__':'bee/'})
Exemplo n.º 11
0
 def testSimple(self):
     r = Route('bla/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level, 1)
     self.assertEqual(len(r.arguments), 0)
     self.assertEqual(r.rule, 'bla/')
     self.assertEqual(r.match('bla/'), {})
     self.assertEqual(r.match('bladdd/'), None)
     self.assertEqual(r.match('bla/another/'),
                      {'__remaining__': 'another/'})
Exemplo n.º 12
0
 def testStringVariable(self):
     r = Route('<name>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.arguments,set(['name']))
     self.assertEqual(r.breadcrumbs,((True,'name'),))
     self.assertEqual(r.rule,'<name>/')
     self.assertEqual(r.match('bla-foo/'),{'name':'bla-foo'})
     self.assertEqual(r.match('bla/another/'),{'name':'bla',
                                                '__remaining__':'another/'})
     self.assertEqual(r.url(name = 'luca'),'/luca/')
Exemplo n.º 13
0
 def testStringVariable(self):
     r = Route('<name>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.arguments, set(['name']))
     self.assertEqual(r.breadcrumbs, ((True, 'name'), ))
     self.assertEqual(r.rule, '<name>/')
     self.assertEqual(r.match('bla-foo/'), {'name': 'bla-foo'})
     self.assertEqual(r.match('bla/another/'), {
         'name': 'bla',
         '__remaining__': 'another/'
     })
     self.assertEqual(r.url(name='luca'), '/luca/')
Exemplo n.º 14
0
 def testIntVariableMinMax(self):
     r = Route('<int(min=1):cid>/')
     self.assertEqual(str(r),'/<int(min=1):cid>/')
     self.assertEqual(r.arguments,set(['cid']))
     self.assertEqual(r.breadcrumbs,((True,'cid'),))
     self.assertEqual(r.match('1/'),{'cid':1})
     self.assertEqual(r.match('476876/'),{'cid':476876})
     self.assertEqual(r.match('0/'),None)
     self.assertEqual(r.match('-5/'),None)
     self.assertEqual(r.url(cid = 13), '/13/')
     self.assertEqual(r.url(cid = 1), '/1/')
     self.assertRaises(ValueError,lambda : r.url(cid = 0))
     self.assertRaises(ValueError,lambda : r.url(cid = -10))
     self.assertRaises(ValueError,lambda : r.url(cid = 'bla'))
Exemplo n.º 15
0
 def test2StringVariables(self):
     r = Route('<name>/<child>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level,2)
     self.assertEqual(r.arguments,set(['name','child']))
     self.assertEqual(r.breadcrumbs,((True,'name'),(True,'child')))
     self.assertEqual(r.rule,'<name>/<child>/')
     self.assertEqual(r.match('bla/foo/'),{'name':'bla','child':'foo'})
     self.assertEqual(r.match('bla/foo/another/'),
                      {'name':'bla','child':'foo',
                       '__remaining__':'another/'})
     self.assertRaises(KeyError, lambda : r.url(name = 'luca'))
     self.assertEqual(r.url(name = 'luca', child = 'joshua'),
                      '/luca/joshua/')
Exemplo n.º 16
0
 def testIntVariableFixDigits(self):
     r = Route('<int(2):id>/')
     self.assertEqual(str(r),'/<int(2):id>/')
     self.assertEqual(r.arguments,set(['id']))
     self.assertEqual(r.breadcrumbs,((True,'id'),))
     self.assertEqual(r.match('35/'),{'id':35})
     self.assertEqual(r.match('355/'),None)
     self.assertEqual(r.match('6/'),None)
     self.assertEqual(r.match('ch/'),None)
     self.assertEqual(r.url(id = 13), '/13/')
     self.assertEqual(r.url(id = 1), '/01/')
     self.assertRaises(ValueError,lambda : r.url(id = 134))
     self.assertRaises(ValueError,lambda : r.url(id = 'bl'))
     self.assertRaises(ValueError,lambda : r.url(id = 'bla'))
Exemplo n.º 17
0
def page_links(request, asbuttons=False, ul=None):
    '''Utility for displaying page navigation links.'''
    ul = ul if ul is not None else html.Widget('ul')
    view = request.view
    Page = view.Page
    if Page:
        # We are on a page application view
        if view.mapper == Page:
            page = request.instance
            if page:
                route = Route(page.url)
                urlargs = dict(request.GET.items())
                try:
                    path = route.url(**urlargs)
                except:
                    path = '/'
                a = html.anchor_or_button('exit',
                                          href=path,
                                          icon='exit-page-edit',
                                          asbutton=asbuttons)
                ul.add(a)
        else:
            page = request.page
            page_request = request.for_model(Page)
            if page_request is not None:
                if page:
                    kwargs = {NEXT_KEY: request.path}
                    include = ('change',)
                else:
                    kwargs = {'url': request.view.path}
                    include = ('add',)
                for link in views.application_views_links(
                                    page_request,
                                    instance=page,
                                    include=include,
                                    asbuttons=asbuttons):
                    kwargs.update(request.urlargs)
                    href = link.attrs['href']
                    link.attrs['href'] = iri_to_uri(href, kwargs)
                    ul.add(link)
    return ul
Exemplo n.º 18
0
 def testSplitRoot(self):
     r = Route('')
     self.assertEqual(r.level, 0)
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l, None)
     r = Route('bla')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l.path, '/bla')
     r = Route('bla/')
     p, l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path, '/')
     self.assertEqual(l.path, '/bla/')
Exemplo n.º 19
0
 def testRoot(self):
     r = Route('/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule, '')
     r = Route('////')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule, '')
     self.assertEqual(r.match(''), {})
     self.assertEqual(r.match('bee/'), {'__remaining__': 'bee/'})
Exemplo n.º 20
0
 def testPathVaiable(self):
     r = Route('bla/<path:rest>', defaults={'rest': ''})
     self.assertEqual(r.arguments, set(['rest']))
     self.assertEqual(r.level, 2)
     self.assertTrue(r.is_leaf)
     self.assertEqual(r.match('bla/a/b/c.html'), {'rest': 'a/b/c.html'})
     self.assertEqual(r.match('bla/'), {'rest': ''})
     self.assertEqual(r.url(rest='a/'), '/bla/a/')
     self.assertEqual(r.url(), '/bla/')
Exemplo n.º 21
0
 def test2StringVariables(self):
     r = Route('<name>/<child>/')
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.level, 2)
     self.assertEqual(r.arguments, set(['name', 'child']))
     self.assertEqual(r.breadcrumbs, ((True, 'name'), (True, 'child')))
     self.assertEqual(r.rule, '<name>/<child>/')
     self.assertEqual(r.match('bla/foo/'), {'name': 'bla', 'child': 'foo'})
     self.assertEqual(r.match('bla/foo/another/'), {
         'name': 'bla',
         'child': 'foo',
         '__remaining__': 'another/'
     })
     self.assertRaises(KeyError, lambda: r.url(name='luca'))
     self.assertEqual(r.url(name='luca', child='joshua'), '/luca/joshua/')
Exemplo n.º 22
0
 def testSplitRoot(self):
     r = Route('')
     self.assertEqual(r.level,0)
     p,l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertEqual(p.path,'/')
     self.assertEqual(l,None)
     r = Route('bla')
     p,l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertTrue(l.is_leaf)
     self.assertEqual(p.path,'/')
     self.assertEqual(l.path,'/bla')
     r = Route('bla/')
     p,l = r.split()
     self.assertFalse(p.is_leaf)
     self.assertFalse(l.is_leaf)
     self.assertEqual(p.path,'/')
     self.assertEqual(l.path,'/bla/')
Exemplo n.º 23
0
 def testIntVariableFixDigits(self):
     r = Route('<int(2):id>/')
     self.assertEqual(str(r), '/<int(2):id>/')
     self.assertEqual(r.arguments, set(['id']))
     self.assertEqual(r.breadcrumbs, ((True, 'id'), ))
     self.assertEqual(r.match('35/'), {'id': 35})
     self.assertEqual(r.match('355/'), None)
     self.assertEqual(r.match('6/'), None)
     self.assertEqual(r.match('ch/'), None)
     self.assertEqual(r.url(id=13), '/13/')
     self.assertEqual(r.url(id=1), '/01/')
     self.assertRaises(ValueError, lambda: r.url(id=134))
     self.assertRaises(ValueError, lambda: r.url(id='bl'))
     self.assertRaises(ValueError, lambda: r.url(id='bla'))
Exemplo n.º 24
0
 def testDefaults(self):
     r = Route('bla/<id>/add/<path:path>', {'path': ''})
     self.assertEqual(r.url(id=10), '/bla/10/add/')
     self.assertEqual(r.url(id=10, path='ciao/luca'),
                      '/bla/10/add/ciao/luca')
Exemplo n.º 25
0
 def testDefaultsAddition(self):
     r = Route('add/<path:path>', {'path': ''})
     r2 = Route('bla/<id>/') + r
     self.assertEqual(r2.defaults, r.defaults)
Exemplo n.º 26
0
 def testMalformedRule1(self):
     self.assertRaises(ValueError, lambda: Route('<bla'))
     self.assertRaises(ValueError, lambda: Route('<bla/'))
     self.assertRaises(ValueError, lambda: Route('bla>/'))
     self.assertRaises(ValueError, lambda: Route('/<bla'))
Exemplo n.º 27
0
 def testDefaults(self):
     r = Route('bla/<id>/add/<path:path>',{'path':''})
     self.assertEqual(r.url(id=10),'/bla/10/add/')
     self.assertEqual(r.url(id=10,path='ciao/luca'),'/bla/10/add/ciao/luca')
Exemplo n.º 28
0
 def testMalformedRule2(self):
     self.assertRaises(ValueError, lambda: Route('<foo>/<bla'))
     self.assertRaises(ValueError, lambda: Route('ciao/<bla/'))
     self.assertRaises(ValueError, lambda: Route('ahhh>/bla>/'))
     self.assertRaises(ValueError, lambda: Route('ahhh/bla>/'))
Exemplo n.º 29
0
 def testMalformedRule3(self):
     self.assertRaises(ValueError, lambda: Route('<foo>/<foo>'))
     self.assertRaises(ValueError, lambda: Route('<foo>/bla/<foo>'))
     self.assertRaises(ValueError, lambda: Route('<foo>/<bla>/<foo>'))
Exemplo n.º 30
0
 def testSimpleAppendSlash(self):
     r = Route('bla', append_slash=True)
     self.assertFalse(r.is_leaf)
     self.assertEqual(r.rule, 'bla/')
Exemplo n.º 31
0
 def testIntVariableMinMax(self):
     r = Route('<int(min=1):cid>/')
     self.assertEqual(str(r), '/<int(min=1):cid>/')
     self.assertEqual(r.arguments, set(['cid']))
     self.assertEqual(r.breadcrumbs, ((True, 'cid'), ))
     self.assertEqual(r.match('1/'), {'cid': 1})
     self.assertEqual(r.match('476876/'), {'cid': 476876})
     self.assertEqual(r.match('0/'), None)
     self.assertEqual(r.match('-5/'), None)
     self.assertEqual(r.url(cid=13), '/13/')
     self.assertEqual(r.url(cid=1), '/1/')
     self.assertRaises(ValueError, lambda: r.url(cid=0))
     self.assertRaises(ValueError, lambda: r.url(cid=-10))
     self.assertRaises(ValueError, lambda: r.url(cid='bla'))