author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 15 Feb 2010 17:47:50 +0100 | |
branch | stable |
changeset 4585 | 912aba7e6400 |
parent 4570 | ede247bbbf62 |
child 4677 | c701aac36f5c |
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): |
1287 | 38 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
39 |
# if rtype == 'tags': |
|
40 |
# print rtype, role, stype, otype, ':', tag |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
41 |
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
|
42 |
# see custom configuration in views.cwuser |
4080 | 43 |
self.assertEquals(rbc(e, 'main', 'attributes'), |
1287 | 44 |
[('login', 'subject'), |
45 |
('upassword', 'subject'), |
|
4080 | 46 |
('firstname', 'subject'), |
47 |
('surname', 'subject'), |
|
1287 | 48 |
('in_group', 'subject'), |
49 |
('eid', 'subject'), |
|
50 |
]) |
|
4080 | 51 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
52 |
[('login', 'subject'), |
|
53 |
('upassword', 'subject'), |
|
54 |
('in_group', 'subject'), |
|
55 |
('eid', 'subject'), |
|
1287 | 56 |
]) |
4080 | 57 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
1287 | 58 |
[('last_login_time', 'subject'), |
3771 | 59 |
('modification_date', 'subject'), |
1287 | 60 |
('created_by', 'subject'), |
61 |
('creation_date', 'subject'), |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
62 |
('cwuri', 'subject'), |
1287 | 63 |
('owned_by', 'subject'), |
64 |
('bookmarked_by', 'object'), |
|
1533 | 65 |
]) |
4080 | 66 |
self.assertListEquals(rbc(e, 'main', 'relations'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
67 |
[('primary_email', 'subject'), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
68 |
('custom_workflow', 'subject'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
69 |
('connait', 'subject'), |
1287 | 70 |
('checked_by', 'object'), |
71 |
]) |
|
4080 | 72 |
self.assertListEquals(rbc(e, 'main', 'inlined'), |
73 |
[('use_email', 'subject'), |
|
74 |
]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
75 |
# owned_by is defined both as subject and object relations on CWUser |
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
76 |
self.assertListEquals(sorted(rbc(e, 'main', 'hidden')), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
77 |
sorted([('has_text', 'subject'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
78 |
('identity', 'subject'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
79 |
('tags', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
80 |
('for_user', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
81 |
('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
|
82 |
('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
|
83 |
('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
|
84 |
('identity', 'object'), |
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
85 |
])) |
1298 | 86 |
|
87 |
def test_inlined_view(self): |
|
4080 | 88 |
self.failUnless('main_inlined' in AFS.etype_get('CWUser', 'use_email', 'subject', 'EmailAddress')) |
89 |
self.failIf('main_inlined' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
90 |
self.failUnless('main_relations' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
1533 | 91 |
|
1287 | 92 |
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
|
93 |
e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
4080 | 94 |
self.assertListEquals(rbc(e, 'main', 'attributes'), |
1287 | 95 |
[('nom', 'subject'), |
4080 | 96 |
('prenom', 'subject'), |
1287 | 97 |
('sexe', 'subject'), |
98 |
('promo', 'subject'), |
|
99 |
('titre', 'subject'), |
|
100 |
('ass', 'subject'), |
|
101 |
('web', 'subject'), |
|
102 |
('tel', 'subject'), |
|
103 |
('fax', 'subject'), |
|
104 |
('datenaiss', 'subject'), |
|
105 |
('test', 'subject'), |
|
106 |
('description', 'subject'), |
|
4080 | 107 |
('salary', 'subject'), |
108 |
('eid', 'subject') |
|
1287 | 109 |
]) |
4080 | 110 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
111 |
[('nom', 'subject'), |
|
112 |
('eid', 'subject') |
|
113 |
]) |
|
114 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
|
3771 | 115 |
[('creation_date', 'subject'), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
116 |
('cwuri', 'subject'), |
1287 | 117 |
('modification_date', 'subject'), |
3771 | 118 |
('created_by', 'subject'), |
1287 | 119 |
('owned_by', 'subject'), |
1533 | 120 |
]) |
4080 | 121 |
self.assertListEquals(rbc(e, 'main', 'relations'), |
1287 | 122 |
[('travaille', 'subject'), |
123 |
('connait', 'object') |
|
124 |
]) |
|
4080 | 125 |
self.assertListEquals(rbc(e, 'main', 'hidden'), |
4570
ede247bbbf62
follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
126 |
[('has_text', 'subject'), |
1300 | 127 |
('identity', 'subject'), |
128 |
('identity', 'object'), |
|
1287 | 129 |
]) |
1533 | 130 |
|
1300 | 131 |
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
|
132 |
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
|
133 |
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
|
134 |
row=0, col=0) |
1300 | 135 |
# 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
|
136 |
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
|
137 |
entity=rset.get_entity(0, 0)) |
1300 | 138 |
self.failIf(any(f for f in form.fields if f is None)) |
1533 | 139 |
|
140 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
141 |
class FormViewsTC(CubicWebTC): |
1300 | 142 |
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
|
143 |
rset = self.execute('CWGroup X') |
1300 | 144 |
self.view('deleteconf', rset, template=None).source |
1533 | 145 |
|
1300 | 146 |
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
|
147 |
rset = self.execute('CWUser X') |
1300 | 148 |
self.view('edition', rset, row=0, template=None).source |
1533 | 149 |
|
1300 | 150 |
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
|
151 |
rset = self.execute('CWUser X') |
1300 | 152 |
self.view('copy', rset, row=0, template=None).source |
1533 | 153 |
|
1300 | 154 |
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
|
155 |
self.view('creation', None, etype='CWUser', template=None).source |
1533 | 156 |
|
1300 | 157 |
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
|
158 |
rset = self.execute('CWUser X') |
1300 | 159 |
self.view('muledit', rset, template=None).source |
1533 | 160 |
|
1300 | 161 |
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
|
162 |
rset = self.execute('CWUser X') |
1300 | 163 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
1533 | 164 |
|
1300 | 165 |
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
|
166 |
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
|
167 |
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
|
168 |
self.view('inline-edition', rset, row=0, col=0, rtype='in_group', |
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
169 |
peid=geid, role='object', template=None, i18nctx='', |
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
170 |
pform=MOCKPFORM).source |
1533 | 171 |
|
1300 | 172 |
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
|
173 |
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
|
174 |
self.view('inline-creation', None, etype='CWUser', rtype='in_group', |
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
175 |
peid=geid, template=None, i18nctx='', role='object', |
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
176 |
pform=MOCKPFORM).source |
1300 | 177 |
|
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
178 |
MOCKPFORM = mock_object(form_previous_values={}, form_valerror=None) |
1533 | 179 |
|
1287 | 180 |
if __name__ == '__main__': |
181 |
unittest_main() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
182 |