author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 29 Jul 2009 09:08:26 +0200 | |
changeset 2550 | 4e009026a0f0 |
parent 2458 | 4d114865098f |
child 2643 | 9976f511003b |
permissions | -rw-r--r-- |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
0 | 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 |
|
2403
74f7fa676a52
fix typo, remove debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2401
diff
changeset
|
63 |
def setUp(self): |
74f7fa676a52
fix typo, remove debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2401
diff
changeset
|
64 |
super(VRegistryTC, self).setUp() |
74f7fa676a52
fix typo, remove debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2401
diff
changeset
|
65 |
assert self.vreg['views']['propertiesform'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
66 |
|
793 | 67 |
def test_possible_views_none_rset(self): |
0 | 68 |
req = self.request() |
69 |
self.assertListEqual(self.pviews(req, None), |
|
70 |
[('changelog', wdoc.ChangeLogView), |
|
71 |
('debug', debug.DebugView), |
|
72 |
('index', startup.IndexView), |
|
73 |
('info', management.ProcessInformationView), |
|
74 |
('manage', startup.ManageView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
75 |
('owl', owl.OWLView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
76 |
('propertiesform', cwproperties.CWPropertiesForm), |
0 | 77 |
('schema', startup.SchemaView), |
1900
8dd4bb69c73d
[tests] fix test after eproperties got renamed to cwproperties
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
78 |
('systempropertiesform', cwproperties.SystemCWPropertiesForm)]) |
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_noresult(self): |
0 | 81 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
82 |
self.assertListEqual(self.pviews(req, rset), |
|
783 | 83 |
[]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
84 |
|
793 | 85 |
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
|
86 |
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"') |
0 | 87 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 88 |
[('csvexport', csvexport.CSVRsetView), |
89 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 90 |
('editable-table', tableview.EditableTableView), |
444 | 91 |
('filetree', treeview.FileTreeView), |
0 | 92 |
('list', baseviews.ListView), |
93 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
94 |
('owlabox', owl.OWLABOXView), |
1654 | 95 |
('primary', primary.PrimaryView), |
96 |
('rsetxml', xmlrss.XMLRsetView), |
|
97 |
('rss', xmlrss.RSSView), |
|
0 | 98 |
('secondary', baseviews.SecondaryView), |
99 |
('security', management.SecurityManagementView), |
|
100 |
('table', tableview.TableView), |
|
101 |
('text', baseviews.TextView), |
|
444 | 102 |
('treeview', treeview.TreeView), |
0 | 103 |
('xbel', xbel.XbelView), |
1654 | 104 |
('xml', xmlrss.XMLView), |
0 | 105 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
106 |
|
793 | 107 |
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
|
108 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 109 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 110 |
[('csvexport', csvexport.CSVRsetView), |
111 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 112 |
('editable-table', tableview.EditableTableView), |
444 | 113 |
('filetree', treeview.FileTreeView), |
0 | 114 |
('list', baseviews.ListView), |
115 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
116 |
('owlabox', owl.OWLABOXView), |
1654 | 117 |
('primary', primary.PrimaryView), |
118 |
('rsetxml', xmlrss.XMLRsetView), |
|
119 |
('rss', xmlrss.RSSView), |
|
0 | 120 |
('secondary', baseviews.SecondaryView), |
121 |
('security', management.SecurityManagementView), |
|
122 |
('table', tableview.TableView), |
|
123 |
('text', baseviews.TextView), |
|
444 | 124 |
('treeview', treeview.TreeView), |
0 | 125 |
('xbel', xbel.XbelView), |
1654 | 126 |
('xml', xmlrss.XMLView), |
0 | 127 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
128 |
|
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
129 |
def test_propertiesform_admin(self): |
2403
74f7fa676a52
fix typo, remove debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2401
diff
changeset
|
130 |
assert self.vreg['views']['propertiesform'] |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
131 |
rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
132 |
rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"') |
2404
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
133 |
self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None)) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
134 |
self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=rset1)) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
135 |
self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2)) |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
136 |
|
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
137 |
def test_propertiesform_anon(self): |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
138 |
self.login('anon') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
139 |
rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
140 |
rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"') |
2404
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
141 |
self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=None) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
142 |
self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
143 |
self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset2) |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
144 |
|
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
145 |
def test_propertiesform_jdoe(self): |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
146 |
self.create_user('jdoe') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
147 |
self.login('jdoe') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
148 |
rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"') |
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
149 |
rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "jdoe"') |
2404
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
150 |
self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None)) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
151 |
self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1) |
2d3c1a3f76c5
remove with statement
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2401
diff
changeset
|
152 |
self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2)) |
2401
890f6b990dd7
[views] epropertiesform renamed propertiesform
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
153 |
|
793 | 154 |
def test_possible_views_multiple_different_types(self): |
0 | 155 |
rset, req = self.env.get_rset_and_req('Any X') |
156 |
self.assertListEqual(self.pviews(req, rset), |
|
1654 | 157 |
[('csvexport', csvexport.CSVRsetView), |
158 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 159 |
('editable-table', tableview.EditableTableView), |
444 | 160 |
('filetree', treeview.FileTreeView), |
0 | 161 |
('list', baseviews.ListView), |
162 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
163 |
('owlabox', owl.OWLABOXView), |
1654 | 164 |
('primary', primary.PrimaryView), |
165 |
('rsetxml', xmlrss.XMLRsetView), |
|
166 |
('rss', xmlrss.RSSView), |
|
0 | 167 |
('secondary', baseviews.SecondaryView), |
168 |
('security', management.SecurityManagementView), |
|
169 |
('table', tableview.TableView), |
|
170 |
('text', baseviews.TextView), |
|
444 | 171 |
('treeview', treeview.TreeView), |
0 | 172 |
('xbel', xbel.XbelView), |
1654 | 173 |
('xml', xmlrss.XMLView), |
0 | 174 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
175 |
|
793 | 176 |
def test_possible_views_any_rset(self): |
0 | 177 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
178 |
self.assertListEqual(self.pviews(req, rset), |
|
1654 | 179 |
[('csvexport', csvexport.CSVRsetView), |
0 | 180 |
('editable-table', tableview.EditableTableView), |
1654 | 181 |
('rsetxml', xmlrss.XMLRsetView), |
0 | 182 |
('table', tableview.TableView), |
183 |
]) |
|
793 | 184 |
|
185 |
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
|
186 |
rset, req = self.env.get_rset_and_req('CWUser X') |
0 | 187 |
self.assertListEqual(self.pviews(req, rset), |
1654 | 188 |
[('csvexport', csvexport.CSVRsetView), |
189 |
('ecsvexport', csvexport.CSVEntityView), |
|
0 | 190 |
('editable-table', tableview.EditableTableView), |
444 | 191 |
('filetree', treeview.FileTreeView), |
1654 | 192 |
('foaf', cwuser.FoafView), |
0 | 193 |
('list', baseviews.ListView), |
194 |
('oneline', baseviews.OneLineView), |
|
587
c8ff5d88f164
adding views to test
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
479
diff
changeset
|
195 |
('owlabox', owl.OWLABOXView), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
196 |
('primary', primary.PrimaryView), |
1654 | 197 |
('rsetxml', xmlrss.XMLRsetView), |
198 |
('rss', xmlrss.RSSView), |
|
0 | 199 |
('secondary', baseviews.SecondaryView), |
200 |
('security', management.SecurityManagementView), |
|
201 |
('table', tableview.TableView), |
|
202 |
('text', baseviews.TextView), |
|
444 | 203 |
('treeview', treeview.TreeView), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
204 |
('vcard', vcard.VCardCWUserView), |
2440
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2439
diff
changeset
|
205 |
('wfhistory', workflow.WFHistoryView), |
0 | 206 |
('xbel', xbel.XbelView), |
1654 | 207 |
('xml', xmlrss.XMLView), |
0 | 208 |
]) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
209 |
|
0 | 210 |
def test_possible_actions_none_rset(self): |
211 |
req = self.request() |
|
212 |
self.assertDictEqual(self.pactions(req, None), |
|
213 |
{'useractions': USERACTIONS, |
|
214 |
'siteactions': SITEACTIONS, |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
215 |
|
0 | 216 |
}) |
217 |
def test_possible_actions_no_entity(self): |
|
218 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
219 |
self.assertDictEqual(self.pactions(req, rset), |
|
220 |
{'useractions': USERACTIONS, |
|
221 |
'siteactions': SITEACTIONS, |
|
222 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
223 |
|
0 | 224 |
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
|
225 |
rset, req = self.env.get_rset_and_req('CWGroup X') |
0 | 226 |
self.assertDictEqual(self.pactions(req, rset), |
227 |
{'useractions': USERACTIONS, |
|
228 |
'siteactions': SITEACTIONS, |
|
229 |
'mainactions': [('muledit', actions.MultipleEditAction)], |
|
230 |
'moreactions': [('delete', actions.DeleteAction), |
|
231 |
('addentity', actions.AddNewAction)], |
|
232 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
233 |
|
0 | 234 |
def test_possible_actions_different_types_entities(self): |
235 |
rset, req = self.env.get_rset_and_req('Any X') |
|
236 |
self.assertDictEqual(self.pactions(req, rset), |
|
237 |
{'useractions': USERACTIONS, |
|
238 |
'siteactions': SITEACTIONS, |
|
239 |
'moreactions': [('delete', actions.DeleteAction)], |
|
240 |
}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
241 |
|
0 | 242 |
def test_possible_actions_final_entities(self): |
243 |
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N') |
|
244 |
self.assertDictEqual(self.pactions(req, rset), |
|
245 |
{'useractions': USERACTIONS, |
|
246 |
'siteactions': SITEACTIONS}) |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
247 |
|
1654 | 248 |
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
|
249 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWUser"') |
0 | 250 |
self.assertDictEqual(self.pactions(req, rset), |
251 |
{'useractions': USERACTIONS, |
|
252 |
'siteactions': SITEACTIONS, |
|
253 |
'mainactions': [('edit', actions.ModifyAction), |
|
1654 | 254 |
('workflow', workflow.ViewWorkflowAction),], |
255 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
|
256 |
('delete', actions.DeleteAction), |
|
793 | 257 |
('copy', actions.CopyAction), |
1654 | 258 |
], |
0 | 259 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
260 |
|
0 | 261 |
|
262 |
def test_select_creation_form(self): |
|
263 |
rset = None |
|
264 |
req = self.request() |
|
265 |
# creation form |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
266 |
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
|
267 |
self.assertIsInstance(self.vreg.select('views', 'creation', req, rset=rset), |
1654 | 268 |
editforms.CreationFormView) |
0 | 269 |
del req.form['etype'] |
270 |
# custom creation form |
|
1654 | 271 |
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
|
272 |
__select__ = specified_etype_implements('CWUser') |
1654 | 273 |
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
CWUserCreationForm) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
278 |
|
0 | 279 |
def test_select_view(self): |
280 |
# no entity |
|
281 |
rset = None |
|
282 |
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
|
283 |
self.assertIsInstance(self.vreg.select('views', 'index', req, rset=rset), |
0 | 284 |
startup.IndexView) |
285 |
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
|
286 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 287 |
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
|
288 |
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
|
289 |
|
0 | 290 |
# no entity |
291 |
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') |
|
292 |
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
|
293 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 294 |
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
|
295 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 296 |
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
|
297 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 298 |
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
|
299 |
self.vreg.select, 'views', 'table', req, rset=rset) |
0 | 300 |
# one entity |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
301 |
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
|
302 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 303 |
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
|
304 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 305 |
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
|
306 |
self.assertIsInstance(self.vreg.select('views', 'edition', req, rset=rset), |
1654 | 307 |
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
|
308 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 309 |
tableview.TableView) |
310 |
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
|
311 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 312 |
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
|
313 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 314 |
# 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
|
315 |
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
|
316 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 317 |
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
|
318 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 319 |
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
|
320 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 321 |
tableview.TableView) |
322 |
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
|
323 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 324 |
# list of entities of different types |
325 |
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
|
326 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
1654 | 327 |
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
|
328 |
self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset), |
0 | 329 |
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
|
330 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 331 |
tableview.TableView) |
332 |
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
|
333 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 334 |
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
|
335 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 336 |
# whatever |
337 |
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
|
338 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 339 |
tableview.TableView) |
340 |
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
|
341 |
self.vreg.select, 'views', 'index', req, rset=rset) |
0 | 342 |
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
|
343 |
self.vreg.select, 'views', 'creation', req, rset=rset) |
0 | 344 |
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
|
345 |
self.vreg.select, 'views', 'primary', req, rset=rset) |
0 | 346 |
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
|
347 |
self.vreg.select, 'views', 'list', req, rset=rset) |
0 | 348 |
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
|
349 |
self.vreg.select, 'views', 'edition', req, rset=rset) |
0 | 350 |
# mixed query |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
351 |
rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup') |
0 | 352 |
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
|
353 |
self.vreg.select, 'views', 'edition', req, rset=rset) |
0 | 354 |
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
|
355 |
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
|
356 |
self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset), |
0 | 357 |
tableview.TableView) |
358 |
||
359 |
def test_interface_selector(self): |
|
360 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
361 |
# image primary view priority |
|
362 |
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
|
363 |
self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset), |
0 | 364 |
idownloadable.IDownloadablePrimaryView) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
365 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
366 |
|
0 | 367 |
def test_score_entity_selector(self): |
368 |
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim')) |
|
369 |
# image primary view priority |
|
370 |
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
|
371 |
self.assertIsInstance(self.vreg.select('views', 'image', req, rset=rset), |
0 | 372 |
idownloadable.ImageView) |
373 |
fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim')) |
|
374 |
# image primary view priority |
|
375 |
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
|
376 |
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
|
377 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
378 |
|
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
379 |
|
0 | 380 |
def _test_view(self, vid, rql, args): |
381 |
if rql is None: |
|
382 |
rset = None |
|
383 |
req = self.request() |
|
384 |
else: |
|
385 |
rset, req = self.env.get_rset_and_req(rql) |
|
386 |
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
|
387 |
self.vreg.render(vid, req, rset=rset, **args) |
0 | 388 |
except: |
389 |
print vid, rset, args |
|
390 |
raise |
|
391 |
||
392 |
def test_form(self): |
|
393 |
for vid, rql, args in ( |
|
394 |
#('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
|
395 |
('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
|
396 |
('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
|
397 |
('muledit', 'CWGroup X', {}), |
0 | 398 |
#('muledit', 'Any X', {}), |
399 |
): |
|
400 |
self._test_view(vid, rql, args) |
|
401 |
||
402 |
||
403 |
def test_properties(self): |
|
404 |
self.assertEquals(sorted(k for k in self.vreg['propertydefs'].keys() |
|
405 |
if k.startswith('boxes.edit_box')), |
|
406 |
['boxes.edit_box.context', |
|
407 |
'boxes.edit_box.order', |
|
408 |
'boxes.edit_box.visible']) |
|
409 |
self.assertEquals([k for k in self.vreg['propertyvalues'].keys() |
|
410 |
if not k.startswith('system.version')], |
|
411 |
[]) |
|
412 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.visible'), True) |
|
413 |
self.assertEquals(self.vreg.property_value('boxes.edit_box.order'), 2) |
|
414 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False) |
|
415 |
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10) |
|
416 |
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box') |
|
417 |
||
418 |
||
419 |
||
420 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
421 |
class CWETypeRQLAction(Action): |
0 | 422 |
id = 'testaction' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
423 |
__select__ = implements('CWEType') & rql_condition('X name "CWEType"') |
0 | 424 |
title = 'bla' |
425 |
||
426 |
class RQLActionTC(ViewSelectorTC): |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
427 |
|
0 | 428 |
def setUp(self): |
429 |
super(RQLActionTC, self).setUp() |
|
1654 | 430 |
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
|
431 |
self.vreg.register_vobject_class(CWETypeRQLAction) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
432 |
|
0 | 433 |
def tearDown(self): |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
434 |
super(RQLActionTC, self).tearDown() |
0 | 435 |
del self.vreg._registries['actions']['testaction'] |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
436 |
|
0 | 437 |
def test(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
438 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"') |
0 | 439 |
self.assertDictEqual(self.pactions(req, rset), |
440 |
{'useractions': USERACTIONS, |
|
441 |
'siteactions': SITEACTIONS, |
|
442 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 443 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
444 |
('delete', actions.DeleteAction), |
|
0 | 445 |
('copy', actions.CopyAction), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
446 |
('testaction', CWETypeRQLAction), |
1654 | 447 |
], |
0 | 448 |
}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
793
diff
changeset
|
449 |
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWRType"') |
0 | 450 |
self.assertDictEqual(self.pactions(req, rset), |
451 |
{'useractions': USERACTIONS, |
|
452 |
'siteactions': SITEACTIONS, |
|
453 |
'mainactions': [('edit', actions.ModifyAction)], |
|
1654 | 454 |
'moreactions': [('managepermission', actions.ManagePermissionsAction), |
455 |
('delete', actions.DeleteAction), |
|
783 | 456 |
('copy', actions.CopyAction), |
1654 | 457 |
], |
0 | 458 |
}) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
459 |
|
0 | 460 |
|
461 |
||
462 |
if __name__ == '__main__': |
|
463 |
unittest_main() |