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