author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 21 Oct 2009 17:32:20 +0200 | |
changeset 3777 | 3ef8cdb5fb1c |
parent 3722 | c414f402cbff |
parent 3771 | 234b003f0fe0 |
child 3998 | 94cc7cad3d2d |
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 |
""" |
1287 | 8 |
from logilab.common.testlib import unittest_main |
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 |
1654 | 12 |
from cubicweb.web.views.autoform import AutomaticEntityForm as AEF |
1359 | 13 |
from cubicweb.web.formwidgets import AutoCompletionWidget |
3722 | 14 |
|
1287 | 15 |
def rbc(entity, category): |
16 |
return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
|
17 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
18 |
class AutomaticEntityFormTC(CubicWebTC): |
1287 | 19 |
|
1359 | 20 |
def test_custom_widget(self): |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
21 |
AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'), |
2643
9976f511003b
web test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
22 |
{'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
|
23 |
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
|
24 |
entity=self.user()) |
1359 | 25 |
field = form.field_by_name('login') |
26 |
self.assertIsInstance(field.widget, AutoCompletionWidget) |
|
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
27 |
AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject') |
1533 | 28 |
|
1359 | 29 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
30 |
def test_cwuser_relations_by_category(self): |
1287 | 31 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
32 |
# if rtype == 'tags': |
|
33 |
# 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
|
34 |
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
|
35 |
# see custom configuration in views.cwuser |
1287 | 36 |
self.assertEquals(rbc(e, 'primary'), |
37 |
[('login', 'subject'), |
|
38 |
('upassword', 'subject'), |
|
39 |
('in_group', 'subject'), |
|
40 |
('eid', 'subject'), |
|
41 |
]) |
|
42 |
self.assertListEquals(rbc(e, 'secondary'), |
|
43 |
[('firstname', 'subject'), |
|
44 |
('surname', 'subject') |
|
45 |
]) |
|
46 |
self.assertListEquals(rbc(e, 'metadata'), |
|
47 |
[('last_login_time', 'subject'), |
|
3771 | 48 |
('modification_date', 'subject'), |
1287 | 49 |
('created_by', 'subject'), |
50 |
('creation_date', 'subject'), |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
51 |
('cwuri', 'subject'), |
1287 | 52 |
('owned_by', 'subject'), |
53 |
('bookmarked_by', 'object'), |
|
1533 | 54 |
]) |
1287 | 55 |
self.assertListEquals(rbc(e, 'generic'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
56 |
[('primary_email', 'subject'), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
57 |
('custom_workflow', 'subject'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
58 |
('connait', 'subject'), |
1287 | 59 |
('checked_by', 'object'), |
60 |
]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
61 |
# owned_by is defined both as subject and object relations on CWUser |
1287 | 62 |
self.assertListEquals(rbc(e, 'generated'), |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
63 |
[('use_email', 'subject'), |
3587 | 64 |
('in_state', 'subject'), |
3771 | 65 |
('is', 'subject'), |
66 |
('is_instance_of', 'subject'), |
|
1654 | 67 |
('has_text', 'subject'), |
1300 | 68 |
('identity', 'subject'), |
1287 | 69 |
('tags', 'object'), |
70 |
('for_user', 'object'), |
|
71 |
('created_by', 'object'), |
|
72 |
('wf_info_for', 'object'), |
|
73 |
('owned_by', 'object'), |
|
1300 | 74 |
('identity', 'object'), |
1287 | 75 |
]) |
1298 | 76 |
|
77 |
def test_inlined_view(self): |
|
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1533
diff
changeset
|
78 |
self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject')) |
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1533
diff
changeset
|
79 |
self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject')) |
1533 | 80 |
|
1287 | 81 |
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
|
82 |
e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
1287 | 83 |
self.assertListEquals(rbc(e, 'primary'), |
84 |
[('nom', 'subject'), |
|
85 |
('eid', 'subject') |
|
86 |
]) |
|
87 |
self.assertListEquals(rbc(e, 'secondary'), |
|
88 |
[('prenom', 'subject'), |
|
89 |
('sexe', 'subject'), |
|
90 |
('promo', 'subject'), |
|
91 |
('titre', 'subject'), |
|
92 |
('ass', 'subject'), |
|
93 |
('web', 'subject'), |
|
94 |
('tel', 'subject'), |
|
95 |
('fax', 'subject'), |
|
96 |
('datenaiss', 'subject'), |
|
97 |
('test', 'subject'), |
|
98 |
('description', 'subject'), |
|
99 |
('salary', 'subject') |
|
100 |
]) |
|
101 |
self.assertListEquals(rbc(e, 'metadata'), |
|
3771 | 102 |
[('creation_date', 'subject'), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
103 |
('cwuri', 'subject'), |
1287 | 104 |
('modification_date', 'subject'), |
3771 | 105 |
('created_by', 'subject'), |
1287 | 106 |
('owned_by', 'subject'), |
1533 | 107 |
]) |
1287 | 108 |
self.assertListEquals(rbc(e, 'generic'), |
109 |
[('travaille', 'subject'), |
|
110 |
('connait', 'object') |
|
111 |
]) |
|
112 |
self.assertListEquals(rbc(e, 'generated'), |
|
3771 | 113 |
[('is', 'subject'), |
114 |
('has_text', 'subject'), |
|
1300 | 115 |
('identity', 'subject'), |
1287 | 116 |
('is_instance_of', 'subject'), |
1300 | 117 |
('identity', 'object'), |
1287 | 118 |
]) |
1533 | 119 |
|
1300 | 120 |
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
|
121 |
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
|
122 |
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
|
123 |
row=0, col=0) |
1300 | 124 |
# 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
|
125 |
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
|
126 |
entity=rset.get_entity(0, 0)) |
1300 | 127 |
self.failIf(any(f for f in form.fields if f is None)) |
1533 | 128 |
|
129 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
130 |
class FormViewsTC(CubicWebTC): |
1300 | 131 |
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
|
132 |
rset = self.execute('CWGroup X') |
1300 | 133 |
self.view('deleteconf', rset, template=None).source |
1533 | 134 |
|
1300 | 135 |
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
|
136 |
rset = self.execute('CWUser X') |
1300 | 137 |
self.view('edition', rset, row=0, template=None).source |
1533 | 138 |
|
1300 | 139 |
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
|
140 |
rset = self.execute('CWUser X') |
1300 | 141 |
self.view('copy', rset, row=0, template=None).source |
1533 | 142 |
|
1300 | 143 |
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
|
144 |
self.view('creation', None, etype='CWUser', template=None).source |
1533 | 145 |
|
1300 | 146 |
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
|
147 |
rset = self.execute('CWUser X') |
1300 | 148 |
self.view('muledit', rset, template=None).source |
1533 | 149 |
|
1300 | 150 |
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
|
151 |
rset = self.execute('CWUser X') |
1300 | 152 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
1533 | 153 |
|
1300 | 154 |
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
|
155 |
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
|
156 |
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
|
157 |
self.view('inline-edition', rset, row=0, col=0, rtype='in_group', |
3587 | 158 |
peid=geid, role='object', template=None, i18nctx='').source |
1533 | 159 |
|
1300 | 160 |
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
|
161 |
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
|
162 |
self.view('inline-creation', None, etype='CWUser', rtype='in_group', |
3587 | 163 |
peid=geid, template=None, i18nctx='', role='object').source |
1300 | 164 |
|
1533 | 165 |
|
1287 | 166 |
if __name__ == '__main__': |
167 |
unittest_main() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
168 |