author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 26 May 2009 18:22:24 +0200 | |
branch | stable |
changeset 1943 | fb557b616c80 |
parent 1914 | 0ce7dbfffefd |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
"""XXX rename, split, reorganize this |
|
3 |
""" |
|
783 | 4 |
from logilab.common.testlib import unittest_main |
793 | 5 |
|
0 | 6 |
from cubicweb.devtools.apptest import EnvBasedTC |
7 |
from cubicweb import CW_SOFTWARE_ROOT as BASE, Binary |
|
793 | 8 |
from cubicweb.selectors import (match_user_groups, implements, |
9 |
specified_etype_implements, rql_condition, |
|
10 |
traced_selection) |
|
11 |
from cubicweb.web import NoSelectableObject |
|
0 | 12 |
from cubicweb.web.action import Action |
1654 | 13 |
from cubicweb.web.views import (primary, baseviews, tableview, editforms, |
14 |
calendar, management, embedding, actions, |
|
15 |
startup, cwuser, schema, xbel, vcard, owl, |
|
16 |
treeview, idownloadable, wdoc, debug, |
|
17 |
cwproperties, workflow, xmlrss, csvexport) |
|
0 | 18 |
|
19 |
USERACTIONS = [('myprefs', actions.UserPreferencesAction), |
|
20 |
('myinfos', actions.UserInfoAction), |
|
21 |
('logout', actions.LogoutAction)] |
|
22 |
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction), |
|
23 |
('manage', actions.ManageAction), |
|
1654 | 24 |
('schema', schema.ViewSchemaAction)] |
0 | 25 |
|
26 |
||
27 |
class ViewSelectorTC(EnvBasedTC): |
|
28 |
||
29 |
def setup_database(self): |
|
30 |
self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau") |
|
31 |
self.add_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
|
32 |
self.add_entity('EmailAddress', address=u"devel@logilab.fr", alias=u'devel') |
|
33 |
self.add_entity('Tag', name=u'x') |
|
34 |
||
35 |
def pactions(self, req, rset): |
|
36 |
resdict = self.vreg.possible_actions(req, rset) |
|
37 |
for cat, actions in resdict.items(): |
|
38 |
resdict[cat] = [(a.id, a.__class__) for a in actions] |
|
39 |
return resdict |
|
40 |
||
41 |
||
42 |
class VRegistryTC(ViewSelectorTC): |
|
43 |
"""test the view selector""" |
|
44 |
||
45 |
def _test_registered(self, registry, content): |
|
46 |
try: |
|
47 |
expected = getattr(self, 'all_%s' % registry) |
|
48 |
except AttributeError: |
|
49 |
return |
|
50 |
if registry == 'hooks': |
|
51 |
self.assertEquals(len(content), expected, content) |
|
52 |
return |
|
53 |
try: |
|
54 |
self.assertSetEqual(content.keys(), expected) |
|
55 |
except: |
|
56 |
print registry, sorted(expected), sorted(content.keys()) |
|
57 |
print 'no more', [v for v in expected if not v in content.keys()] |
|
58 |
print 'missing', [v for v in content.keys() if not v in expected] |
|
59 |
raise |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
60 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
61 |
|
793 | 62 |
def test_possible_views_none_rset(self): |
0 | 63 |
req = self.request() |
64 |
self.assertListEqual(self.pviews(req, None), |
|
65 |
[('changelog', wdoc.ChangeLogView), |
|
66 |
('debug', debug.DebugView), |
|
67 |
('index', startup.IndexView), |
|
68 |
('info', management.ProcessInformationView), |
|
69 |
('manage', startup.ManageView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
70 |
('owl', owl.OWLView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
71 |
('propertiesform', cwproperties.CWPropertiesForm), |
0 | 72 |
('schema', startup.SchemaView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
73 |
('systempropertiesform', cwproperties.SystemCWPropertiesForm)]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
74 |
|
793 | 75 |
def test_possible_views_noresult(self): |
0 | 76 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
77 |
self.assertListEqual(self.pviews(req, rset), |
|
783 | 78 |
[]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
79 |
|
793 | 80 |
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
|
81 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 82 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 83 |
[('csvexport', csvexport.CSVRsetView), |
84 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 85 |
('editable-table', tableview.EditableTableView), |
444 | 86 |
('filetree', treeview.FileTreeView), |
0 | 87 |
('list', baseviews.ListView), |
88 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
89 |
('owlabox', owl.OWLABOXView), |
1654 | 90 |
('primary', primary.PrimaryView), |
91 |
('rsetxml', xmlrss.XMLRsetView), |
|
92 |
('rss', xmlrss.RSSView), |
|
0 | 93 |
('secondary', baseviews.SecondaryView), |
94 |
('security', management.SecurityManagementView), |
|
95 |
('table', tableview.TableView), |
|
96 |
('text', baseviews.TextView), |
|
444 | 97 |
('treeview', treeview.TreeView), |
0 | 98 |
('xbel', xbel.XbelView), |
1654 | 99 |
('xml', xmlrss.XMLView), |
0 | 100 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
101 |
|
793 | 102 |
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
|
103 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 104 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 105 |
[('csvexport', csvexport.CSVRsetView), |
106 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 107 |
('editable-table', tableview.EditableTableView), |
444 | 108 |
('filetree', treeview.FileTreeView), |
0 | 109 |
('list', baseviews.ListView), |
110 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
111 |
('owlabox', owl.OWLABOXView), |
1654 | 112 |
('primary', primary.PrimaryView), |
113 |
('rsetxml', xmlrss.XMLRsetView), |
|
114 |
('rss', xmlrss.RSSView), |
|
0 | 115 |
('secondary', baseviews.SecondaryView), |
116 |
('security', management.SecurityManagementView), |
|
117 |
('table', tableview.TableView), |
|
118 |
('text', baseviews.TextView), |
|
444 | 119 |
('treeview', treeview.TreeView), |
0 | 120 |
('xbel', xbel.XbelView), |
1654 | 121 |
('xml', xmlrss.XMLView), |
0 | 122 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
123 |
|
793 | 124 |
def test_possible_views_multiple_different_types(self): |
0 | 125 |
rset, req = self.env.get_rset_and_req('Any X') |
126 |
self.assertListEqual(self.pviews(req, rset), |
|
1654 | 127 |
[('csvexport', csvexport.CSVRsetView), |
128 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 129 |
('editable-table', tableview.EditableTableView), |
444 | 130 |
('filetree', treeview.FileTreeView), |
0 | 131 |
('list', baseviews.ListView), |
132 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
133 |
('owlabox', owl.OWLABOXView), |
1654 | 134 |
('primary', primary.PrimaryView), |
135 |
('rsetxml', xmlrss.XMLRsetView), |
|
136 |
('rss', xmlrss.RSSView), |
|
0 | 137 |
('secondary', baseviews.SecondaryView), |
138 |
('security', management.SecurityManagementView), |
|
139 |
('table', tableview.TableView), |
|
140 |
('text', baseviews.TextView), |
|
444 | 141 |
('treeview', treeview.TreeView), |
0 | 142 |
('xbel', xbel.XbelView), |
1654 | 143 |
('xml', xmlrss.XMLView), |
0 | 144 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
145 |
|
793 | 146 |
def test_possible_views_any_rset(self): |
0 | 147 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
148 |
self.assertListEqual(self.pviews(req, rset), |
|
1654 | 149 |
[('csvexport', csvexport.CSVRsetView), |
0 | 150 |
('editable-table', tableview.EditableTableView), |
1654 | 151 |
('rsetxml', xmlrss.XMLRsetView), |
0 | 152 |
('table', tableview.TableView), |
153 |
]) |
|
793 | 154 |
|
155 |
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
|
156 |
rset, req = self.env.get_rset_and_req('CWUser X') |
0 | 157 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 158 |
[('csvexport', csvexport.CSVRsetView), |
159 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 160 |
('editable-table', tableview.EditableTableView), |
444 | 161 |
('filetree', treeview.FileTreeView), |
1654 | 162 |
('foaf', cwuser.FoafView), |
0 | 163 |
('list', baseviews.ListView), |
164 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
165 |
('owlabox', owl.OWLABOXView), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
166 |
('primary', primary.PrimaryView), |
1654 | 167 |
('rsetxml', xmlrss.XMLRsetView), |
168 |
('rss', xmlrss.RSSView), |
|
0 | 169 |
('secondary', baseviews.SecondaryView), |
170 |
('security', management.SecurityManagementView), |
|
171 |
('table', tableview.TableView), |
|
172 |
('text', baseviews.TextView), |
|
444 | 173 |
('treeview', treeview.TreeView), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
174 |
('vcard', vcard.VCardCWUserView), |
0 | 175 |
('xbel', xbel.XbelView), |
1654 | 176 |
('xml', xmlrss.XMLView), |
0 | 177 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
178 |
|
0 | 179 |
def test_possible_actions_none_rset(self): |
180 |
req = self.request() |
|
181 |
self.assertDictEqual(self.pactions(req, None), |
|
182 |
{'useractions': USERACTIONS, |
|
183 |
'siteactions': SITEACTIONS, |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
184 |
|
0 | 185 |
}) |
186 |
def test_possible_actions_no_entity(self): |
|
187 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
188 |
self.assertDictEqual(self.pactions(req, rset), |
|
189 |
{'useractions': USERACTIONS, |
|
190 |
'siteactions': SITEACTIONS, |
|
191 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
192 |
|
0 | 193 |
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
|
194 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 195 |
self.assertDictEqual(self.pactions(req, rset), |
196 |
{'useractions': USERACTIONS, |
|
197 |
'siteactions': SITEACTIONS, |
|
198 |
'mainactions': [('muledit', actions.MultipleEditAction)], |
|
199 |
'moreactions': [('delete', actions.DeleteAction), |
|
200 |
('addentity', actions.AddNewAction)], |
|
201 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
202 |
|
0 | 203 |
def test_possible_actions_different_types_entities(self): |
204 |
rset, req = self.env.get_rset_and_req('Any X') |
|
205 |
self.assertDictEqual(self.pactions(req, rset), |
|
206 |
{'useractions': USERACTIONS, |
|
207 |
'siteactions': SITEACTIONS, |
|
208 |
'moreactions': [('delete', actions.DeleteAction)], |
|
209 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
210 |
|
0 | 211 |
def test_possible_actions_final_entities(self): |
212 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
213 |
self.assertDictEqual(self.pactions(req, rset), |
|
214 |
{'useractions': USERACTIONS, |
|
215 |
'siteactions': SITEACTIONS}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
216 |
|
1654 | 217 |
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
|
218 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWUser"') |
0 | 219 |
self.assertDictEqual(self.pactions(req, rset), |
220 |
{'useractions': USERACTIONS, |
|
221 |
'siteactions': SITEACTIONS, |
|
222 |
'mainactions': [('edit', actions.ModifyAction), |
|
1654 | 223 |
('workflow', workflow.ViewWorkflowAction),], |
224 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
|
225 |
('delete', actions.DeleteAction), |
|
793 | 226 |
('copy', actions.CopyAction), |
1654 | 227 |
], |
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), |
1654 | 237 |
editforms.CreationFormView) |
0 | 238 |
del req.form['etype'] |
239 |
# custom creation form |
|
1654 | 240 |
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
|
241 |
__select__ = specified_etype_implements('CWUser') |
1654 | 242 |
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
|
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) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
247 |
|
0 | 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) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
258 |
|
0 | 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), |
1654 | 272 |
primary.PrimaryView) |
0 | 273 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
274 |
baseviews.ListView) |
|
275 |
self.assertIsInstance(self.vreg.select_view('edition', req, rset), |
|
1654 | 276 |
editforms.EditionFormView) |
0 | 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), |
1654 | 286 |
primary.PrimaryView) |
0 | 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), |
|
1654 | 296 |
primary.PrimaryView) |
0 | 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 |
||
328 |
def test_interface_selector(self): |
|
329 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
330 |
# image primary view priority |
|
331 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
332 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
333 |
idownloadable.IDownloadablePrimaryView) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
334 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
335 |
|
0 | 336 |
def test_score_entity_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('image', req, rset), |
|
341 |
idownloadable.ImageView) |
|
342 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
343 |
# image primary view priority |
|
344 |
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"') |
|
345 |
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
|
346 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
347 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
348 |
|
0 | 349 |
def _test_view(self, vid, rql, args): |
350 |
if rql is None: |
|
351 |
rset = None |
|
352 |
req = self.request() |
|
353 |
else: |
|
354 |
rset, req = self.env.get_rset_and_req(rql) |
|
355 |
try: |
|
356 |
self.vreg.render('views', vid, req, rset=rset, **args) |
|
357 |
except: |
|
358 |
print vid, rset, args |
|
359 |
raise |
|
360 |
||
361 |
def test_form(self): |
|
362 |
for vid, rql, args in ( |
|
363 |
#('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
|
364 |
('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
|
365 |
('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
|
366 |
('muledit', 'CWGroup X', {}), |
0 | 367 |
#('muledit', 'Any X', {}), |
368 |
): |
|
369 |
self._test_view(vid, rql, args) |
|
370 |
||
371 |
||
372 |
def test_properties(self): |
|
373 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
374 |
if k.startswith('boxes.edit_box')), |
|
375 |
['boxes.edit_box.context', |
|
376 |
'boxes.edit_box.order', |
|
377 |
'boxes.edit_box.visible']) |
|
378 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
379 |
if not k.startswith('system.version')], |
|
380 |
[]) |
|
381 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
382 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
383 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
384 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
385 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
386 |
||
387 |
||
388 |
||
389 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
390 |
class CWETypeRQLAction(Action): |
0 | 391 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
392 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 393 |
title = 'bla' |
394 |
||
395 |
class RQLActionTC(ViewSelectorTC): |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
396 |
|
0 | 397 |
def setUp(self): |
398 |
super(RQLActionTC, self).setUp() |
|
1654 | 399 |
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
|
400 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
401 |
|
0 | 402 |
def tearDown(self): |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
403 |
super(RQLActionTC, self).tearDown() |
0 | 404 |
del self.vreg._registries['actions']['testaction'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
405 |
|
0 | 406 |
def test(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
407 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"') |
0 | 408 |
self.assertDictEqual(self.pactions(req, rset), |
409 |
{'useractions': USERACTIONS, |
|
410 |
'siteactions': SITEACTIONS, |
|
411 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 412 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
413 |
('delete', actions.DeleteAction), |
|
0 | 414 |
('copy', actions.CopyAction), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
415 |
('testaction', CWETypeRQLAction), |
1654 | 416 |
], |
0 | 417 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
418 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 419 |
self.assertDictEqual(self.pactions(req, rset), |
420 |
{'useractions': USERACTIONS, |
|
421 |
'siteactions': SITEACTIONS, |
|
422 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 423 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
424 |
('delete', actions.DeleteAction), |
|
783 | 425 |
('copy', actions.CopyAction), |
1654 | 426 |
], |
0 | 427 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
428 |
|
0 | 429 |
|
430 |
||
431 |
if __name__ == '__main__': |
|
432 |
unittest_main() |