author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 28 May 2009 18:28:05 +0200 | |
changeset 1983 | 5edd22d0e61a |
parent 1977 | 606923dff11b |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
"""cubicweb.common.widget unit tests |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
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:
1802
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:
1802
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:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
807
diff
changeset
|
9 |
from datetime import datetime |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
807
diff
changeset
|
10 |
NOW = datetime.now() |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
807
diff
changeset
|
11 |
|
0 | 12 |
from logilab.common.testlib import unittest_main |
13 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
14 |
||
806
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
15 |
from cubicweb.common.mttransforms import HAS_TAL |
0 | 16 |
from cubicweb.web.widgets import widget, AutoCompletionWidget |
17 |
||
18 |
||
19 |
class WidgetsTC(EnvBasedTC): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
20 |
|
0 | 21 |
def get_widget(self, etype, rname, rtype): |
22 |
rschema = self.schema[rname] |
|
23 |
return widget(self.vreg, etype, rschema, rtype, role='subject') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
24 |
|
0 | 25 |
|
26 |
def test_hidden_widget(self): |
|
27 |
w = self.get_widget('State', 'eid', 'Int') |
|
28 |
self.assertEquals(w.name, 'eid') |
|
29 |
self.assertEquals(w.render_example(self.request()), '') |
|
30 |
self.assertDictEquals(w.attrs, {}) |
|
31 |
entity = self.etype_instance('State') |
|
32 |
entity.eid = 'X' |
|
33 |
self.assertEquals(w.required(entity), True) |
|
34 |
self.assertEquals(w.render(entity), '') |
|
35 |
self.assertEquals(w.edit_render(entity), |
|
36 |
u'<input type="hidden" name="eid" value="X" />') |
|
37 |
||
38 |
def test_textarea_widget(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
39 |
self.add_entity('CWProperty', pkey=u'ui.fckeditor', value=u'') |
0 | 40 |
self.commit() |
41 |
w = self.get_widget('State', 'description', 'String') |
|
42 |
self.assertEquals(w.name, 'description') |
|
43 |
self.assertEquals(w.render_example(self.request()), '') |
|
44 |
self.assertDictEquals(w.attrs, {'accesskey': 'd'}) |
|
45 |
entity = self.etype_instance('State') |
|
46 |
entity.eid = 'X' |
|
47 |
entity |
|
48 |
self.assertEquals(w.required(entity), False) |
|
49 |
self.assertEquals(w.render(entity), '') |
|
806
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
50 |
if HAS_TAL: |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
51 |
tal_format = u'\n<option value="text/cubicweb-page-template" >text/cubicweb-page-template</option>' |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
52 |
else: |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
53 |
tal_format = u'' |
0 | 54 |
self.assertTextEquals(w.edit_render(entity), |
55 |
u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
|
56 |
<input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
|
57 |
||
58 |
<select name="description_format:X" id="description_format:X" tabindex="0"> |
|
59 |
<option value="text/rest" >text/rest</option> |
|
60 |
<option value="text/html" selected="selected">text/html</option> |
|
806
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
61 |
<option value="text/plain" >text/plain</option>%s |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
62 |
</select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1"></textarea>''' % tal_format) |
0 | 63 |
|
64 |
def test_textarea_widget_previous_value(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
65 |
self.add_entity('CWProperty', pkey=u'ui.fckeditor', value=u'') |
0 | 66 |
self.commit() |
67 |
w = self.get_widget('State', 'description', 'String') |
|
68 |
req = self.request() |
|
69 |
req.data['formvalues'] = {'description:X': 'a description'} |
|
70 |
entity = self.etype_instance('State', req) |
|
71 |
entity.eid = 'X' |
|
72 |
self.assertEquals(w.required(entity), False) |
|
73 |
self.assertEquals(w.render(entity), '') |
|
806
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
74 |
if HAS_TAL: |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
75 |
tal_format = u'\n<option value="text/cubicweb-page-template" >text/cubicweb-page-template</option>' |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
76 |
else: |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
77 |
tal_format = u'' |
0 | 78 |
self.assertTextEquals(w.edit_render(entity), |
79 |
u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
|
80 |
<input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
|
81 |
||
82 |
<select name="description_format:X" id="description_format:X" tabindex="0"> |
|
83 |
<option value="text/rest" >text/rest</option> |
|
84 |
<option value="text/html" selected="selected">text/html</option> |
|
806
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
85 |
<option value="text/plain" >text/plain</option>%s |
a95e7097924a
fix unittest_widgets.py: the cubicweb-page-template format is only available when simpleTAL is found
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
86 |
</select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1">a description</textarea>''' % tal_format) |
0 | 87 |
|
88 |
def test_fckeditor_widget(self): |
|
89 |
w = self.get_widget('State', 'description', 'String') |
|
90 |
req = self.request() |
|
91 |
entity = self.etype_instance('State', req) |
|
92 |
entity.eid = 'X' |
|
93 |
self.assertEquals(w.required(entity), False) |
|
94 |
self.assertEquals(w.render(entity), '') |
|
95 |
self.assertTextEquals(w.edit_render(entity), |
|
96 |
u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
|
97 |
<input type="hidden" name="edits-description_format:X" value=""/> |
|
98 |
<input type="hidden" name="description_format:X" value="text/html"/> |
|
99 |
<textarea cubicweb:type="wysiwyg" onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="0"></textarea>''') |
|
100 |
||
101 |
def test_string_widget(self): |
|
102 |
w = self.get_widget('Personne', 'nom', 'String') |
|
103 |
self.assertEquals(w.name, 'nom') |
|
104 |
self.assertEquals(w.render_example(self.request()), '') |
|
105 |
self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) |
|
106 |
entity = self.etype_instance('Personne') |
|
107 |
entity.eid = 'X' |
|
108 |
self.assertEquals(w.required(entity), True) |
|
109 |
self.assertEquals(w.render(entity), '') |
|
110 |
self.assertEquals(w.edit_render(entity), |
|
111 |
u'<input type="hidden" name="edits-nom:X" value="__cubicweb_internal_field__"/>\n' |
|
112 |
'<input type="text" name="nom:X" value="" accesskey="n" id="nom:X" maxlength="64" size="40" tabindex="0"/>') |
|
113 |
||
114 |
def test_string_widget_previous_value(self): |
|
115 |
w = self.get_widget('Personne', 'nom', 'String') |
|
116 |
self.assertEquals(w.name, 'nom') |
|
117 |
self.assertEquals(w.render_example(self.request()), '') |
|
118 |
self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) |
|
119 |
req = self.request() |
|
120 |
req.data['formvalues'] = {'nom:X': 'a name'} |
|
121 |
entity = self.etype_instance('Personne', req) |
|
122 |
entity.eid = 'X' |
|
123 |
self.assertEquals(w.required(entity), True) |
|
124 |
self.assertEquals(w.render(entity), '') |
|
125 |
self.assertEquals(w.edit_render(entity), |
|
126 |
u'<input type="hidden" name="edits-nom:X" value="__cubicweb_internal_field__"/>\n' |
|
127 |
'<input type="text" name="nom:X" value="a name" accesskey="n" id="nom:X" maxlength="64" size="40" tabindex="0"/>') |
|
128 |
||
129 |
def test_static_combo_widget(self): |
|
130 |
w = self.get_widget('Personne', 'promo', 'String') |
|
131 |
self.assertEquals(w.name, 'promo') |
|
132 |
self.assertEquals(w.render_example(self.request()), '') |
|
133 |
self.assertDictEquals(w.attrs, {}) |
|
134 |
entity = self.etype_instance('Personne') |
|
135 |
entity.eid = 'X' |
|
136 |
self.assertEquals(w.required(entity), False) |
|
137 |
self.assertEquals(w.render(entity), '') |
|
138 |
self.assertTextEquals(w.edit_render(entity), |
|
139 |
u'<input type="hidden" name="edits-promo:X" value="__cubicweb_internal_field__"/>\n\n' |
|
140 |
'<select name="promo:X" id="promo:X" tabindex="0">\n' |
|
141 |
'<option value="bon" >bon</option>\n' |
|
142 |
'<option value="pasbon" >pasbon</option>\n' |
|
143 |
'</select>') |
|
144 |
||
145 |
def test_static_combo_widget_previous_value(self): |
|
146 |
w = self.get_widget('Personne', 'promo', 'String') |
|
147 |
self.assertEquals(w.name, 'promo') |
|
148 |
self.assertEquals(w.render_example(self.request()), '') |
|
149 |
self.assertDictEquals(w.attrs, {}) |
|
150 |
req = self.request() |
|
151 |
req.data['formvalues'] = {'promo:X': 'pasbon'} |
|
152 |
entity = self.etype_instance('Personne', req) |
|
153 |
entity.eid = 'X' |
|
154 |
self.assertEquals(w.required(entity), False) |
|
155 |
self.assertEquals(w.render(entity), '') |
|
156 |
self.assertTextEquals(w.edit_render(entity), |
|
157 |
u'<input type="hidden" name="edits-promo:X" value="__cubicweb_internal_field__"/>\n\n' |
|
158 |
'<select name="promo:X" id="promo:X" tabindex="0">\n' |
|
159 |
'<option value="bon" >bon</option>\n' |
|
160 |
'<option value="pasbon" selected="selected">pasbon</option>\n' |
|
161 |
'</select>') |
|
162 |
||
163 |
def test_integer_widget(self): |
|
164 |
w = self.get_widget('Personne', 'tel', 'Int') |
|
165 |
self.assertEquals(w.name, 'tel') |
|
166 |
self.assertEquals(w.render_example(self.request()), '23') |
|
167 |
self.assertDictEquals(w.attrs, {'accesskey': 't', 'maxlength': 15, 'size': 5}) |
|
168 |
entity = self.etype_instance('Personne') |
|
169 |
entity.eid = 'X' |
|
170 |
self.assertEquals(w.required(entity), False) |
|
171 |
self.assertEquals(w.render(entity), '') |
|
172 |
self.assertEquals(w.edit_render(entity), |
|
173 |
u'<input type="hidden" name="edits-tel:X" value="__cubicweb_internal_field__"/>\n' |
|
174 |
'<input type="text" name="tel:X" value="" accesskey="t" id="tel:X" maxlength="15" size="5" tabindex="0"/>') |
|
175 |
||
176 |
def test_integer_widget_previous_value(self): |
|
177 |
w = self.get_widget('Personne', 'tel', 'Int') |
|
178 |
self.assertEquals(w.name, 'tel') |
|
179 |
self.assertEquals(w.render_example(self.request()), '23') |
|
180 |
self.assertDictEquals(w.attrs, {'accesskey': 't', 'maxlength': 15, 'size': 5}) |
|
181 |
req = self.request() |
|
182 |
req.data['formvalues'] = {'tel:X': '0123456789'} |
|
183 |
entity = self.etype_instance('Personne', req) |
|
184 |
entity.eid = 'X' |
|
185 |
self.assertEquals(w.required(entity), False) |
|
186 |
self.assertEquals(w.render(entity), '') |
|
187 |
self.assertEquals(w.edit_render(entity), |
|
188 |
u'<input type="hidden" name="edits-tel:X" value="__cubicweb_internal_field__"/>\n' |
|
189 |
'<input type="text" name="tel:X" value="0123456789" accesskey="t" id="tel:X" maxlength="15" size="5" tabindex="0"/>') |
|
190 |
||
191 |
def test_datetime_widget(self): |
|
192 |
w = self.get_widget('Personne', 'datenaiss', 'Datetime') |
|
193 |
self.assertEquals(w.name, 'datenaiss') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
194 |
example = '%s, or without time: %s' % ( |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
807
diff
changeset
|
195 |
NOW.strftime(self.vreg.property_value('ui.datetime-format')), |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
807
diff
changeset
|
196 |
NOW.strftime(self.vreg.property_value('ui.date-format'))) |
0 | 197 |
self.assertEquals(w.render_example(self.request()), example) |
198 |
self.assertDictEquals(w.attrs, {'accesskey': 'd', 'maxlength': 16, 'size': 16}) |
|
199 |
entity = self.etype_instance('Personne') |
|
200 |
entity.eid = 'X' |
|
201 |
self.assertEquals(w.required(entity), False) |
|
202 |
self.assertEquals(w.render(entity), '') |
|
203 |
self.assertEquals(w.edit_render(entity), |
|
204 |
u'<input type="hidden" name="edits-datenaiss:X" value="__cubicweb_internal_field__"/>\n' |
|
205 |
'<input type="text" name="datenaiss:X" value="" accesskey="d" id="datenaiss:X" maxlength="16" size="16" tabindex="0"/>' |
|
206 |
'<a onclick="toggleCalendar(\'datenaiss:Xhelper\', \'datenaiss:X\', %s, %s);" class="calhelper">\n<img src="http://testing.fr/cubicweb/data/calendar.gif" title="calendar" alt="" /></a><div class="calpopup hidden" id="datenaiss:Xhelper"></div>' % (NOW.year, NOW.month)) |
|
207 |
||
208 |
def test_datetime_widget_previous_value(self): |
|
209 |
w = self.get_widget('Personne', 'datenaiss', 'Datetime') |
|
210 |
self.assertEquals(w.name, 'datenaiss') |
|
211 |
self.assertDictEquals(w.attrs, {'accesskey': 'd', 'maxlength': 16, 'size': 16}) |
|
212 |
req = self.request() |
|
213 |
req.data['formvalues'] = {'datenaiss:X': '2000/01/01'} |
|
214 |
entity = self.etype_instance('Personne', req) |
|
215 |
entity.eid = 'X' |
|
216 |
self.assertEquals(w.required(entity), False) |
|
217 |
self.assertEquals(w.render(entity), '') |
|
218 |
self.assertEquals(w.edit_render(entity), |
|
219 |
u'<input type="hidden" name="edits-datenaiss:X" value="__cubicweb_internal_field__"/>\n' |
|
220 |
'<input type="text" name="datenaiss:X" value="2000/01/01" accesskey="d" id="datenaiss:X" maxlength="16" size="16" tabindex="0"/>' |
|
221 |
'<a onclick="toggleCalendar(\'datenaiss:Xhelper\', \'datenaiss:X\', %s, %s);" class="calhelper">\n<img src="http://testing.fr/cubicweb/data/calendar.gif" title="calendar" alt="" /></a><div class="calpopup hidden" id="datenaiss:Xhelper"></div>' % (NOW.year, NOW.month)) |
|
222 |
||
223 |
||
224 |
||
225 |
def test_float_widget(self): |
|
226 |
w = self.get_widget('Personne', 'salary', 'Float') |
|
227 |
self.assertEquals(w.name, 'salary') |
|
807
e3cabbdd172a
fix unittest_widgets.py: remove stupid (copy/paste) now().strftime call
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
806
diff
changeset
|
228 |
format = self.vreg.property_value('ui.float-format') |
0 | 229 |
self.assertEquals(w.render_example(self.request()), format % 1.23) |
230 |
self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) |
|
231 |
entity = self.etype_instance('Personne') |
|
232 |
entity.eid = 'X' |
|
233 |
self.assertEquals(w.required(entity), False) |
|
234 |
self.assertEquals(w.render(entity), '') |
|
235 |
self.assertEquals(w.edit_render(entity), |
|
236 |
u'<input type="hidden" name="edits-salary:X" value="__cubicweb_internal_field__"/>\n' |
|
237 |
'<input type="text" name="salary:X" value="" accesskey="s" id="salary:X" maxlength="15" size="5" tabindex="0"/>') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
238 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
239 |
|
0 | 240 |
def test_float_widget_previous_value(self): |
241 |
w = self.get_widget('Personne', 'salary', 'Float') |
|
242 |
self.assertEquals(w.name, 'salary') |
|
807
e3cabbdd172a
fix unittest_widgets.py: remove stupid (copy/paste) now().strftime call
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
806
diff
changeset
|
243 |
format = self.vreg.property_value('ui.float-format') |
0 | 244 |
self.assertEquals(w.render_example(self.request()), format % 1.23) |
245 |
self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) |
|
246 |
req = self.request() |
|
247 |
req.data['formvalues'] = {'salary:X': 7.89} |
|
248 |
entity = self.etype_instance('Personne', req) |
|
249 |
entity.eid = 'X' |
|
250 |
self.assertEquals(w.required(entity), False) |
|
251 |
self.assertEquals(w.render(entity), '') |
|
252 |
self.assertEquals(w.edit_render(entity), |
|
253 |
u'<input type="hidden" name="edits-salary:X" value="__cubicweb_internal_field__"/>\n' |
|
254 |
'<input type="text" name="salary:X" value="7.89" accesskey="s" id="salary:X" maxlength="15" size="5" tabindex="0"/>') |
|
255 |
||
256 |
||
257 |
def test_bool_widget(self): |
|
258 |
w = self.get_widget('Personne', 'test', 'Boolean') |
|
259 |
self.assertEquals(w.name, 'test') |
|
260 |
self.assertEquals(w.render_example(self.request()), '') |
|
261 |
self.assertDictEquals(w.attrs, {'accesskey': 't'}) |
|
262 |
entity = self.etype_instance('Personne') |
|
263 |
entity.eid = 'X' |
|
264 |
self.assertEquals(w.required(entity), False) |
|
265 |
self.assertEquals(w.render(entity), '') |
|
266 |
self.assertEquals(w.edit_render(entity), |
|
267 |
u'''<input type="hidden" name="edits-test:X" value="__cubicweb_internal_field__"/> |
|
268 |
||
269 |
<input type="radio" name="test:X" value="1" accesskey="t" id="test:X" tabindex="0"/>yes<br/> |
|
270 |
<input type="radio" name="test:X" value="" accesskey="t" tabindex="0" checked="checked"/>no<br/>''') |
|
271 |
||
272 |
def test_bool_widget_previous_value(self): |
|
273 |
w = self.get_widget('Personne', 'test', 'Boolean') |
|
274 |
self.assertEquals(w.name, 'test') |
|
275 |
self.assertEquals(w.render_example(self.request()), '') |
|
276 |
self.assertDictEquals(w.attrs, {'accesskey': 't'}) |
|
277 |
req = self.request() |
|
278 |
req.data['formvalues'] = {'test:X': 'checked'} |
|
279 |
entity = self.etype_instance('Personne', req) |
|
280 |
entity.eid = 'X' |
|
281 |
self.assertEquals(w.required(entity), False) |
|
282 |
self.assertEquals(w.render(entity), '') |
|
283 |
self.assertEquals(w.edit_render(entity), |
|
284 |
u'''<input type="hidden" name="edits-test:X" value="__cubicweb_internal_field__"/> |
|
285 |
||
286 |
<input type="radio" name="test:X" value="1" accesskey="t" id="test:X" tabindex="0" checked="checked"/>yes<br/> |
|
287 |
<input type="radio" name="test:X" value="" accesskey="t" tabindex="0"/>no<br/>''') |
|
288 |
||
289 |
||
290 |
def test_password_widget(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
291 |
w = self.get_widget('CWUser', 'upassword', 'Password') |
0 | 292 |
self.assertEquals(w.name, 'upassword') |
293 |
self.assertEquals(w.render_example(self.request()), '') |
|
294 |
self.assertDictEquals(w.attrs, {'accesskey': 'u'}) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
295 |
entity = self.etype_instance('CWUser') |
0 | 296 |
entity.eid = 'X' |
297 |
self.assertEquals(w.required(entity), True) |
|
298 |
self.assertEquals(w.render(entity), '') |
|
299 |
self.assertEquals(w.edit_render(entity), |
|
300 |
u'<input type="hidden" name="edits-upassword:X" value="__cubicweb_internal_field__"/>\n' |
|
301 |
'<input type="password" name="upassword:X" value="" accesskey="u" id="upassword:X" tabindex="0"/><br/>\n' |
|
302 |
'<input type="password" name="upassword-confirm:X" id="upassword-confirm:X" tabindex="1"/> <span class="emphasis">(confirm password)</span>') |
|
303 |
||
304 |
def test_autocompletion_widget(self): |
|
305 |
entity = self.etype_instance('Personne') |
|
306 |
entity.widgets['nom'] = 'AutoCompletionWidget' |
|
307 |
entity.autocomplete_initfuncs = {'nom' : 'getnames'} |
|
308 |
try: |
|
309 |
w = self.get_widget(entity, 'nom', 'String') |
|
310 |
self.failUnless(isinstance(w, AutoCompletionWidget)) |
|
311 |
self.assertEquals(w.name, 'nom') |
|
312 |
self.assertEquals(w.render_example(self.request()), '') |
|
313 |
self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) |
|
314 |
entity.eid = 'X' |
|
315 |
self.assertEquals(w.required(entity), True) |
|
316 |
self.assertEquals(w.render(entity), '') |
|
317 |
||
318 |
self.assertTextEquals(w.edit_render(entity), |
|
319 |
u'<input type="hidden" name="edits-nom:X" value="__cubicweb_internal_field__"/>\n' |
|
320 |
u'<input type="text" name="nom:X" value="" cubicweb:dataurl="http://testing.fr/cubicweb/json?pageid=None&mode=remote&fname=getnames" class="widget required" id="nom:X" tabindex="0" cubicweb:loadtype="auto" cubicweb:wdgtype="SuggestField" cubicweb:accesskey="n" cubicweb:maxlength="64" cubicweb:size="40" />') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
321 |
|
0 | 322 |
finally: |
323 |
del entity.widgets['nom'] |
|
324 |
||
325 |
||
326 |
def test_autocompletion_widget_previous_value(self): |
|
327 |
req = self.request() |
|
328 |
req.data['formvalues'] = {'nom:X': 'a name'} |
|
329 |
entity = self.etype_instance('Personne', req) |
|
330 |
entity.widgets['nom'] = 'AutoCompletionWidget' |
|
331 |
entity.autocomplete_initfuncs = {'nom' : 'getnames'} |
|
332 |
try: |
|
333 |
w = self.get_widget(entity, 'nom', 'String') |
|
334 |
self.failUnless(isinstance(w, AutoCompletionWidget)) |
|
335 |
self.assertEquals(w.name, 'nom') |
|
336 |
self.assertEquals(w.render_example(self.request()), '') |
|
337 |
self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) |
|
338 |
entity.eid = 'X' |
|
339 |
self.assertEquals(w.required(entity), True) |
|
340 |
self.assertEquals(w.render(entity), '') |
|
341 |
self.assertTextEquals(w.edit_render(entity), |
|
342 |
u'<input type="hidden" name="edits-nom:X" value="__cubicweb_internal_field__"/>\n' |
|
343 |
u'<input type="text" name="nom:X" value="a name" cubicweb:dataurl="http://testing.fr/cubicweb/json?pageid=None&mode=remote&fname=getnames" class="widget required" id="nom:X" tabindex="0" cubicweb:loadtype="auto" cubicweb:wdgtype="SuggestField" cubicweb:accesskey="n" cubicweb:maxlength="64" cubicweb:size="40" />') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
344 |
|
0 | 345 |
finally: |
346 |
del entity.widgets['nom'] |
|
347 |
||
348 |
||
349 |
def test_nonregr_float_widget_with_none(self): |
|
350 |
w = self.get_widget('Personne', 'salary', 'Float') |
|
351 |
self.assertEquals(w.name, 'salary') |
|
807
e3cabbdd172a
fix unittest_widgets.py: remove stupid (copy/paste) now().strftime call
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
806
diff
changeset
|
352 |
format = self.vreg.property_value('ui.float-format') |
0 | 353 |
self.assertEquals(w.render_example(self.request()), format % 1.23) |
354 |
self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) |
|
355 |
req = self.request() |
|
356 |
entity = self.etype_instance('Personne', req) |
|
357 |
entity.eid = 'X' |
|
358 |
entity.salary = None |
|
359 |
self.assertEquals(w.required(entity), False) |
|
360 |
self.assertEquals(w.render(entity), '') |
|
361 |
self.assertEquals(w.edit_render(entity), |
|
362 |
u'<input type="hidden" name="edits-salary:X" value="__cubicweb_internal_field__"/>\n' |
|
363 |
'<input type="text" name="salary:X" value="" accesskey="s" id="salary:X" maxlength="15" size="5" tabindex="0"/>') |
|
364 |
||
365 |
||
366 |
def test_custom_widget_for_non_final_relation(self): |
|
367 |
entity = self.etype_instance('Personne', self.request()) |
|
368 |
entity.widgets['travaille'] = 'AutoCompletionWidget' |
|
369 |
entity.autocomplete_initfuncs = {'nom' : 'getnames'} |
|
370 |
w = self.get_widget(entity, 'travaille', 'Societe') |
|
371 |
self.failUnless(isinstance(w, AutoCompletionWidget)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
372 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
373 |
|
0 | 374 |
if __name__ == '__main__': |
375 |
unittest_main() |