author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 22 Mar 2013 20:10:19 +0100 | |
changeset 8773 | 21edcb0a5ed7 |
parent 8632 | fa044b9157d7 |
child 9359 | 31a1813d53f3 |
permissions | -rw-r--r-- |
7803
02e141e41da2
some minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7802
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4715
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
from logilab.common.testlib import TestCase, unittest_main |
19 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2439
diff
changeset
|
20 |
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
|
21 |
from cubicweb.devtools.fake import FakeRequest |
0 | 22 |
|
23 |
from cubicweb.web.views.urlrewrite import SimpleReqRewriter, SchemaBasedRewriter, rgx, rgx_action |
|
24 |
||
25 |
||
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
26 |
class UrlRewriteTC(CubicWebTC): |
0 | 27 |
|
28 |
def test_auto_extend_rules(self): |
|
29 |
class Rewriter(SimpleReqRewriter): |
|
30 |
rules = [ |
|
31 |
('foo', dict(rql='Foo F')), |
|
32 |
('/index', dict(vid='index2')), |
|
33 |
] |
|
34 |
rules = [] |
|
35 |
for pattern, values in Rewriter.rules: |
|
36 |
if hasattr(pattern, 'pattern'): |
|
37 |
pattern = pattern.pattern |
|
38 |
rules.append((pattern, values)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
self.assertListEqual(rules, [ |
0 | 40 |
('foo' , dict(rql='Foo F')), |
41 |
('/index' , dict(vid='index2')), |
|
2780
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2439
diff
changeset
|
42 |
('/_', dict(vid='manage')), |
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2439
diff
changeset
|
43 |
('/_registry', dict(vid='registry')), |
2439
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
44 |
('/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
|
45 |
('/myprefs', dict(vid='propertiesform')), |
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1802
diff
changeset
|
46 |
('/siteconfig', dict(vid='systempropertiesform')), |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
47 |
('/siteinfo', dict(vid='siteinfo')), |
0 | 48 |
('/manage', dict(vid='manage')), |
2439
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
49 |
('/notfound', dict(vid='404')), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
50 |
('/error', dict(vid='error')), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
51 |
('/sparql', dict(vid='sparql')), |
4715
d3f87ee74fe4
[test] fix test broken by arthur processinfo patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4390
diff
changeset
|
52 |
('/processinfo', dict(vid='processinfo')), |
7802
d0bf71aff4a1
[web test] fix test broken by new users/groups management views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
53 |
('/cwuser$', {'vid': 'cw.users-and-groups-management', |
d0bf71aff4a1
[web test] fix test broken by new users/groups management views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
54 |
'tab': 'cw_users_management'}), |
d0bf71aff4a1
[web test] fix test broken by new users/groups management views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
55 |
('/cwgroup$', {'vid': 'cw.users-and-groups-management', |
d0bf71aff4a1
[web test] fix test broken by new users/groups management views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
56 |
'tab': 'cw_groups_management'}), |
7992
4ff9f25cb06e
[table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7803
diff
changeset
|
57 |
('/cwsource$', {'vid': 'cw.sources-management'}), |
4390 | 58 |
('/schema/([^/]+?)/?$', {'rql': r'Any X WHERE X is CWEType, X name "\1"', 'vid': 'primary'}), |
0 | 59 |
('/add/([^/]+?)/?$' , dict(vid='creation', etype=r'\1')), |
60 |
('/doc/images/(.+?)/?$', dict(fid='\\1', vid='wdocimages')), |
|
61 |
('/doc/?$', dict(fid='main', vid='wdoc')), |
|
62 |
('/doc/(.+?)/?$', dict(fid='\\1', vid='wdoc')), |
|
63 |
# now in SchemaBasedRewriter |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
64 |
#('/search/(.+)$', dict(rql=r'Any X WHERE X has_text "\1"')), |
0 | 65 |
]) |
66 |
||
67 |
||
68 |
def test_no_extend_rules(self): |
|
69 |
class Rewriter(SimpleReqRewriter): |
|
70 |
ignore_baseclass_rules = True |
|
71 |
rules = [ |
|
72 |
('foo', dict(rql='Foo F')), |
|
73 |
('/index', dict(vid='index2')), |
|
74 |
] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
75 |
self.assertListEqual(Rewriter.rules, [ |
0 | 76 |
('foo' , dict(rql='Foo F')), |
77 |
('/index' , dict(vid='index2')), |
|
78 |
]) |
|
79 |
||
80 |
def test_basic_transformation(self): |
|
81 |
"""test simple string-based rewrite""" |
|
82 |
req = FakeRequest() |
|
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
83 |
rewriter = SimpleReqRewriter(req) |
0 | 84 |
self.assertRaises(KeyError, rewriter.rewrite, req, '/view?vid=whatever') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
85 |
self.assertEqual(req.form, {}) |
0 | 86 |
rewriter.rewrite(req, '/index') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
87 |
self.assertEqual(req.form, {'vid' : "index"}) |
0 | 88 |
|
89 |
def test_regexp_transformation(self): |
|
90 |
"""test regexp-based rewrite""" |
|
91 |
req = FakeRequest() |
|
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
92 |
rewriter = SimpleReqRewriter(req) |
0 | 93 |
rewriter.rewrite(req, '/add/Task') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
94 |
self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
0 | 95 |
req = FakeRequest() |
96 |
rewriter.rewrite(req, '/add/Task/') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
97 |
self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
0 | 98 |
|
99 |
||
100 |
||
101 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2439
diff
changeset
|
102 |
class RgxActionRewriteTC(CubicWebTC): |
0 | 103 |
|
104 |
def setup_database(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7017
diff
changeset
|
105 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7017
diff
changeset
|
106 |
self.p1 = self.create_user(req, u'user1') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7992
diff
changeset
|
107 |
self.p1.cw_set(firstname=u'joe', surname=u'Dalton') |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7017
diff
changeset
|
108 |
self.p2 = self.create_user(req, u'user2') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7992
diff
changeset
|
109 |
self.p2.cw_set(firstname=u'jack', surname=u'Dalton') |
0 | 110 |
|
111 |
def test_rgx_action_with_transforms(self): |
|
112 |
class TestSchemaBasedRewriter(SchemaBasedRewriter): |
|
113 |
rules = [ |
|
114 |
(rgx('/(?P<sn>\w+)/(?P<fn>\w+)'), rgx_action(r'Any X WHERE X surname %(sn)s, X firstname %(fn)s', |
|
115 |
argsgroups=('sn', 'fn'), |
|
116 |
transforms={'sn' : unicode.capitalize, |
|
117 |
'fn' : unicode.lower,})), |
|
118 |
] |
|
119 |
req = self.request() |
|
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
120 |
rewriter = TestSchemaBasedRewriter(req) |
0 | 121 |
pmid, rset = rewriter.rewrite(req, u'/DaLToN/JoE') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
122 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
123 |
self.assertEqual(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
|
124 |
|
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
125 |
def test_inheritance_precedence(self): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
126 |
RQL1 = 'Any C WHERE C is CWEType' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
127 |
RQL2 = 'Any C WHERE C is CWUser' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
128 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
129 |
class BaseRewriter(SchemaBasedRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
130 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
131 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
132 |
rgx_action(rql=RQL1, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
133 |
form=dict(vid='baseindex')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
134 |
), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
135 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
136 |
class Rewriter(BaseRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
137 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
138 |
(rgx('/collector/something(/?)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
139 |
rgx_action(rql=RQL2, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
140 |
form=dict(vid='index')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
141 |
), |
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 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
144 |
req = self.request() |
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
145 |
rewriter = Rewriter(req) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
146 |
pmid, rset = rewriter.rewrite(req, '/collector') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
147 |
self.assertEqual(rset.rql, RQL1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
148 |
self.assertEqual(req.form, {'vid' : "baseindex"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
149 |
pmid, rset = rewriter.rewrite(req, '/collector/something') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
150 |
self.assertEqual(rset.rql, RQL2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
151 |
self.assertEqual(req.form, {'vid' : "index"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
152 |
pmid, rset = rewriter.rewrite(req, '/collector/something/') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
153 |
self.assertEqual(req.form, {'vid' : "index"}) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
154 |
self.assertEqual(rset.rql, RQL2) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
155 |
pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
156 |
self.assertEqual(rset.rql, RQL1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
157 |
self.assertEqual(req.form, {'vid' : "baseindex"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
158 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
159 |
def test_inheritance_precedence_same_rgx(self): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
160 |
RQL1 = 'Any C WHERE C is CWEType' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
161 |
RQL2 = 'Any C WHERE C is CWUser' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
162 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
163 |
class BaseRewriter(SchemaBasedRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
164 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
165 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
166 |
rgx_action(rql=RQL1, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
167 |
form=dict(vid='baseindex')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
168 |
), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
169 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
170 |
class Rewriter(BaseRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
171 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
172 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
173 |
rgx_action(rql=RQL2, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
174 |
form=dict(vid='index')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
175 |
), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
176 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
177 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
178 |
req = self.request() |
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
179 |
rewriter = Rewriter(req) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
180 |
pmid, rset = rewriter.rewrite(req, '/collector') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
181 |
self.assertEqual(rset.rql, RQL2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
182 |
self.assertEqual(req.form, {'vid' : "index"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
183 |
pmid, rset = rewriter.rewrite(req, '/collector/something') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
184 |
self.assertEqual(rset.rql, RQL2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
185 |
self.assertEqual(req.form, {'vid' : "index"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
186 |
pmid, rset = rewriter.rewrite(req, '/collector/something/') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
187 |
self.assertEqual(req.form, {'vid' : "index"}) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
188 |
self.assertEqual(rset.rql, RQL2) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
189 |
pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
190 |
self.assertEqual(rset.rql, RQL2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
191 |
self.assertEqual(req.form, {'vid' : "index"}) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
192 |
|
0 | 193 |
|
194 |
if __name__ == '__main__': |
|
195 |
unittest_main() |