web/test/unittest_urlrewrite.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 18 Jan 2010 19:21:30 +0100
changeset 4252 6c4f109c2b03
parent 3465 01616e5fa590
parent 4212 ab6573088b4a
child 4390 0285c1fa1459
permissions -rw-r--r--
backport stable branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     1
"""
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     2
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     3
:organization: Logilab
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3168
diff changeset
     4
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     6
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1900
diff changeset
     7
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2439
diff changeset
    10
from cubicweb.devtools.testlib import CubicWebTC
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2439
diff changeset
    11
from cubicweb.devtools.fake import FakeRequest
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
from cubicweb.web.views.urlrewrite import SimpleReqRewriter, SchemaBasedRewriter, rgx, rgx_action
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
    16
class UrlRewriteTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
    def test_auto_extend_rules(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
        class Rewriter(SimpleReqRewriter):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
            rules = [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
                ('foo', dict(rql='Foo F')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
                ('/index', dict(vid='index2')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
                ]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
        rules = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
        for pattern, values in Rewriter.rules:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
            if hasattr(pattern, 'pattern'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
                pattern = pattern.pattern
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
            rules.append((pattern, values))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
        self.assertListEquals(rules, [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
            ('foo' , dict(rql='Foo F')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
            ('/index' , dict(vid='index2')),
2780
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2439
diff changeset
    32
            ('/_', dict(vid='manage')),
ad1dfc3855b0 B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2439
diff changeset
    33
            ('/_registry', dict(vid='registry')),
2439
77d8dd77acb3 [cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    34
            ('/schema', dict(vid='schema')),
1900
8dd4bb69c73d [tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1802
diff changeset
    35
            ('/myprefs', dict(vid='propertiesform')),
8dd4bb69c73d [tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1802
diff changeset
    36
            ('/siteconfig', dict(vid='systempropertiesform')),
2439
77d8dd77acb3 [cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    37
            ('/siteinfo', dict(vid='info')),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
            ('/manage', dict(vid='manage')),
2439
77d8dd77acb3 [cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    39
            ('/notfound', dict(vid='404')),
77d8dd77acb3 [cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    40
            ('/error', dict(vid='error')),
77d8dd77acb3 [cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    41
            ('/sparql', dict(vid='sparql')),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    42
            ('/schema/([^/]+?)/?$', {'rql': r'Any X WHERE X is CWEType, X name "\1"', 'vid': 'eschema'}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
            ('/add/([^/]+?)/?$' , dict(vid='creation', etype=r'\1')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
            ('/doc/images/(.+?)/?$', dict(fid='\\1', vid='wdocimages')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
            ('/doc/?$', dict(fid='main', vid='wdoc')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
            ('/doc/(.+?)/?$', dict(fid='\\1', vid='wdoc')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
            ('/changelog/?$', dict(vid='changelog')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            # now in SchemaBasedRewriter
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
    49
            #('/search/(.+)$', dict(rql=r'Any X WHERE X has_text "\1"')),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
            ])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    def test_no_extend_rules(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        class Rewriter(SimpleReqRewriter):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
            ignore_baseclass_rules = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
            rules = [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
                ('foo', dict(rql='Foo F')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
                ('/index', dict(vid='index2')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
                ]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        self.assertListEquals(Rewriter.rules, [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
            ('foo' , dict(rql='Foo F')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
            ('/index' , dict(vid='index2')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
            ])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
    def test_basic_transformation(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        """test simple string-based rewrite"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        req = FakeRequest()
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
    68
        rewriter = SimpleReqRewriter(req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        self.assertRaises(KeyError, rewriter.rewrite, req, '/view?vid=whatever')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        self.assertEquals(req.form, {})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        rewriter.rewrite(req, '/index')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
        self.assertEquals(req.form, {'vid' : "index"})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    def test_regexp_transformation(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        """test regexp-based rewrite"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        req = FakeRequest()
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
    77
        rewriter = SimpleReqRewriter(req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        rewriter.rewrite(req, '/add/Task')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self.assertEquals(req.form, {'vid' : "creation", 'etype' : "Task"})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        req = FakeRequest()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        rewriter.rewrite(req, '/add/Task/')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        self.assertEquals(req.form, {'vid' : "creation", 'etype' : "Task"})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2439
diff changeset
    87
class RgxActionRewriteTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
    def setup_database(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        self.p1 = self.create_user(u'user1')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        self.p1.set_attributes(firstname=u'joe', surname=u'Dalton')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        self.p2 = self.create_user(u'user2')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        self.p2.set_attributes(firstname=u'jack', surname=u'Dalton')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
    def test_rgx_action_with_transforms(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
        class TestSchemaBasedRewriter(SchemaBasedRewriter):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
            rules = [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
                (rgx('/(?P<sn>\w+)/(?P<fn>\w+)'), rgx_action(r'Any X WHERE X surname %(sn)s, X firstname %(fn)s',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                                                                             argsgroups=('sn', 'fn'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
                                                                             transforms={'sn' : unicode.capitalize,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
                                                                                         'fn' : unicode.lower,})),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
                ]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        req = self.request()
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
   104
        rewriter = TestSchemaBasedRewriter(req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        pmid, rset = rewriter.rewrite(req, u'/DaLToN/JoE')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        self.assertEquals(len(rset), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        self.assertEquals(rset[0][0], self.p1.eid)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   108
3168
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   109
    def test_inheritance_precedence(self):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   110
        RQL1 = 'Any C WHERE C is CWEType'
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   111
        RQL2 = 'Any C WHERE C is CWUser'
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   112
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   113
        class BaseRewriter(SchemaBasedRewriter):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   114
            rules = [
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   115
               (rgx('/collector(.*)'),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   116
                rgx_action(rql=RQL1,
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   117
                    form=dict(vid='baseindex')),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   118
                ),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   119
                ]
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   120
        class Rewriter(BaseRewriter):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   121
            rules = [
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   122
               (rgx('/collector/something(/?)'),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   123
                rgx_action(rql=RQL2,
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   124
                    form=dict(vid='index')),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   125
                ),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   126
                ]
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   127
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   128
        req = self.request()
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
   129
        rewriter = Rewriter(req)
3168
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   130
        pmid, rset = rewriter.rewrite(req, '/collector')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   131
        self.assertEquals(rset.rql, RQL1)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   132
        self.assertEquals(req.form, {'vid' : "baseindex"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   133
        pmid, rset = rewriter.rewrite(req, '/collector/something')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   134
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   135
        self.assertEquals(req.form, {'vid' : "index"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   136
        pmid, rset = rewriter.rewrite(req, '/collector/something/')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   137
        self.assertEquals(req.form, {'vid' : "index"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   138
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   139
        pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   140
        self.assertEquals(rset.rql, RQL1)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   141
        self.assertEquals(req.form, {'vid' : "baseindex"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   142
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   143
    def test_inheritance_precedence_same_rgx(self):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   144
        RQL1 = 'Any C WHERE C is CWEType'
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   145
        RQL2 = 'Any C WHERE C is CWUser'
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   146
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   147
        class BaseRewriter(SchemaBasedRewriter):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   148
            rules = [
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   149
               (rgx('/collector(.*)'),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   150
                rgx_action(rql=RQL1,
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   151
                    form=dict(vid='baseindex')),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   152
                ),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   153
                ]
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   154
        class Rewriter(BaseRewriter):
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   155
            rules = [
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   156
               (rgx('/collector(.*)'),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   157
                rgx_action(rql=RQL2,
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   158
                    form=dict(vid='index')),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   159
                ),
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   160
                ]
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   161
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   162
        req = self.request()
3465
01616e5fa590 [tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3185
diff changeset
   163
        rewriter = Rewriter(req)
3168
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   164
        pmid, rset = rewriter.rewrite(req, '/collector')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   165
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   166
        self.assertEquals(req.form, {'vid' : "index"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   167
        pmid, rset = rewriter.rewrite(req, '/collector/something')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   168
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   169
        self.assertEquals(req.form, {'vid' : "index"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   170
        pmid, rset = rewriter.rewrite(req, '/collector/something/')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   171
        self.assertEquals(req.form, {'vid' : "index"})
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   172
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   173
        pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/')
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   174
        self.assertEquals(rset.rql, RQL2)
1ecd1b6d6f1b [tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2780
diff changeset
   175
        self.assertEquals(req.form, {'vid' : "index"})
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   176
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    unittest_main()