author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 09 Nov 2015 15:29:07 +0100 | |
changeset 10871 | 1d4a94d04ec6 |
parent 10725 | 1776c94a74e8 |
permissions | -rw-r--r-- |
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
1 |
# copyright 2003-2014 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/>. |
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
18 |
|
10725
1776c94a74e8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10399
diff
changeset
|
19 |
from six import text_type |
1776c94a74e8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10399
diff
changeset
|
20 |
|
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
21 |
from logilab.common import tempattr |
0 | 22 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2439
diff
changeset
|
23 |
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
|
24 |
from cubicweb.devtools.fake import FakeRequest |
0 | 25 |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
26 |
from cubicweb.web.views.urlrewrite import (SimpleReqRewriter, SchemaBasedRewriter, |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
27 |
rgx, rgx_action) |
0 | 28 |
|
29 |
||
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
30 |
class UrlRewriteTC(CubicWebTC): |
0 | 31 |
|
32 |
def test_auto_extend_rules(self): |
|
33 |
class Rewriter(SimpleReqRewriter): |
|
34 |
rules = [ |
|
35 |
('foo', dict(rql='Foo F')), |
|
36 |
('/index', dict(vid='index2')), |
|
37 |
] |
|
38 |
rules = [] |
|
39 |
for pattern, values in Rewriter.rules: |
|
40 |
if hasattr(pattern, 'pattern'): |
|
41 |
pattern = pattern.pattern |
|
42 |
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
|
43 |
self.assertListEqual(rules, [ |
0 | 44 |
('foo' , dict(rql='Foo F')), |
45 |
('/index' , dict(vid='index2')), |
|
2780
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2439
diff
changeset
|
46 |
('/_', dict(vid='manage')), |
ad1dfc3855b0
B web/tests back to green
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2439
diff
changeset
|
47 |
('/_registry', dict(vid='registry')), |
2439
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
48 |
('/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
|
49 |
('/myprefs', dict(vid='propertiesform')), |
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1802
diff
changeset
|
50 |
('/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
|
51 |
('/siteinfo', dict(vid='siteinfo')), |
0 | 52 |
('/manage', dict(vid='manage')), |
2439
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
53 |
('/notfound', dict(vid='404')), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
54 |
('/error', dict(vid='error')), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
55 |
('/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
|
56 |
('/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
|
57 |
('/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
|
58 |
'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
|
59 |
('/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
|
60 |
'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
|
61 |
('/cwsource$', {'vid': 'cw.sources-management'}), |
4390 | 62 |
('/schema/([^/]+?)/?$', {'rql': r'Any X WHERE X is CWEType, X name "\1"', 'vid': 'primary'}), |
0 | 63 |
('/add/([^/]+?)/?$' , dict(vid='creation', etype=r'\1')), |
64 |
('/doc/images/(.+?)/?$', dict(fid='\\1', vid='wdocimages')), |
|
65 |
('/doc/?$', dict(fid='main', vid='wdoc')), |
|
66 |
('/doc/(.+?)/?$', dict(fid='\\1', vid='wdoc')), |
|
67 |
# now in SchemaBasedRewriter |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
68 |
#('/search/(.+)$', dict(rql=r'Any X WHERE X has_text "\1"')), |
0 | 69 |
]) |
70 |
||
71 |
||
72 |
def test_no_extend_rules(self): |
|
73 |
class Rewriter(SimpleReqRewriter): |
|
74 |
ignore_baseclass_rules = True |
|
75 |
rules = [ |
|
76 |
('foo', dict(rql='Foo F')), |
|
77 |
('/index', dict(vid='index2')), |
|
78 |
] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
79 |
self.assertListEqual(Rewriter.rules, [ |
0 | 80 |
('foo' , dict(rql='Foo F')), |
81 |
('/index' , dict(vid='index2')), |
|
82 |
]) |
|
83 |
||
84 |
def test_basic_transformation(self): |
|
85 |
"""test simple string-based rewrite""" |
|
86 |
req = FakeRequest() |
|
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
87 |
rewriter = SimpleReqRewriter(req) |
0 | 88 |
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
|
89 |
self.assertEqual(req.form, {}) |
0 | 90 |
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
|
91 |
self.assertEqual(req.form, {'vid' : "index"}) |
0 | 92 |
|
93 |
def test_regexp_transformation(self): |
|
94 |
"""test regexp-based rewrite""" |
|
95 |
req = FakeRequest() |
|
3465
01616e5fa590
[tests] make unittest_urlrewrite pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3185
diff
changeset
|
96 |
rewriter = SimpleReqRewriter(req) |
0 | 97 |
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
|
98 |
self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
0 | 99 |
req = FakeRequest() |
100 |
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
|
101 |
self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
0 | 102 |
|
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
103 |
def test_inheritance(self): |
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
104 |
BaseTransition = self.vreg['etypes'].etype_class('BaseTransition') |
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
105 |
with self.admin_access.web_request() as req: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
106 |
x = req.create_entity('WorkflowTransition', name=u'test') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
107 |
ctrlid, rset = self.app.url_resolver.process(req, 'basetransition/%s' % x.eid) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
108 |
self.assertEqual(ctrlid, 'view') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
109 |
self.assertEqual(x.eid, rset[0][0]) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
110 |
# cw_rest_attr_info is cached but clear_cache doesn't like cached class |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
111 |
# method |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
112 |
del BaseTransition._cw_rest_attr_info_cache_ |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
113 |
try: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
114 |
with tempattr(BaseTransition, 'rest_attr', 'name'): |
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
115 |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
116 |
ctrlid, rset = self.app.url_resolver.process(req, 'basetransition/%s' % x.name) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
117 |
self.assertEqual(ctrlid, 'view') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
118 |
self.assertEqual(x.eid, rset[0][0]) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
119 |
finally: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
120 |
del BaseTransition._cw_rest_attr_info_cache_ |
0 | 121 |
|
122 |
||
123 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2439
diff
changeset
|
124 |
class RgxActionRewriteTC(CubicWebTC): |
0 | 125 |
|
126 |
def setup_database(self): |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
127 |
with self.admin_access.repo_cnx() as cnx: |
9841
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
128 |
p1 = self.create_user(cnx, u'user1') |
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
129 |
p1.cw_set(firstname=u'joe', surname=u'Dalton') |
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
130 |
p2 = self.create_user(cnx, u'user2') |
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
131 |
p2.cw_set(firstname=u'jack', surname=u'Dalton') |
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
132 |
self.p1eid = p1.eid |
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
133 |
cnx.commit() |
0 | 134 |
|
135 |
def test_rgx_action_with_transforms(self): |
|
136 |
class TestSchemaBasedRewriter(SchemaBasedRewriter): |
|
137 |
rules = [ |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
138 |
(rgx('/(?P<sn>\w+)/(?P<fn>\w+)'), |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
139 |
rgx_action(r'Any X WHERE X surname %(sn)s, ' |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
140 |
'X firstname %(fn)s', |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
141 |
argsgroups=('sn', 'fn'), |
10725
1776c94a74e8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10399
diff
changeset
|
142 |
transforms={'sn' : text_type.capitalize, |
1776c94a74e8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10399
diff
changeset
|
143 |
'fn' : text_type.lower,})), |
0 | 144 |
] |
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
145 |
with self.admin_access.web_request() as req: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
146 |
rewriter = TestSchemaBasedRewriter(req) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
147 |
_pmid, rset = rewriter.rewrite(req, u'/DaLToN/JoE') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
148 |
self.assertEqual(len(rset), 1) |
9841
d2e196f12db4
[webtests/urlrewrite] do not store a plain entity on the test, only an eid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9840
diff
changeset
|
149 |
self.assertEqual(rset[0][0], self.p1eid) |
10399
5234525560ac
[web, urlrewrite] remove unused `cachekey` argument from `rgx_action` (closes #5355967)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9841
diff
changeset
|
150 |
self.assertEqual(rset.description[0][0], 'CWUser') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
151 |
|
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
152 |
def test_inheritance_precedence(self): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
153 |
RQL1 = 'Any C WHERE C is CWEType' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
154 |
RQL2 = 'Any C WHERE C is CWUser' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
155 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
156 |
class BaseRewriter(SchemaBasedRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
157 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
158 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
159 |
rgx_action(rql=RQL1, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
160 |
form=dict(vid='baseindex')), |
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 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
163 |
class Rewriter(BaseRewriter): |
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/something(/?)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
166 |
rgx_action(rql=RQL2, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
167 |
form=dict(vid='index')), |
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 |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
171 |
with self.admin_access.web_request() as req: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
172 |
rewriter = Rewriter(req) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
173 |
_pmid, rset = rewriter.rewrite(req, '/collector') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
174 |
self.assertEqual(rset.rql, RQL1) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
175 |
self.assertEqual(req.form, {'vid' : "baseindex"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
176 |
_pmid, rset = rewriter.rewrite(req, '/collector/something') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
177 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
178 |
self.assertEqual(req.form, {'vid' : "index"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
179 |
_pmid, rset = rewriter.rewrite(req, '/collector/something/') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
180 |
self.assertEqual(req.form, {'vid' : "index"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
181 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
182 |
_pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
183 |
self.assertEqual(rset.rql, RQL1) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
184 |
self.assertEqual(req.form, {'vid' : "baseindex"}) |
3168
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
185 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
186 |
def test_inheritance_precedence_same_rgx(self): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
187 |
RQL1 = 'Any C WHERE C is CWEType' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
188 |
RQL2 = 'Any C WHERE C is CWUser' |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
189 |
|
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
190 |
class BaseRewriter(SchemaBasedRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
191 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
192 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
193 |
rgx_action(rql=RQL1, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
194 |
form=dict(vid='baseindex')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
195 |
), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
196 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
197 |
class Rewriter(BaseRewriter): |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
198 |
rules = [ |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
199 |
(rgx('/collector(.*)'), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
200 |
rgx_action(rql=RQL2, |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
201 |
form=dict(vid='index')), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
202 |
), |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
203 |
] |
1ecd1b6d6f1b
[tests] inheritance_precedence in url rewrite
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
2780
diff
changeset
|
204 |
|
9840
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
205 |
with self.admin_access.web_request() as req: |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
206 |
rewriter = Rewriter(req) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
207 |
_pmid, rset = rewriter.rewrite(req, '/collector') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
208 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
209 |
self.assertEqual(req.form, {'vid' : "index"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
210 |
_pmid, rset = rewriter.rewrite(req, '/collector/something') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
211 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
212 |
self.assertEqual(req.form, {'vid' : "index"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
213 |
_pmid, rset = rewriter.rewrite(req, '/collector/something/') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
214 |
self.assertEqual(req.form, {'vid' : "index"}) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
215 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
216 |
_pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
217 |
self.assertEqual(rset.rql, RQL2) |
92ea0a4746e2
[webtests/urlrewrite] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
218 |
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
|
219 |
|
0 | 220 |
|
221 |
if __name__ == '__main__': |
|
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8632
diff
changeset
|
222 |
from logilab.common.testlib import unittest_main |
0 | 223 |
unittest_main() |