author | sylvain.thenault@logilab.fr |
Wed, 13 May 2009 10:12:40 +0200 | |
branch | tls-sprint |
changeset 1774 | 4f4e0c6682e5 |
parent 1654 | 57b9fd2462b8 |
child 1797 | c2a80130b06d |
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 |
1654 | 15 |
from cubicweb.web.views import (primary, baseviews, tableview, editforms, |
16 |
calendar, management, embedding, actions, |
|
17 |
startup, cwuser, schema, xbel, vcard, owl, |
|
18 |
treeview, idownloadable, wdoc, debug, |
|
19 |
cwproperties, workflow, xmlrss, csvexport) |
|
0 | 20 |
|
21 |
USERACTIONS = [('myprefs', actions.UserPreferencesAction), |
|
22 |
('myinfos', actions.UserInfoAction), |
|
23 |
('logout', actions.LogoutAction)] |
|
24 |
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction), |
|
25 |
('manage', actions.ManageAction), |
|
1654 | 26 |
('schema', schema.ViewSchemaAction)] |
0 | 27 |
|
28 |
||
29 |
class ViewSelectorTC(EnvBasedTC): |
|
30 |
||
31 |
def setup_database(self): |
|
32 |
self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau") |
|
33 |
self.add_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
|
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 |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
62 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
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), |
|
1654 | 69 |
('epropertiesform', cwproperties.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), |
1654 | 75 |
('systemepropertiesform', cwproperties.SystemEPropertiesForm)]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
76 |
|
793 | 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 |
[]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
81 |
|
793 | 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), |
1654 | 85 |
[('csvexport', csvexport.CSVRsetView), |
86 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 92 |
('primary', primary.PrimaryView), |
93 |
('rsetxml', xmlrss.XMLRsetView), |
|
94 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 101 |
('xml', xmlrss.XMLView), |
0 | 102 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
103 |
|
793 | 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), |
1654 | 107 |
[('csvexport', csvexport.CSVRsetView), |
108 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 114 |
('primary', primary.PrimaryView), |
115 |
('rsetxml', xmlrss.XMLRsetView), |
|
116 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 123 |
('xml', xmlrss.XMLView), |
0 | 124 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
125 |
|
793 | 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), |
|
1654 | 129 |
[('csvexport', csvexport.CSVRsetView), |
130 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 136 |
('primary', primary.PrimaryView), |
137 |
('rsetxml', xmlrss.XMLRsetView), |
|
138 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 145 |
('xml', xmlrss.XMLView), |
0 | 146 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
147 |
|
793 | 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), |
|
1654 | 151 |
[('csvexport', csvexport.CSVRsetView), |
0 | 152 |
('editable-table', tableview.EditableTableView), |
1654 | 153 |
('rsetxml', xmlrss.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), |
1654 | 160 |
[('csvexport', csvexport.CSVRsetView), |
161 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 162 |
('editable-table', tableview.EditableTableView), |
444 | 163 |
('filetree', treeview.FileTreeView), |
1654 | 164 |
('foaf', cwuser.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), |
1654 | 168 |
('primary', cwuser.CWUserPrimaryView), |
169 |
('rsetxml', xmlrss.XMLRsetView), |
|
170 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 178 |
('xml', xmlrss.XMLView), |
0 | 179 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
180 |
|
0 | 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, |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
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 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
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 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
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 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
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}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
218 |
|
1654 | 219 |
def test_possible_actions_eetype_cwuser_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), |
|
1654 | 225 |
('workflow', workflow.ViewWorkflowAction),], |
226 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
|
227 |
('delete', actions.DeleteAction), |
|
793 | 228 |
('copy', actions.CopyAction), |
1654 | 229 |
], |
0 | 230 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
231 |
|
0 | 232 |
|
233 |
def test_select_creation_form(self): |
|
234 |
rset = None |
|
235 |
req = self.request() |
|
236 |
# creation form |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
237 |
req.form['etype'] = 'CWGroup' |
0 | 238 |
self.assertIsInstance(self.vreg.select_view('creation', req, rset), |
1654 | 239 |
editforms.CreationFormView) |
0 | 240 |
del req.form['etype'] |
241 |
# custom creation form |
|
1654 | 242 |
class CWUserCreationForm(editforms.CreationFormView): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
243 |
__select__ = specified_etype_implements('CWUser') |
1654 | 244 |
self.vreg._loadedmods[__name__] = {} |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
245 |
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
|
246 |
req.form['etype'] = 'CWUser' |
0 | 247 |
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
|
248 |
CWUserCreationForm) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
249 |
|
0 | 250 |
def test_select_view(self): |
251 |
# no entity |
|
252 |
rset = None |
|
253 |
req = self.request() |
|
254 |
self.assertIsInstance(self.vreg.select_view('index', req, rset), |
|
255 |
startup.IndexView) |
|
256 |
self.failUnlessRaises(NoSelectableObject, |
|
257 |
self.vreg.select_view, 'primary', req, rset) |
|
258 |
self.failUnlessRaises(NoSelectableObject, |
|
259 |
self.vreg.select_view, 'table', req, rset) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
260 |
|
0 | 261 |
# no entity |
262 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
263 |
self.failUnlessRaises(NoSelectableObject, |
|
264 |
self.vreg.select_view, 'index', req, rset) |
|
265 |
self.failUnlessRaises(NoSelectableObject, |
|
266 |
self.vreg.select_view, 'creation', req, rset) |
|
267 |
self.failUnlessRaises(NoSelectableObject, |
|
268 |
self.vreg.select_view, 'primary', req, rset) |
|
269 |
self.failUnlessRaises(NoSelectableObject, |
|
270 |
self.vreg.select_view, 'table', req, rset) |
|
271 |
# one entity |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
272 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 273 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1654 | 274 |
primary.PrimaryView) |
0 | 275 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
276 |
baseviews.ListView) |
|
277 |
self.assertIsInstance(self.vreg.select_view('edition', req, rset), |
|
1654 | 278 |
editforms.EditionFormView) |
0 | 279 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
280 |
tableview.TableView) |
|
281 |
self.failUnlessRaises(NoSelectableObject, |
|
282 |
self.vreg.select_view, 'creation', req, rset) |
|
283 |
self.failUnlessRaises(NoSelectableObject, |
|
284 |
self.vreg.select_view, 'index', req, rset) |
|
285 |
# 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
|
286 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 287 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1654 | 288 |
primary.PrimaryView) |
0 | 289 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
290 |
baseviews.ListView) |
|
291 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
292 |
tableview.TableView) |
|
293 |
self.failUnlessRaises(NoSelectableObject, |
|
294 |
self.vreg.select_view, 'creation', req, rset) |
|
295 |
# list of entities of different types |
|
296 |
rset, req = self.env.get_rset_and_req('Any X') |
|
297 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
1654 | 298 |
primary.PrimaryView) |
0 | 299 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
300 |
baseviews.ListView) |
|
301 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
302 |
tableview.TableView) |
|
303 |
self.failUnlessRaises(NoSelectableObject, |
|
304 |
self.vreg.select_view, 'creation', req, rset) |
|
305 |
self.failUnlessRaises(NoSelectableObject, |
|
306 |
self.vreg.select_view, 'index', req, rset) |
|
307 |
# whatever |
|
308 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
309 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
310 |
tableview.TableView) |
|
311 |
self.failUnlessRaises(NoSelectableObject, |
|
312 |
self.vreg.select_view, 'index', req, rset) |
|
313 |
self.failUnlessRaises(NoSelectableObject, |
|
314 |
self.vreg.select_view, 'creation', req, rset) |
|
315 |
self.failUnlessRaises(NoSelectableObject, |
|
316 |
self.vreg.select_view, 'primary', req, rset) |
|
317 |
self.failUnlessRaises(NoSelectableObject, |
|
318 |
self.vreg.select_view, 'list', req, rset) |
|
319 |
self.failUnlessRaises(NoSelectableObject, |
|
320 |
self.vreg.select_view, 'edition', req, rset) |
|
321 |
# mixed query |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
322 |
rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup') |
0 | 323 |
self.failUnlessRaises(NoSelectableObject, |
324 |
self.vreg.select_view, 'edition', req, rset) |
|
325 |
self.failUnlessRaises(NoSelectableObject, |
|
326 |
self.vreg.select_view, 'creation', req, rset) |
|
327 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
328 |
tableview.TableView) |
|
1654 | 329 |
# cwuser primary view priority |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
330 |
rset, req = self.env.get_rset_and_req('CWUser X WHERE X login "admin"') |
0 | 331 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1654 | 332 |
cwuser.CWUserPrimaryView) |
0 | 333 |
self.assertIsInstance(self.vreg.select_view('text', req, rset), |
334 |
baseviews.TextView) |
|
335 |
||
336 |
def test_interface_selector(self): |
|
337 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
338 |
# image primary view priority |
|
339 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
340 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
341 |
idownloadable.IDownloadablePrimaryView) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
342 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
343 |
|
0 | 344 |
def test_score_entity_selector(self): |
345 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
346 |
# image primary view priority |
|
347 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
348 |
self.assertIsInstance(self.vreg.select_view('image', req, rset), |
|
349 |
idownloadable.ImageView) |
|
350 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
351 |
# image primary view priority |
|
352 |
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"') |
|
353 |
self.assertRaises(NoSelectableObject, self.vreg.select_view, 'image', req, rset) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
354 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
355 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
356 |
|
0 | 357 |
def _test_view(self, vid, rql, args): |
358 |
if rql is None: |
|
359 |
rset = None |
|
360 |
req = self.request() |
|
361 |
else: |
|
362 |
rset, req = self.env.get_rset_and_req(rql) |
|
363 |
try: |
|
364 |
self.vreg.render('views', vid, req, rset=rset, **args) |
|
365 |
except: |
|
366 |
print vid, rset, args |
|
367 |
raise |
|
368 |
||
369 |
def test_form(self): |
|
370 |
for vid, rql, args in ( |
|
371 |
#('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
|
372 |
('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
|
373 |
('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
|
374 |
('muledit', 'CWGroup X', {}), |
0 | 375 |
#('muledit', 'Any X', {}), |
376 |
): |
|
377 |
self._test_view(vid, rql, args) |
|
378 |
||
379 |
||
380 |
def test_properties(self): |
|
381 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
382 |
if k.startswith('boxes.edit_box')), |
|
383 |
['boxes.edit_box.context', |
|
384 |
'boxes.edit_box.order', |
|
385 |
'boxes.edit_box.visible']) |
|
386 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
387 |
if not k.startswith('system.version')], |
|
388 |
[]) |
|
389 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
390 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
391 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
392 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
393 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
394 |
||
395 |
||
396 |
||
397 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
398 |
class CWETypeRQLAction(Action): |
0 | 399 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
400 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 401 |
title = 'bla' |
402 |
||
403 |
class RQLActionTC(ViewSelectorTC): |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
404 |
|
0 | 405 |
def setUp(self): |
406 |
super(RQLActionTC, self).setUp() |
|
1654 | 407 |
self.vreg._loadedmods[__name__] = {} |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
408 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
409 |
|
0 | 410 |
def tearDown(self): |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
411 |
super(RQLActionTC, self).tearDown() |
0 | 412 |
del self.vreg._registries['actions']['testaction'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
413 |
|
0 | 414 |
def test(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
415 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"') |
0 | 416 |
self.assertDictEqual(self.pactions(req, rset), |
417 |
{'useractions': USERACTIONS, |
|
418 |
'siteactions': SITEACTIONS, |
|
419 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 420 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
421 |
('delete', actions.DeleteAction), |
|
0 | 422 |
('copy', actions.CopyAction), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
423 |
('testaction', CWETypeRQLAction), |
1654 | 424 |
], |
0 | 425 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
426 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 427 |
self.assertDictEqual(self.pactions(req, rset), |
428 |
{'useractions': USERACTIONS, |
|
429 |
'siteactions': SITEACTIONS, |
|
430 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 431 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
432 |
('delete', actions.DeleteAction), |
|
783 | 433 |
('copy', actions.CopyAction), |
1654 | 434 |
], |
0 | 435 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
436 |
|
0 | 437 |
|
438 |
||
439 |
if __name__ == '__main__': |
|
440 |
unittest_main() |