1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 from logilab.common.testlib import TestCase, unittest_main |
18 |
|
19 from logilab.common import tempattr |
19 |
20 |
20 from cubicweb.devtools.testlib import CubicWebTC |
21 from cubicweb.devtools.testlib import CubicWebTC |
21 from cubicweb.devtools.fake import FakeRequest |
22 from cubicweb.devtools.fake import FakeRequest |
22 |
23 |
23 from cubicweb.web.views.urlrewrite import SimpleReqRewriter, SchemaBasedRewriter, rgx, rgx_action |
24 from cubicweb.web.views.urlrewrite import SimpleReqRewriter, SchemaBasedRewriter, rgx, rgx_action |
94 self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
95 self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
95 req = FakeRequest() |
96 req = FakeRequest() |
96 rewriter.rewrite(req, '/add/Task/') |
97 rewriter.rewrite(req, '/add/Task/') |
97 self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
98 self.assertEqual(req.form, {'vid' : "creation", 'etype' : "Task"}) |
98 |
99 |
|
100 def test_inheritance(self): |
|
101 BaseTransition = self.vreg['etypes'].etype_class('BaseTransition') |
|
102 req = self.request() |
|
103 x = req.create_entity('WorkflowTransition', name=u'test') |
|
104 ctrlid, rset = self.app.url_resolver.process(req, 'basetransition/%s' % x.eid) |
|
105 self.assertEqual(ctrlid, 'view') |
|
106 self.assertEqual(x.eid, rset[0][0]) |
|
107 # cw_rest_attr_info is cached but clear_cache doesn't like cached class |
|
108 # method |
|
109 del BaseTransition._cw_rest_attr_info_cache_ |
|
110 try: |
|
111 with tempattr(BaseTransition, 'rest_attr', 'name'): |
|
112 |
|
113 ctrlid, rset = self.app.url_resolver.process(req, 'basetransition/%s' % x.name) |
|
114 self.assertEqual(ctrlid, 'view') |
|
115 self.assertEqual(x.eid, rset[0][0]) |
|
116 finally: |
|
117 del BaseTransition._cw_rest_attr_info_cache_ |
99 |
118 |
100 |
119 |
101 |
120 |
102 class RgxActionRewriteTC(CubicWebTC): |
121 class RgxActionRewriteTC(CubicWebTC): |
103 |
122 |