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