author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 23 Jul 2009 14:12:18 +0200 | |
changeset 2439 | 77d8dd77acb3 |
parent 2058 | 7ef12c03447c |
child 2440 | 8e6b83e3b6b5 |
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), |
|
2439
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2058
diff
changeset
|
25 |
('schema', schema.ViewSchemaAction), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2058
diff
changeset
|
26 |
('siteinfo', actions.SiteInfoAction), |
77d8dd77acb3
[cleanup] fix tests
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2058
diff
changeset
|
27 |
] |
0 | 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), |
|
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), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
73 |
('propertiesform', cwproperties.CWPropertiesForm), |
0 | 74 |
('schema', startup.SchemaView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
75 |
('systempropertiesform', cwproperties.SystemCWPropertiesForm)]) |
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), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
168 |
('primary', primary.PrimaryView), |
1654 | 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' |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
238 |
self.assertIsInstance(self.vreg.select('views', 'creation', req, rset=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' |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
247 |
self.assertIsInstance(self.vreg.select('views', 'creation', req, rset=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() |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
254 |
self.assertIsInstance(self.vreg.select('views', 'index', req, rset=rset), |
0 | 255 |
startup.IndexView) |
256 |
self.failUnlessRaises(NoSelectableObject, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
257 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 258 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
259 |
self.vreg.select, 'views', 'table', req, rset=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, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
264 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 265 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
266 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 267 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
268 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 269 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
270 |
self.vreg.select, 'views', 'table', req, rset=rset) |
0 | 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"') |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
273 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 274 |
primary.PrimaryView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
275 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 276 |
baseviews.ListView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
277 |
self.assertIsInstance(self.vreg.select('views', 'edition', req, rset=rset), |
1654 | 278 |
editforms.EditionFormView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
279 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 280 |
tableview.TableView) |
281 |
self.failUnlessRaises(NoSelectableObject, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
282 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 283 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
284 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 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') |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
287 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 288 |
primary.PrimaryView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
289 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 290 |
baseviews.ListView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
291 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 292 |
tableview.TableView) |
293 |
self.failUnlessRaises(NoSelectableObject, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
294 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 295 |
# list of entities of different types |
296 |
rset, req = self.env.get_rset_and_req('Any X') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
297 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 298 |
primary.PrimaryView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
299 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 300 |
baseviews.ListView) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
301 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 302 |
tableview.TableView) |
303 |
self.failUnlessRaises(NoSelectableObject, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
304 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 305 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
306 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 307 |
# whatever |
308 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
309 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 310 |
tableview.TableView) |
311 |
self.failUnlessRaises(NoSelectableObject, |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
312 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 313 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
314 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 315 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
316 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 317 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
318 |
self.vreg.select, 'views', 'list', req, rset=rset) |
0 | 319 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
320 |
self.vreg.select, 'views', 'edition', req, rset=rset) |
0 | 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, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
324 |
self.vreg.select, 'views', 'edition', req, rset=rset) |
0 | 325 |
self.failUnlessRaises(NoSelectableObject, |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
326 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
327 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 328 |
tableview.TableView) |
329 |
||
330 |
def test_interface_selector(self): |
|
331 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
332 |
# image primary view priority |
|
333 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
334 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
0 | 335 |
idownloadable.IDownloadablePrimaryView) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
336 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
337 |
|
0 | 338 |
def test_score_entity_selector(self): |
339 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
340 |
# image primary view priority |
|
341 |
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
342 |
self.assertIsInstance(self.vreg.select('views', 'image', req, rset=rset), |
0 | 343 |
idownloadable.ImageView) |
344 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
345 |
# image primary view priority |
|
346 |
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"') |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
347 |
self.assertRaises(NoSelectableObject, self.vreg.select, 'views', 'image', req, rset=rset) |
1570
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 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
350 |
|
0 | 351 |
def _test_view(self, vid, rql, args): |
352 |
if rql is None: |
|
353 |
rset = None |
|
354 |
req = self.request() |
|
355 |
else: |
|
356 |
rset, req = self.env.get_rset_and_req(rql) |
|
357 |
try: |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
358 |
self.vreg.render(vid, req, rset=rset, **args) |
0 | 359 |
except: |
360 |
print vid, rset, args |
|
361 |
raise |
|
362 |
||
363 |
def test_form(self): |
|
364 |
for vid, rql, args in ( |
|
365 |
#('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
|
366 |
('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
|
367 |
('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
|
368 |
('muledit', 'CWGroup X', {}), |
0 | 369 |
#('muledit', 'Any X', {}), |
370 |
): |
|
371 |
self._test_view(vid, rql, args) |
|
372 |
||
373 |
||
374 |
def test_properties(self): |
|
375 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
376 |
if k.startswith('boxes.edit_box')), |
|
377 |
['boxes.edit_box.context', |
|
378 |
'boxes.edit_box.order', |
|
379 |
'boxes.edit_box.visible']) |
|
380 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
381 |
if not k.startswith('system.version')], |
|
382 |
[]) |
|
383 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
384 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
385 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
386 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
387 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
388 |
||
389 |
||
390 |
||
391 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
392 |
class CWETypeRQLAction(Action): |
0 | 393 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
394 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 395 |
title = 'bla' |
396 |
||
397 |
class RQLActionTC(ViewSelectorTC): |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
398 |
|
0 | 399 |
def setUp(self): |
400 |
super(RQLActionTC, self).setUp() |
|
1654 | 401 |
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
|
402 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
403 |
|
0 | 404 |
def tearDown(self): |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
405 |
super(RQLActionTC, self).tearDown() |
0 | 406 |
del self.vreg._registries['actions']['testaction'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
407 |
|
0 | 408 |
def test(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
409 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"') |
0 | 410 |
self.assertDictEqual(self.pactions(req, rset), |
411 |
{'useractions': USERACTIONS, |
|
412 |
'siteactions': SITEACTIONS, |
|
413 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 414 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
415 |
('delete', actions.DeleteAction), |
|
0 | 416 |
('copy', actions.CopyAction), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
417 |
('testaction', CWETypeRQLAction), |
1654 | 418 |
], |
0 | 419 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
420 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 421 |
self.assertDictEqual(self.pactions(req, rset), |
422 |
{'useractions': USERACTIONS, |
|
423 |
'siteactions': SITEACTIONS, |
|
424 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 425 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
426 |
('delete', actions.DeleteAction), |
|
783 | 427 |
('copy', actions.CopyAction), |
1654 | 428 |
], |
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() |