author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Jun 2009 15:06:55 +0200 | |
changeset 2057 | 0a0cbccafcb5 |
parent 1977 | 606923dff11b |
child 2058 | 7ef12c03447c |
child 2401 | 890f6b990dd7 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
"""XXX rename, split, reorganize this |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1914
diff
changeset
|
3 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 4 |
""" |
783 | 5 |
from logilab.common.testlib import unittest_main |
793 | 6 |
|
0 | 7 |
from cubicweb.devtools.apptest import EnvBasedTC |
8 |
from cubicweb import CW_SOFTWARE_ROOT as BASE, Binary |
|
793 | 9 |
from cubicweb.selectors import (match_user_groups, implements, |
10 |
specified_etype_implements, rql_condition, |
|
11 |
traced_selection) |
|
12 |
from cubicweb.web import NoSelectableObject |
|
0 | 13 |
from cubicweb.web.action import Action |
1654 | 14 |
from cubicweb.web.views import (primary, baseviews, tableview, editforms, |
15 |
calendar, management, embedding, actions, |
|
16 |
startup, cwuser, schema, xbel, vcard, owl, |
|
17 |
treeview, idownloadable, wdoc, debug, |
|
18 |
cwproperties, workflow, xmlrss, csvexport) |
|
0 | 19 |
|
20 |
USERACTIONS = [('myprefs', actions.UserPreferencesAction), |
|
21 |
('myinfos', actions.UserInfoAction), |
|
22 |
('logout', actions.LogoutAction)] |
|
23 |
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction), |
|
24 |
('manage', actions.ManageAction), |
|
1654 | 25 |
('schema', schema.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), |
|
68 |
('index', startup.IndexView), |
|
69 |
('info', management.ProcessInformationView), |
|
70 |
('manage', startup.ManageView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
71 |
('owl', owl.OWLView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
72 |
('propertiesform', cwproperties.CWPropertiesForm), |
0 | 73 |
('schema', startup.SchemaView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
74 |
('systempropertiesform', cwproperties.SystemCWPropertiesForm)]) |
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), |
1654 | 84 |
[('csvexport', csvexport.CSVRsetView), |
85 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 91 |
('primary', primary.PrimaryView), |
92 |
('rsetxml', xmlrss.XMLRsetView), |
|
93 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 100 |
('xml', xmlrss.XMLView), |
0 | 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), |
1654 | 106 |
[('csvexport', csvexport.CSVRsetView), |
107 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 113 |
('primary', primary.PrimaryView), |
114 |
('rsetxml', xmlrss.XMLRsetView), |
|
115 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 122 |
('xml', xmlrss.XMLView), |
0 | 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), |
|
1654 | 128 |
[('csvexport', csvexport.CSVRsetView), |
129 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 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), |
1654 | 135 |
('primary', primary.PrimaryView), |
136 |
('rsetxml', xmlrss.XMLRsetView), |
|
137 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 144 |
('xml', xmlrss.XMLView), |
0 | 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), |
|
1654 | 150 |
[('csvexport', csvexport.CSVRsetView), |
0 | 151 |
('editable-table', tableview.EditableTableView), |
1654 | 152 |
('rsetxml', xmlrss.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), |
1654 | 159 |
[('csvexport', csvexport.CSVRsetView), |
160 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 161 |
('editable-table', tableview.EditableTableView), |
444 | 162 |
('filetree', treeview.FileTreeView), |
1654 | 163 |
('foaf', cwuser.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), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
167 |
('primary', primary.PrimaryView), |
1654 | 168 |
('rsetxml', xmlrss.XMLRsetView), |
169 |
('rss', xmlrss.RSSView), |
|
0 | 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), |
1654 | 177 |
('xml', xmlrss.XMLView), |
0 | 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 |
|
1654 | 218 |
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
|
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), |
|
1654 | 224 |
('workflow', workflow.ViewWorkflowAction),], |
225 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
|
226 |
('delete', actions.DeleteAction), |
|
793 | 227 |
('copy', actions.CopyAction), |
1654 | 228 |
], |
0 | 229 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
230 |
|
0 | 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), |
1654 | 238 |
editforms.CreationFormView) |
0 | 239 |
del req.form['etype'] |
240 |
# custom creation form |
|
1654 | 241 |
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
|
242 |
__select__ = specified_etype_implements('CWUser') |
1654 | 243 |
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
|
244 |
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
|
245 |
req.form['etype'] = 'CWUser' |
0 | 246 |
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
|
247 |
CWUserCreationForm) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
248 |
|
0 | 249 |
def test_select_view(self): |
250 |
# no entity |
|
251 |
rset = None |
|
252 |
req = self.request() |
|
253 |
self.assertIsInstance(self.vreg.select_view('index', req, rset), |
|
254 |
startup.IndexView) |
|
255 |
self.failUnlessRaises(NoSelectableObject, |
|
256 |
self.vreg.select_view, 'primary', req, rset) |
|
257 |
self.failUnlessRaises(NoSelectableObject, |
|
258 |
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
|
259 |
|
0 | 260 |
# no entity |
261 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
262 |
self.failUnlessRaises(NoSelectableObject, |
|
263 |
self.vreg.select_view, 'index', req, rset) |
|
264 |
self.failUnlessRaises(NoSelectableObject, |
|
265 |
self.vreg.select_view, 'creation', req, rset) |
|
266 |
self.failUnlessRaises(NoSelectableObject, |
|
267 |
self.vreg.select_view, 'primary', req, rset) |
|
268 |
self.failUnlessRaises(NoSelectableObject, |
|
269 |
self.vreg.select_view, 'table', req, rset) |
|
270 |
# one entity |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
271 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 272 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1654 | 273 |
primary.PrimaryView) |
0 | 274 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
275 |
baseviews.ListView) |
|
276 |
self.assertIsInstance(self.vreg.select_view('edition', req, rset), |
|
1654 | 277 |
editforms.EditionFormView) |
0 | 278 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
279 |
tableview.TableView) |
|
280 |
self.failUnlessRaises(NoSelectableObject, |
|
281 |
self.vreg.select_view, 'creation', req, rset) |
|
282 |
self.failUnlessRaises(NoSelectableObject, |
|
283 |
self.vreg.select_view, 'index', req, rset) |
|
284 |
# 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
|
285 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 286 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
1654 | 287 |
primary.PrimaryView) |
0 | 288 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
289 |
baseviews.ListView) |
|
290 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
291 |
tableview.TableView) |
|
292 |
self.failUnlessRaises(NoSelectableObject, |
|
293 |
self.vreg.select_view, 'creation', req, rset) |
|
294 |
# list of entities of different types |
|
295 |
rset, req = self.env.get_rset_and_req('Any X') |
|
296 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
1654 | 297 |
primary.PrimaryView) |
0 | 298 |
self.assertIsInstance(self.vreg.select_view('list', req, rset), |
299 |
baseviews.ListView) |
|
300 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
301 |
tableview.TableView) |
|
302 |
self.failUnlessRaises(NoSelectableObject, |
|
303 |
self.vreg.select_view, 'creation', req, rset) |
|
304 |
self.failUnlessRaises(NoSelectableObject, |
|
305 |
self.vreg.select_view, 'index', req, rset) |
|
306 |
# whatever |
|
307 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
308 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
309 |
tableview.TableView) |
|
310 |
self.failUnlessRaises(NoSelectableObject, |
|
311 |
self.vreg.select_view, 'index', req, rset) |
|
312 |
self.failUnlessRaises(NoSelectableObject, |
|
313 |
self.vreg.select_view, 'creation', req, rset) |
|
314 |
self.failUnlessRaises(NoSelectableObject, |
|
315 |
self.vreg.select_view, 'primary', req, rset) |
|
316 |
self.failUnlessRaises(NoSelectableObject, |
|
317 |
self.vreg.select_view, 'list', req, rset) |
|
318 |
self.failUnlessRaises(NoSelectableObject, |
|
319 |
self.vreg.select_view, 'edition', req, rset) |
|
320 |
# mixed query |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
321 |
rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup') |
0 | 322 |
self.failUnlessRaises(NoSelectableObject, |
323 |
self.vreg.select_view, 'edition', req, rset) |
|
324 |
self.failUnlessRaises(NoSelectableObject, |
|
325 |
self.vreg.select_view, 'creation', req, rset) |
|
326 |
self.assertIsInstance(self.vreg.select_view('table', req, rset), |
|
327 |
tableview.TableView) |
|
328 |
||
329 |
def test_interface_selector(self): |
|
330 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
331 |
# image primary view priority |
|
332 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
333 |
self.assertIsInstance(self.vreg.select_view('primary', req, rset), |
|
334 |
idownloadable.IDownloadablePrimaryView) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
335 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
336 |
|
0 | 337 |
def test_score_entity_selector(self): |
338 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
339 |
# image primary view priority |
|
340 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
341 |
self.assertIsInstance(self.vreg.select_view('image', req, rset), |
|
342 |
idownloadable.ImageView) |
|
343 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
344 |
# image primary view priority |
|
345 |
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"') |
|
346 |
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
|
347 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
348 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
349 |
|
0 | 350 |
def _test_view(self, vid, rql, args): |
351 |
if rql is None: |
|
352 |
rset = None |
|
353 |
req = self.request() |
|
354 |
else: |
|
355 |
rset, req = self.env.get_rset_and_req(rql) |
|
356 |
try: |
|
357 |
self.vreg.render('views', vid, req, rset=rset, **args) |
|
358 |
except: |
|
359 |
print vid, rset, args |
|
360 |
raise |
|
361 |
||
362 |
def test_form(self): |
|
363 |
for vid, rql, args in ( |
|
364 |
#('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
|
365 |
('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
|
366 |
('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
|
367 |
('muledit', 'CWGroup X', {}), |
0 | 368 |
#('muledit', 'Any X', {}), |
369 |
): |
|
370 |
self._test_view(vid, rql, args) |
|
371 |
||
372 |
||
373 |
def test_properties(self): |
|
374 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
375 |
if k.startswith('boxes.edit_box')), |
|
376 |
['boxes.edit_box.context', |
|
377 |
'boxes.edit_box.order', |
|
378 |
'boxes.edit_box.visible']) |
|
379 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
380 |
if not k.startswith('system.version')], |
|
381 |
[]) |
|
382 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
383 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
384 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
385 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
386 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
387 |
||
388 |
||
389 |
||
390 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
391 |
class CWETypeRQLAction(Action): |
0 | 392 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
393 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 394 |
title = 'bla' |
395 |
||
396 |
class RQLActionTC(ViewSelectorTC): |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
397 |
|
0 | 398 |
def setUp(self): |
399 |
super(RQLActionTC, self).setUp() |
|
1654 | 400 |
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
|
401 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
402 |
|
0 | 403 |
def tearDown(self): |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
404 |
super(RQLActionTC, self).tearDown() |
0 | 405 |
del self.vreg._registries['actions']['testaction'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
406 |
|
0 | 407 |
def test(self): |
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('CWEType X WHERE X name "CWEType"') |
0 | 409 |
self.assertDictEqual(self.pactions(req, rset), |
410 |
{'useractions': USERACTIONS, |
|
411 |
'siteactions': SITEACTIONS, |
|
412 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 413 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
414 |
('delete', actions.DeleteAction), |
|
0 | 415 |
('copy', actions.CopyAction), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
416 |
('testaction', CWETypeRQLAction), |
1654 | 417 |
], |
0 | 418 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
419 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 420 |
self.assertDictEqual(self.pactions(req, rset), |
421 |
{'useractions': USERACTIONS, |
|
422 |
'siteactions': SITEACTIONS, |
|
423 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 424 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
425 |
('delete', actions.DeleteAction), |
|
783 | 426 |
('copy', actions.CopyAction), |
1654 | 427 |
], |
0 | 428 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
429 |
|
0 | 430 |
|
431 |
||
432 |
if __name__ == '__main__': |
|
433 |
unittest_main() |