author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 08 Sep 2009 15:30:49 +0200 | |
branch | 3.5 |
changeset 3111 | 7b405bb305ab |
parent 2920 | 64322aa83a1d |
child 2968 | 0e3460341023 |
child 3361 | be0605689fed |
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 |
9 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
1300 | 10 |
from cubicweb.devtools.testlib import WebTest |
1654 | 11 |
from cubicweb.web.views.autoform import AutomaticEntityForm as AEF |
1359 | 12 |
from cubicweb.web.formwidgets import AutoCompletionWidget |
1287 | 13 |
def rbc(entity, category): |
14 |
return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
|
15 |
||
16 |
class AutomaticEntityFormTC(EnvBasedTC): |
|
17 |
||
1359 | 18 |
def test_custom_widget(self): |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
19 |
AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'), |
2643
9976f511003b
web test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
20 |
{'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
|
21 |
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
|
22 |
entity=self.user()) |
1359 | 23 |
field = form.field_by_name('login') |
24 |
self.assertIsInstance(field.widget, AutoCompletionWidget) |
|
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1739
diff
changeset
|
25 |
AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject') |
1533 | 26 |
|
1359 | 27 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
28 |
def test_cwuser_relations_by_category(self): |
1287 | 29 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
30 |
# if rtype == 'tags': |
|
31 |
# 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
|
32 |
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
|
33 |
# see custom configuration in views.cwuser |
1287 | 34 |
self.assertEquals(rbc(e, 'primary'), |
35 |
[('login', 'subject'), |
|
36 |
('upassword', 'subject'), |
|
37 |
('in_group', 'subject'), |
|
38 |
('in_state', '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'), |
|
47 |
('created_by', 'subject'), |
|
48 |
('creation_date', 'subject'), |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
49 |
('cwuri', 'subject'), |
1287 | 50 |
('modification_date', 'subject'), |
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'), |
1654 | 63 |
('has_text', 'subject'), |
1300 | 64 |
('identity', 'subject'), |
65 |
('is', 'subject'), |
|
1287 | 66 |
('is_instance_of', 'subject'), |
67 |
('tags', 'object'), |
|
68 |
('for_user', 'object'), |
|
69 |
('created_by', 'object'), |
|
70 |
('wf_info_for', 'object'), |
|
71 |
('owned_by', 'object'), |
|
1300 | 72 |
('identity', 'object'), |
1287 | 73 |
]) |
1298 | 74 |
|
75 |
def test_inlined_view(self): |
|
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1533
diff
changeset
|
76 |
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
|
77 |
self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject')) |
1533 | 78 |
|
1287 | 79 |
def test_personne_relations_by_category(self): |
80 |
e = self.etype_instance('Personne') |
|
81 |
self.assertListEquals(rbc(e, 'primary'), |
|
82 |
[('nom', 'subject'), |
|
83 |
('eid', 'subject') |
|
84 |
]) |
|
85 |
self.assertListEquals(rbc(e, 'secondary'), |
|
86 |
[('prenom', 'subject'), |
|
87 |
('sexe', 'subject'), |
|
88 |
('promo', 'subject'), |
|
89 |
('titre', 'subject'), |
|
90 |
('ass', 'subject'), |
|
91 |
('web', 'subject'), |
|
92 |
('tel', 'subject'), |
|
93 |
('fax', 'subject'), |
|
94 |
('datenaiss', 'subject'), |
|
95 |
('test', 'subject'), |
|
96 |
('description', 'subject'), |
|
97 |
('salary', 'subject') |
|
98 |
]) |
|
99 |
self.assertListEquals(rbc(e, 'metadata'), |
|
100 |
[('created_by', 'subject'), |
|
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'), |
104 |
('owned_by', 'subject'), |
|
1533 | 105 |
]) |
1287 | 106 |
self.assertListEquals(rbc(e, 'generic'), |
107 |
[('travaille', 'subject'), |
|
108 |
('connait', 'object') |
|
109 |
]) |
|
110 |
self.assertListEquals(rbc(e, 'generated'), |
|
1300 | 111 |
[('has_text', 'subject'), |
112 |
('identity', 'subject'), |
|
113 |
('is', 'subject'), |
|
1287 | 114 |
('is_instance_of', 'subject'), |
1300 | 115 |
('identity', 'object'), |
1287 | 116 |
]) |
1533 | 117 |
|
1300 | 118 |
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
|
119 |
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
|
120 |
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
|
121 |
row=0, col=0) |
1300 | 122 |
# 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
|
123 |
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
|
124 |
entity=rset.get_entity(0, 0)) |
1300 | 125 |
self.failIf(any(f for f in form.fields if f is None)) |
1533 | 126 |
|
127 |
||
1300 | 128 |
class FormViewsTC(WebTest): |
129 |
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
|
130 |
rset = self.execute('CWGroup X') |
1300 | 131 |
self.view('deleteconf', rset, template=None).source |
1533 | 132 |
|
1300 | 133 |
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
|
134 |
rset = self.execute('CWUser X') |
1300 | 135 |
self.view('edition', rset, row=0, 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('copy', rset, row=0, template=None).source |
1533 | 140 |
|
1300 | 141 |
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
|
142 |
self.view('creation', None, etype='CWUser', template=None).source |
1533 | 143 |
|
1300 | 144 |
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
|
145 |
rset = self.execute('CWUser X') |
1300 | 146 |
self.view('muledit', rset, template=None).source |
1533 | 147 |
|
1300 | 148 |
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
|
149 |
rset = self.execute('CWUser X') |
1300 | 150 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
1533 | 151 |
|
1300 | 152 |
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
|
153 |
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
|
154 |
rset = self.execute('CWUser X LIMIT 1') |
1300 | 155 |
self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source |
1533 | 156 |
|
1300 | 157 |
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
|
158 |
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
|
159 |
self.view('inline-creation', None, etype='CWUser', rtype='in_group', peid=geid, template=None).source |
1300 | 160 |
|
1533 | 161 |
|
1287 | 162 |
if __name__ == '__main__': |
163 |
unittest_main() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
164 |