author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Mar 2010 09:23:05 +0100 | |
changeset 4923 | 449f6c144ad4 |
parent 4758 | 0efdcf0fa4c7 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3930
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
7 |
""" |
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
8 |
from logilab.common.testlib import unittest_main, mock_object |
3757 | 9 |
from logilab.common.compat import any |
3722 | 10 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
11 |
from cubicweb.devtools.testlib import CubicWebTC |
4080 | 12 |
from cubicweb.web import uicfg |
1359 | 13 |
from cubicweb.web.formwidgets import AutoCompletionWidget |
3722 | 14 |
|
4080 | 15 |
AFFK = uicfg.autoform_field_kwargs |
16 |
AFS = uicfg.autoform_section |
|
1287 | 17 |
|
4080 | 18 |
def rbc(entity, formtype, section): |
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
19 |
if section in ('attributes', 'metadata', 'hidden'): |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
20 |
permission = 'update' |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
21 |
else: |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
22 |
permission = 'add' |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
23 |
return [(rschema.type, x) for rschema, tschemas, x in AFS.relations_by_section(entity, formtype, section, permission)] |
1287 | 24 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
25 |
class AutomaticEntityFormTC(CubicWebTC): |
1287 | 26 |
|
1359 | 27 |
def test_custom_widget(self): |
4080 | 28 |
AFFK.tag_subject_of(('CWUser', 'login', '*'), |
29 |
{'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')}) |
|
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
30 |
form = self.vreg['forms'].select('edition', self.request(), |
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
31 |
entity=self.user()) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4080
diff
changeset
|
32 |
field = form.field_by_name('login', 'subject') |
1359 | 33 |
self.assertIsInstance(field.widget, AutoCompletionWidget) |
4080 | 34 |
AFFK.del_rtag('CWUser', 'login', '*', 'subject') |
1533 | 35 |
|
1359 | 36 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
37 |
def test_cwuser_relations_by_category(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
38 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
39 |
# see custom configuration in views.cwuser |
4080 | 40 |
self.assertEquals(rbc(e, 'main', 'attributes'), |
1287 | 41 |
[('login', 'subject'), |
42 |
('upassword', 'subject'), |
|
4080 | 43 |
('firstname', 'subject'), |
44 |
('surname', 'subject'), |
|
1287 | 45 |
('in_group', 'subject'), |
46 |
]) |
|
4080 | 47 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
48 |
[('login', 'subject'), |
|
49 |
('upassword', 'subject'), |
|
50 |
('in_group', 'subject'), |
|
1287 | 51 |
]) |
4080 | 52 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
1287 | 53 |
[('last_login_time', 'subject'), |
3771 | 54 |
('modification_date', 'subject'), |
1287 | 55 |
('created_by', 'subject'), |
56 |
('creation_date', 'subject'), |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
57 |
('cwuri', 'subject'), |
1287 | 58 |
('owned_by', 'subject'), |
59 |
('bookmarked_by', 'object'), |
|
1533 | 60 |
]) |
4726
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
61 |
# XXX skip 'tags' relation here and in the hidden category because |
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
62 |
# of some test interdependancy when pytest is launched on whole cw |
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
63 |
# (appears here while expected in hidden |
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
64 |
self.assertListEquals([x for x in rbc(e, 'main', 'relations') |
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
65 |
if x != ('tags', 'object')], |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
66 |
[('primary_email', 'subject'), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
67 |
('custom_workflow', 'subject'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
68 |
('connait', 'subject'), |
1287 | 69 |
('checked_by', 'object'), |
70 |
]) |
|
4080 | 71 |
self.assertListEquals(rbc(e, 'main', 'inlined'), |
72 |
[('use_email', 'subject'), |
|
73 |
]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
74 |
# owned_by is defined both as subject and object relations on CWUser |
4726
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
75 |
self.assertListEquals(sorted(x for x in rbc(e, 'main', 'hidden') |
1357833f5595
[test] XXX fix to have pytest succeed on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
76 |
if x != ('tags', 'object')), |
4758
0efdcf0fa4c7
fix code and tests broken by 4744:13a5d3a7410e (proper permission on eid/has_text/identity relations)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4726
diff
changeset
|
77 |
sorted([('for_user', 'object'), |
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
78 |
('created_by', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
79 |
('wf_info_for', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
80 |
('owned_by', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
81 |
])) |
1298 | 82 |
|
83 |
def test_inlined_view(self): |
|
4080 | 84 |
self.failUnless('main_inlined' in AFS.etype_get('CWUser', 'use_email', 'subject', 'EmailAddress')) |
85 |
self.failIf('main_inlined' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
86 |
self.failUnless('main_relations' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
1533 | 87 |
|
1287 | 88 |
def test_personne_relations_by_category(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
89 |
e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
4080 | 90 |
self.assertListEquals(rbc(e, 'main', 'attributes'), |
1287 | 91 |
[('nom', 'subject'), |
4080 | 92 |
('prenom', 'subject'), |
1287 | 93 |
('sexe', 'subject'), |
94 |
('promo', 'subject'), |
|
95 |
('titre', 'subject'), |
|
96 |
('ass', 'subject'), |
|
97 |
('web', 'subject'), |
|
98 |
('tel', 'subject'), |
|
99 |
('fax', 'subject'), |
|
100 |
('datenaiss', 'subject'), |
|
101 |
('test', 'subject'), |
|
102 |
('description', 'subject'), |
|
4080 | 103 |
('salary', 'subject'), |
1287 | 104 |
]) |
4080 | 105 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
106 |
[('nom', 'subject'), |
|
107 |
]) |
|
108 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
|
3771 | 109 |
[('creation_date', 'subject'), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
110 |
('cwuri', 'subject'), |
1287 | 111 |
('modification_date', 'subject'), |
3771 | 112 |
('created_by', 'subject'), |
1287 | 113 |
('owned_by', 'subject'), |
1533 | 114 |
]) |
4080 | 115 |
self.assertListEquals(rbc(e, 'main', 'relations'), |
1287 | 116 |
[('travaille', 'subject'), |
117 |
('connait', 'object') |
|
118 |
]) |
|
4080 | 119 |
self.assertListEquals(rbc(e, 'main', 'hidden'), |
4758
0efdcf0fa4c7
fix code and tests broken by 4744:13a5d3a7410e (proper permission on eid/has_text/identity relations)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4726
diff
changeset
|
120 |
[]) |
1533 | 121 |
|
1300 | 122 |
def test_edition_form(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
123 |
rset = self.execute('CWUser X LIMIT 1') |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
124 |
form = self.vreg['forms'].select('edition', rset.req, rset=rset, |
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
|
125 |
row=0, col=0) |
1300 | 126 |
# should be also selectable by specifying entity |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
127 |
self.vreg['forms'].select('edition', rset.req, |
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
|
128 |
entity=rset.get_entity(0, 0)) |
1300 | 129 |
self.failIf(any(f for f in form.fields if f is None)) |
1533 | 130 |
|
131 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
132 |
class FormViewsTC(CubicWebTC): |
1300 | 133 |
def test_delete_conf_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
134 |
rset = self.execute('CWGroup X') |
1300 | 135 |
self.view('deleteconf', rset, template=None).source |
1533 | 136 |
|
1300 | 137 |
def test_automatic_edition_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
138 |
rset = self.execute('CWUser X') |
1300 | 139 |
self.view('edition', rset, row=0, template=None).source |
1533 | 140 |
|
1300 | 141 |
def test_automatic_edition_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
142 |
rset = self.execute('CWUser X') |
1300 | 143 |
self.view('copy', rset, row=0, template=None).source |
1533 | 144 |
|
1300 | 145 |
def test_automatic_creation_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
146 |
self.view('creation', None, etype='CWUser', template=None).source |
1533 | 147 |
|
1300 | 148 |
def test_automatic_muledit_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
149 |
rset = self.execute('CWUser X') |
1300 | 150 |
self.view('muledit', rset, template=None).source |
1533 | 151 |
|
1300 | 152 |
def test_automatic_reledit_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
153 |
rset = self.execute('CWUser X') |
1300 | 154 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
1533 | 155 |
|
1300 | 156 |
def test_automatic_inline_edit_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
157 |
geid = self.execute('CWGroup X LIMIT 1')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
158 |
rset = self.execute('CWUser X LIMIT 1') |
3361
be0605689fed
[tests] fix inline-creation/edition unit tests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2920
diff
changeset
|
159 |
self.view('inline-edition', rset, row=0, col=0, rtype='in_group', |
4677
c701aac36f5c
[test] inline-creation requires petype argument to be selectable. Fix arguments order to make it clearer that 'template' is an argument of the test class .view method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
160 |
peid=geid, role='object', i18nctx='', pform=MOCKPFORM, |
c701aac36f5c
[test] inline-creation requires petype argument to be selectable. Fix arguments order to make it clearer that 'template' is an argument of the test class .view method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
161 |
template=None).source |
1533 | 162 |
|
1300 | 163 |
def test_automatic_inline_creation_formview(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
164 |
geid = self.execute('CWGroup X LIMIT 1')[0][0] |
3361
be0605689fed
[tests] fix inline-creation/edition unit tests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2920
diff
changeset
|
165 |
self.view('inline-creation', None, etype='CWUser', rtype='in_group', |
4677
c701aac36f5c
[test] inline-creation requires petype argument to be selectable. Fix arguments order to make it clearer that 'template' is an argument of the test class .view method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
166 |
peid=geid, petype='CWGroup', i18nctx='', role='object', pform=MOCKPFORM, |
c701aac36f5c
[test] inline-creation requires petype argument to be selectable. Fix arguments order to make it clearer that 'template' is an argument of the test class .view method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4570
diff
changeset
|
167 |
template=None) |
1300 | 168 |
|
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
169 |
MOCKPFORM = mock_object(form_previous_values={}, form_valerror=None) |
1533 | 170 |
|
1287 | 171 |
if __name__ == '__main__': |
172 |
unittest_main() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
173 |