author | sylvain.thenault@logilab.fr |
Thu, 07 May 2009 16:33:22 +0200 | |
branch | tls-sprint |
changeset 1714 | a721966779be |
parent 1398 | 5fe84a5f7035 |
child 1570 | 5c40d9fb4e8d |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
"""XXX rename, split, reorganize this |
|
3 |
""" |
|
783 | 4 |
from __future__ import with_statement |
0 | 5 |
|
783 | 6 |
from logilab.common.testlib import unittest_main |
793 | 7 |
|
0 | 8 |
from cubicweb.devtools.apptest import EnvBasedTC |
9 |
from cubicweb import CW_SOFTWARE_ROOT as BASE, Binary |
|
793 | 10 |
from cubicweb.selectors import (match_user_groups, implements, |
11 |
specified_etype_implements, rql_condition, |
|
12 |
traced_selection) |
|
13 |
from cubicweb.web import NoSelectableObject |
|
0 | 14 |
from cubicweb.web.action import Action |
15 |
from cubicweb.web.views import (baseviews, tableview, baseforms, calendar, |
|
444 | 16 |
management, embedding, actions, startup, |
783 | 17 |
euser, schemaentities, xbel, vcard, owl, |
18 |
treeview, idownloadable, wdoc, debug, eproperties) |
|
0 | 19 |
|
20 |
USERACTIONS = [('myprefs', actions.UserPreferencesAction), |
|
21 |
('myinfos', actions.UserInfoAction), |
|
22 |
('logout', actions.LogoutAction)] |
|
23 |
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction), |
|
24 |
('manage', actions.ManageAction), |
|
25 |
('schema', actions.ViewSchemaAction)] |
|
26 |
||
27 |
||
28 |
class ViewSelectorTC(EnvBasedTC): |
|
29 |
||
30 |
def setup_database(self): |
|
31 |
self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau") |
|
32 |
self.add_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
|
33 |
self.add_entity('Card', title=u'mandatory', content=u"DoC !") |
|
34 |
self.add_entity('EmailAddress', address=u"devel@logilab.fr", alias=u'devel') |
|
35 |
self.add_entity('Tag', name=u'x') |
|
36 |
||
37 |
def pactions(self, req, rset): |
|
38 |
resdict = self.vreg.possible_actions(req, rset) |
|
39 |
for cat, actions in resdict.items(): |
|
40 |
resdict[cat] = [(a.id, a.__class__) for a in actions] |
|
41 |
return resdict |
|
42 |
||
43 |
||
44 |
class VRegistryTC(ViewSelectorTC): |
|
45 |
"""test the view selector""" |
|
46 |
||
47 |
def _test_registered(self, registry, content): |
|
48 |
try: |
|
49 |
expected = getattr(self, 'all_%s' % registry) |
|
50 |
except AttributeError: |
|
51 |
return |
|
52 |
if registry == 'hooks': |
|
53 |
self.assertEquals(len(content), expected, content) |
|
54 |
return |
|
55 |
try: |
|
56 |
self.assertSetEqual(content.keys(), expected) |
|
57 |
except: |
|
58 |
print registry, sorted(expected), sorted(content.keys()) |
|
59 |
print 'no more', [v for v in expected if not v in content.keys()] |
|
60 |
print 'missing', [v for v in content.keys() if not v in expected] |
|
61 |
raise |
|
62 |
||
63 |
||
793 | 64 |
def test_possible_views_none_rset(self): |
0 | 65 |
req = self.request() |
66 |
self.assertListEqual(self.pviews(req, None), |
|
67 |
[('changelog', wdoc.ChangeLogView), |
|
68 |
('debug', debug.DebugView), |
|
783 | 69 |
('epropertiesform', eproperties.EPropertiesForm), |
0 | 70 |
('index', startup.IndexView), |
71 |
('info', management.ProcessInformationView), |
|
72 |
('manage', startup.ManageView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
73 |
('owl', owl.OWLView), |
0 | 74 |
('schema', startup.SchemaView), |
783 | 75 |
('systemepropertiesform', eproperties.SystemEPropertiesForm)]) |
793 | 76 |
|
77 |
def test_possible_views_noresult(self): |
|
0 | 78 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
79 |
self.assertListEqual(self.pviews(req, rset), |
|
783 | 80 |
[]) |
793 | 81 |
|
82 |
def test_possible_views_one_egroup(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
83 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 84 |
self.assertListEqual(self.pviews(req, rset), |
85 |
[('csvexport', baseviews.CSVRsetView), |
|
86 |
('ecsvexport', baseviews.CSVEntityView), |
|
87 |
('editable-table', tableview.EditableTableView), |
|
444 | 88 |
('filetree', treeview.FileTreeView), |
0 | 89 |
('list', baseviews.ListView), |
90 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
91 |
('owlabox', owl.OWLABOXView), |
0 | 92 |
('primary', baseviews.PrimaryView), |
444 | 93 |
('rsetxml', baseviews.XMLRsetView), |
0 | 94 |
('rss', baseviews.RssView), |
95 |
('secondary', baseviews.SecondaryView), |
|
96 |
('security', management.SecurityManagementView), |
|
97 |
('table', tableview.TableView), |
|
98 |
('text', baseviews.TextView), |
|
444 | 99 |
('treeview', treeview.TreeView), |
0 | 100 |
('xbel', xbel.XbelView), |
101 |
('xml', baseviews.XmlView), |
|
102 |
]) |
|
793 | 103 |
|
104 |
def test_possible_views_multiple_egroups(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
105 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 106 |
self.assertListEqual(self.pviews(req, rset), |
107 |
[('csvexport', baseviews.CSVRsetView), |
|
108 |
('ecsvexport', baseviews.CSVEntityView), |
|
109 |
('editable-table', tableview.EditableTableView), |
|
444 | 110 |
('filetree', treeview.FileTreeView), |
0 | 111 |
('list', baseviews.ListView), |
112 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
113 |
('owlabox', owl.OWLABOXView), |
0 | 114 |
('primary', baseviews.PrimaryView), |
444 | 115 |
('rsetxml', baseviews.XMLRsetView), |
0 | 116 |
('rss', baseviews.RssView), |
117 |
('secondary', baseviews.SecondaryView), |
|
118 |
('security', management.SecurityManagementView), |
|
119 |
('table', tableview.TableView), |
|
120 |
('text', baseviews.TextView), |
|
444 | 121 |
('treeview', treeview.TreeView), |
0 | 122 |
('xbel', xbel.XbelView), |
123 |
('xml', baseviews.XmlView), |
|
124 |
]) |
|
793 | 125 |
|
126 |
def test_possible_views_multiple_different_types(self): |
|
0 | 127 |
rset, req = self.env.get_rset_and_req('Any X') |
128 |
self.assertListEqual(self.pviews(req, rset), |
|
129 |
[('csvexport', baseviews.CSVRsetView), |
|
130 |
('ecsvexport', baseviews.CSVEntityView), |
|
131 |
('editable-table', tableview.EditableTableView), |
|
444 | 132 |
('filetree', treeview.FileTreeView), |
0 | 133 |
('list', baseviews.ListView), |
134 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
135 |
('owlabox', owl.OWLABOXView), |
0 | 136 |
('primary', baseviews.PrimaryView), |
444 | 137 |
('rsetxml', baseviews.XMLRsetView), |
0 | 138 |
('rss', baseviews.RssView), |
139 |
('secondary', baseviews.SecondaryView), |
|
140 |
('security', management.SecurityManagementView), |
|
141 |
('table', tableview.TableView), |
|
142 |
('text', baseviews.TextView), |
|
444 | 143 |
('treeview', treeview.TreeView), |
0 | 144 |
('xbel', xbel.XbelView), |
145 |
('xml', baseviews.XmlView), |
|
146 |
]) |
|
793 | 147 |
|
148 |
def test_possible_views_any_rset(self): |
|
0 | 149 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
150 |
self.assertListEqual(self.pviews(req, rset), |
|
151 |
[('csvexport', baseviews.CSVRsetView), |
|
152 |
('editable-table', tableview.EditableTableView), |
|
444 | 153 |
('rsetxml', baseviews.XMLRsetView), |
0 | 154 |
('table', tableview.TableView), |
155 |
]) |
|
793 | 156 |
|
157 |
def test_possible_views_multiple_eusers(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
158 |
rset, req = self.env.get_rset_and_req('CWUser X') |
0 | 159 |
self.assertListEqual(self.pviews(req, rset), |
160 |
[('csvexport', baseviews.CSVRsetView), |
|
161 |
('ecsvexport', baseviews.CSVEntityView), |
|
162 |
('editable-table', tableview.EditableTableView), |
|
444 | 163 |
('filetree', treeview.FileTreeView), |
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
164 |
('foaf', euser.FoafView), |
0 | 165 |
('list', baseviews.ListView), |
166 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
167 |
('owlabox', owl.OWLABOXView), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
168 |
('primary', euser.CWUserPrimaryView), |
444 | 169 |
('rsetxml', baseviews.XMLRsetView), |
0 | 170 |
('rss', baseviews.RssView), |
171 |
('secondary', baseviews.SecondaryView), |
|
172 |
('security', management.SecurityManagementView), |
|
173 |
('table', tableview.TableView), |
|
174 |
('text', baseviews.TextView), |
|
444 | 175 |
('treeview', treeview.TreeView), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
176 |
('vcard', vcard.VCardCWUserView), |
0 | 177 |
('xbel', xbel.XbelView), |
178 |
('xml', baseviews.XmlView), |
|
179 |
]) |
|
180 |
||
181 |
def test_possible_actions_none_rset(self): |
|
182 |
req = self.request() |
|
183 |
self.assertDictEqual(self.pactions(req, None), |
|
184 |
{'useractions': USERACTIONS, |
|
185 |
'siteactions': SITEACTIONS, |
|
793 | 186 |
|
0 | 187 |
}) |
188 |
def test_possible_actions_no_entity(self): |
|
189 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
190 |
self.assertDictEqual(self.pactions(req, rset), |
|
191 |
{'useractions': USERACTIONS, |
|
192 |
'siteactions': SITEACTIONS, |
|
193 |
}) |
|
793 | 194 |
|
0 | 195 |
def test_possible_actions_same_type_entities(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
196 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 197 |
self.assertDictEqual(self.pactions(req, rset), |
198 |
{'useractions': USERACTIONS, |
|
199 |
'siteactions': SITEACTIONS, |
|
200 |
'mainactions': [('muledit', actions.MultipleEditAction)], |
|
201 |
'moreactions': [('delete', actions.DeleteAction), |
|
202 |
('addentity', actions.AddNewAction)], |
|
203 |
}) |
|
793 | 204 |
|
0 | 205 |
def test_possible_actions_different_types_entities(self): |
206 |
rset, req = self.env.get_rset_and_req('Any X') |
|
207 |
self.assertDictEqual(self.pactions(req, rset), |
|
208 |
{'useractions': USERACTIONS, |
|
209 |
'siteactions': SITEACTIONS, |
|
210 |
'moreactions': [('delete', actions.DeleteAction)], |
|
211 |
}) |
|
793 | 212 |
|
0 | 213 |
def test_possible_actions_final_entities(self): |
214 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
215 |
self.assertDictEqual(self.pactions(req, rset), |
|
216 |
{'useractions': USERACTIONS, |
|
217 |
'siteactions': SITEACTIONS}) |
|
218 |
||
219 |
def test_possible_actions_eetype_euser_entity(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
220 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWUser"') |
0 | 221 |
self.assertDictEqual(self.pactions(req, rset), |
222 |
{'useractions': USERACTIONS, |
|
223 |
'siteactions': SITEACTIONS, |
|
224 |
'mainactions': [('edit', actions.ModifyAction), |
|
225 |
('workflow', schemaentities.ViewWorkflowAction),], |
|
226 |
'moreactions': [('delete', actions.DeleteAction), |
|
793 | 227 |
('copy', actions.CopyAction), |
228 |
('managepermission', actions.ManagePermissionsAction)], |
|
0 | 229 |
}) |
230 |
||
231 |
||
232 |
def test_select_creation_form(self): |
|
233 |
rset = None |
|
234 |
req = self.request() |
|
235 |
# creation form |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
236 |
req.form['etype'] = 'CWGroup' |
0 | 237 |
self.assertIsInstance(self.vreg.select_view('creation', req, rset), |
238 |
baseforms.CreationForm) |
|
239 |
del req.form['etype'] |
|
240 |
# custom creation form |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
241 |
class CWUserCreationForm(baseforms.CreationForm): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
242 |
__select__ = specified_etype_implements('CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
243 |
self.vreg.register_vobject_class(CWUserCreationForm) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
244 |
req.form['etype'] = 'CWUser' |
0 | 245 |
self.assertIsInstance(self.vreg.select_view('creation', req, rset), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
246 |
CWUserCreationForm) |
0 | 247 |
|
248 |
def test_select_view(self): |
|
249 |
# no entity |
|
250 |
rset = None |
|
251 |
req = self.request() |
|
252 |
self.assertIsInstance(self.vreg.select_view('index', req, rset), |
|
253 |
startup.IndexView) |
|
254 |
self.failUnlessRaises(NoSelectableObject, |
|
255 |
self.vreg.select_view, 'primary', req, rset) |
|
256 |
self.failUnlessRaises(NoSelectableObject, |
|
257 |
self.vreg.select_view, 'table', req, rset) |
|
258 |
||
259 |
# no entity |
|
260 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
261 |
self.failUnlessRaises(NoSelectableObject, |
|
262 |
self.vreg.select_view, 'index', req, rset) |
|
263 |
self.failUnlessRaises(NoSelectableObject, |
|
264 |
self.vreg.select_view, 'creation', req, rset) |
|
265 |
self.failUnlessRaises(NoSelectableObject, |
|
266 |
self.vreg.select_view, 'primary', req, rset) |
|
267 |
self.failUnlessRaises(NoSelectableObject, |
|
268 |
self.vreg.select_view, 'table', req, rset) |
|
269 |
# one entity |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
270 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 271 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
272 |
baseviews.PrimaryView) |
|
273 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
|
274 |
baseviews.ListView) |
|
275 |
self.assertIsInstance(self.vreg.select_view('edition', req, rset), |
|
276 |
baseforms.EditionForm) |
|
277 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
278 |
tableview.TableView) |
|
279 |
self.failUnlessRaises(NoSelectableObject, |
|
280 |
self.vreg.select_view, 'creation', req, rset) |
|
281 |
self.failUnlessRaises(NoSelectableObject, |
|
282 |
self.vreg.select_view, 'index', req, rset) |
|
283 |
# list of entities of the same type |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
284 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 285 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
286 |
baseviews.PrimaryView) |
|
287 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
|
288 |
baseviews.ListView) |
|
289 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
290 |
tableview.TableView) |
|
291 |
self.failUnlessRaises(NoSelectableObject, |
|
292 |
self.vreg.select_view, 'creation', req, rset) |
|
293 |
# list of entities of different types |
|
294 |
rset, req = self.env.get_rset_and_req('Any X') |
|
295 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
296 |
baseviews.PrimaryView) |
|
297 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
|
298 |
baseviews.ListView) |
|
299 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
300 |
tableview.TableView) |
|
301 |
self.failUnlessRaises(NoSelectableObject, |
|
302 |
self.vreg.select_view, 'creation', req, rset) |
|
303 |
self.failUnlessRaises(NoSelectableObject, |
|
304 |
self.vreg.select_view, 'index', req, rset) |
|
305 |
# whatever |
|
306 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
307 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
308 |
tableview.TableView) |
|
309 |
self.failUnlessRaises(NoSelectableObject, |
|
310 |
self.vreg.select_view, 'index', req, rset) |
|
311 |
self.failUnlessRaises(NoSelectableObject, |
|
312 |
self.vreg.select_view, 'creation', req, rset) |
|
313 |
self.failUnlessRaises(NoSelectableObject, |
|
314 |
self.vreg.select_view, 'primary', req, rset) |
|
315 |
self.failUnlessRaises(NoSelectableObject, |
|
316 |
self.vreg.select_view, 'list', req, rset) |
|
317 |
self.failUnlessRaises(NoSelectableObject, |
|
318 |
self.vreg.select_view, 'edition', req, rset) |
|
319 |
# mixed query |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
320 |
rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup') |
0 | 321 |
self.failUnlessRaises(NoSelectableObject, |
322 |
self.vreg.select_view, 'edition', req, rset) |
|
323 |
self.failUnlessRaises(NoSelectableObject, |
|
324 |
self.vreg.select_view, 'creation', req, rset) |
|
325 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
326 |
tableview.TableView) |
|
327 |
# euser primary view priority |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
328 |
rset, req = self.env.get_rset_and_req('CWUser X WHERE X login "admin"') |
0 | 329 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
330 |
euser.CWUserPrimaryView) |
0 | 331 |
self.assertIsInstance(self.vreg.select_view('text', req, rset), |
332 |
baseviews.TextView) |
|
333 |
||
334 |
def test_interface_selector(self): |
|
335 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
336 |
# image primary view priority |
|
337 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
338 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
339 |
idownloadable.IDownloadablePrimaryView) |
|
340 |
||
341 |
||
342 |
def test_score_entity_selector(self): |
|
343 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
344 |
# image primary view priority |
|
345 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
346 |
self.assertIsInstance(self.vreg.select_view('image', req, rset), |
|
347 |
idownloadable.ImageView) |
|
348 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
349 |
# image primary view priority |
|
350 |
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"') |
|
351 |
self.assertRaises(NoSelectableObject, self.vreg.select_view, 'image', req, rset) |
|
352 |
||
353 |
||
354 |
||
355 |
def _test_view(self, vid, rql, args): |
|
356 |
if rql is None: |
|
357 |
rset = None |
|
358 |
req = self.request() |
|
359 |
else: |
|
360 |
rset, req = self.env.get_rset_and_req(rql) |
|
361 |
try: |
|
362 |
self.vreg.render('views', vid, req, rset=rset, **args) |
|
363 |
except: |
|
364 |
print vid, rset, args |
|
365 |
raise |
|
366 |
||
367 |
def test_form(self): |
|
368 |
for vid, rql, args in ( |
|
369 |
#('creation', 'Any X WHERE X eid 999999', {}), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
370 |
('edition', 'CWGroup X WHERE X name "managers"', {}), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
371 |
('copy', 'CWGroup X WHERE X name "managers"', {}), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
372 |
('muledit', 'CWGroup X', {}), |
0 | 373 |
#('muledit', 'Any X', {}), |
374 |
): |
|
375 |
self._test_view(vid, rql, args) |
|
376 |
||
377 |
||
378 |
def test_properties(self): |
|
379 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
380 |
if k.startswith('boxes.edit_box')), |
|
381 |
['boxes.edit_box.context', |
|
382 |
'boxes.edit_box.order', |
|
383 |
'boxes.edit_box.visible']) |
|
384 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
385 |
if not k.startswith('system.version')], |
|
386 |
[]) |
|
387 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
388 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
389 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
390 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
391 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
392 |
||
393 |
||
394 |
||
431 | 395 |
def test_owners_match_user_group(self): |
396 |
"""tests usage of 'owners' group with match_user_group""" |
|
0 | 397 |
class SomeAction(Action): |
398 |
id = 'yo' |
|
399 |
category = 'foo' |
|
764 | 400 |
__select__ = match_user_groups('owners') |
0 | 401 |
self.vreg.register_vobject_class(SomeAction) |
402 |
self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
|
403 |
try: |
|
404 |
# login as a simple user |
|
405 |
self.create_user('john') |
|
406 |
self.login('john') |
|
407 |
# it should not be possible to use SomeAction not owned objects |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
408 |
rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
0 | 409 |
self.failIf('foo' in self.pactions(req, rset)) |
410 |
# insert a new card, and check that we can use SomeAction on our object |
|
411 |
self.execute('INSERT Card C: C title "zoubidou"') |
|
412 |
self.commit() |
|
413 |
rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
|
414 |
self.failUnless('foo' in self.pactions(req, rset)) |
|
415 |
# make sure even managers can't use the action |
|
416 |
self.restore_connection() |
|
417 |
rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
|
418 |
self.failIf('foo' in self.pactions(req, rset)) |
|
419 |
finally: |
|
420 |
del self.vreg[SomeAction.__registry__][SomeAction.id] |
|
421 |
||
422 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
423 |
class CWETypeRQLAction(Action): |
0 | 424 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
425 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 426 |
title = 'bla' |
427 |
||
428 |
class RQLActionTC(ViewSelectorTC): |
|
429 |
||
430 |
def setUp(self): |
|
431 |
super(RQLActionTC, self).setUp() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
432 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
0 | 433 |
|
434 |
def tearDown(self): |
|
435 |
super(RQLActionTC, self).tearDown() |
|
436 |
del self.vreg._registries['actions']['testaction'] |
|
437 |
||
438 |
def test(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
439 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"') |
0 | 440 |
self.assertDictEqual(self.pactions(req, rset), |
441 |
{'useractions': USERACTIONS, |
|
442 |
'siteactions': SITEACTIONS, |
|
443 |
'mainactions': [('edit', actions.ModifyAction)], |
|
444 |
'moreactions': [('delete', actions.DeleteAction), |
|
445 |
('copy', actions.CopyAction), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
446 |
('testaction', CWETypeRQLAction), |
783 | 447 |
('managepermission', actions.ManagePermissionsAction)], |
0 | 448 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
449 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 450 |
self.assertDictEqual(self.pactions(req, rset), |
451 |
{'useractions': USERACTIONS, |
|
452 |
'siteactions': SITEACTIONS, |
|
453 |
'mainactions': [('edit', actions.ModifyAction)], |
|
454 |
'moreactions': [('delete', actions.DeleteAction), |
|
783 | 455 |
('copy', actions.CopyAction), |
456 |
('managepermission', actions.ManagePermissionsAction)], |
|
0 | 457 |
}) |
458 |
||
459 |
||
460 |
||
461 |
if __name__ == '__main__': |
|
462 |
unittest_main() |