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