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