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