author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 21 Dec 2009 18:43:16 +0100 | |
changeset 4151 | 66fe38345a65 |
parent 4080 | f88331eb374c |
child 4172 | 4d4cef034eec |
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 |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1797
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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 |
|
17 |
||
18 |
def rbc(entity, formtype, section): |
|
19 |
return [(rschema.type, x) for rschema, tschemas, x in AFS.relations_by_section(entity, formtype, section)] |
|
1287 | 20 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
21 |
class AutomaticEntityFormTC(CubicWebTC): |
1287 | 22 |
|
1359 | 23 |
def test_custom_widget(self): |
4080 | 24 |
AFFK.tag_subject_of(('CWUser', 'login', '*'), |
25 |
{'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
|
26 |
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
|
27 |
entity=self.user()) |
1359 | 28 |
field = form.field_by_name('login') |
29 |
self.assertIsInstance(field.widget, AutoCompletionWidget) |
|
4080 | 30 |
AFFK.del_rtag('CWUser', 'login', '*', 'subject') |
1533 | 31 |
|
1359 | 32 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
33 |
def test_cwuser_relations_by_category(self): |
1287 | 34 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
35 |
# if rtype == 'tags': |
|
36 |
# 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
|
37 |
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
|
38 |
# see custom configuration in views.cwuser |
4080 | 39 |
self.assertEquals(rbc(e, 'main', 'attributes'), |
1287 | 40 |
[('login', 'subject'), |
41 |
('upassword', 'subject'), |
|
4080 | 42 |
('firstname', 'subject'), |
43 |
('surname', 'subject'), |
|
1287 | 44 |
('in_group', 'subject'), |
45 |
('eid', 'subject'), |
|
46 |
]) |
|
4080 | 47 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
48 |
[('login', 'subject'), |
|
49 |
('upassword', 'subject'), |
|
50 |
('in_group', 'subject'), |
|
51 |
('eid', 'subject'), |
|
1287 | 52 |
]) |
4080 | 53 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
1287 | 54 |
[('last_login_time', 'subject'), |
3771 | 55 |
('modification_date', 'subject'), |
1287 | 56 |
('created_by', 'subject'), |
57 |
('creation_date', 'subject'), |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
58 |
('cwuri', 'subject'), |
1287 | 59 |
('owned_by', 'subject'), |
60 |
('bookmarked_by', 'object'), |
|
1533 | 61 |
]) |
4080 | 62 |
self.assertListEquals(rbc(e, 'main', 'relations'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
63 |
[('primary_email', 'subject'), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
64 |
('custom_workflow', 'subject'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
65 |
('connait', 'subject'), |
1287 | 66 |
('checked_by', 'object'), |
67 |
]) |
|
4080 | 68 |
self.assertListEquals(rbc(e, 'main', 'inlined'), |
69 |
[('use_email', 'subject'), |
|
70 |
]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
71 |
# owned_by is defined both as subject and object relations on CWUser |
4080 | 72 |
self.assertListEquals(rbc(e, 'main', 'hidden'), |
73 |
[('in_state', 'subject'), |
|
3771 | 74 |
('is', 'subject'), |
75 |
('is_instance_of', 'subject'), |
|
1654 | 76 |
('has_text', 'subject'), |
1300 | 77 |
('identity', 'subject'), |
1287 | 78 |
('tags', 'object'), |
79 |
('for_user', 'object'), |
|
80 |
('created_by', 'object'), |
|
81 |
('wf_info_for', 'object'), |
|
82 |
('owned_by', 'object'), |
|
1300 | 83 |
('identity', 'object'), |
1287 | 84 |
]) |
1298 | 85 |
|
86 |
def test_inlined_view(self): |
|
4080 | 87 |
self.failUnless('main_inlined' in AFS.etype_get('CWUser', 'use_email', 'subject', 'EmailAddress')) |
88 |
self.failIf('main_inlined' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
89 |
self.failUnless('main_relations' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
1533 | 90 |
|
1287 | 91 |
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
|
92 |
e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
4080 | 93 |
self.assertListEquals(rbc(e, 'main', 'attributes'), |
1287 | 94 |
[('nom', 'subject'), |
4080 | 95 |
('prenom', 'subject'), |
1287 | 96 |
('sexe', 'subject'), |
97 |
('promo', 'subject'), |
|
98 |
('titre', 'subject'), |
|
99 |
('ass', 'subject'), |
|
100 |
('web', 'subject'), |
|
101 |
('tel', 'subject'), |
|
102 |
('fax', 'subject'), |
|
103 |
('datenaiss', 'subject'), |
|
104 |
('test', 'subject'), |
|
105 |
('description', 'subject'), |
|
4080 | 106 |
('salary', 'subject'), |
107 |
('eid', 'subject') |
|
1287 | 108 |
]) |
4080 | 109 |
self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
110 |
[('nom', 'subject'), |
|
111 |
('eid', 'subject') |
|
112 |
]) |
|
113 |
self.assertListEquals(rbc(e, 'main', 'metadata'), |
|
3771 | 114 |
[('creation_date', 'subject'), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
115 |
('cwuri', 'subject'), |
1287 | 116 |
('modification_date', 'subject'), |
3771 | 117 |
('created_by', 'subject'), |
1287 | 118 |
('owned_by', 'subject'), |
1533 | 119 |
]) |
4080 | 120 |
self.assertListEquals(rbc(e, 'main', 'relations'), |
1287 | 121 |
[('travaille', 'subject'), |
122 |
('connait', 'object') |
|
123 |
]) |
|
4080 | 124 |
self.assertListEquals(rbc(e, 'main', 'hidden'), |
3771 | 125 |
[('is', 'subject'), |
126 |
('has_text', 'subject'), |
|
1300 | 127 |
('identity', 'subject'), |
1287 | 128 |
('is_instance_of', 'subject'), |
1300 | 129 |
('identity', 'object'), |
1287 | 130 |
]) |
1533 | 131 |
|
1300 | 132 |
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
|
133 |
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
|
134 |
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
|
135 |
row=0, col=0) |
1300 | 136 |
# 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
|
137 |
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
|
138 |
entity=rset.get_entity(0, 0)) |
1300 | 139 |
self.failIf(any(f for f in form.fields if f is None)) |
1533 | 140 |
|
141 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
142 |
class FormViewsTC(CubicWebTC): |
1300 | 143 |
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
|
144 |
rset = self.execute('CWGroup X') |
1300 | 145 |
self.view('deleteconf', rset, template=None).source |
1533 | 146 |
|
1300 | 147 |
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
|
148 |
rset = self.execute('CWUser X') |
1300 | 149 |
self.view('edition', rset, row=0, template=None).source |
1533 | 150 |
|
1300 | 151 |
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
|
152 |
rset = self.execute('CWUser X') |
1300 | 153 |
self.view('copy', rset, row=0, template=None).source |
1533 | 154 |
|
1300 | 155 |
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
|
156 |
self.view('creation', None, etype='CWUser', template=None).source |
1533 | 157 |
|
1300 | 158 |
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
|
159 |
rset = self.execute('CWUser X') |
1300 | 160 |
self.view('muledit', rset, template=None).source |
1533 | 161 |
|
1300 | 162 |
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
|
163 |
rset = self.execute('CWUser X') |
1300 | 164 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
1533 | 165 |
|
1300 | 166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
pform=MOCKPFORM).source |
1533 | 172 |
|
1300 | 173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
pform=MOCKPFORM).source |
1300 | 178 |
|
3930
c0ae3148b893
fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
179 |
MOCKPFORM = mock_object(form_previous_values={}, form_valerror=None) |
1533 | 180 |
|
1287 | 181 |
if __name__ == '__main__': |
182 |
unittest_main() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
183 |