vendor/Five/1.2b-r20590

view form/tests/forms.txt @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 Testing forms
2 =============
4 Before we can begin, we need to set up a few things. We need a
5 manager account:
7 >>> uf = self.folder.acl_users
8 >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
10 We need to configure all of Five for the functional test:
12 >>> import Products.Five.form.tests
13 >>> from Products.Five import zcml
14 >>> zcml.load_config('configure.zcml', package=Products.Five)
15 >>> zcml.load_config('configure.zcml', package=Products.Five.form.tests)
17 Finally, we need to setup a traversable folder. Otherwise, Five won't
18 get to to do its view lookup:
20 >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
21 >>> manage_addFiveTraversableFolder(self.folder, 'ftf')
24 Add forms
25 ---------
27 We can add objects to containers (object managers) through add forms.
28 An unprotected form can be accessed with anonymously:
30 >>> print http(r"""
31 ... GET /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
32 ... """, handle_errors=False)
33 HTTP/1.1 200 OK
34 ...
36 For a protected one we need a manager account:
38 >>> print http(r"""
39 ... GET /test_folder_1_/ftf/+/protectedaddform.html HTTP/1.1
40 ... Authorization: Basic manager:r00t
41 ... """, handle_errors=False)
42 HTTP/1.1 200 OK
43 ...
45 otherwise we will fail to access it (N.B: this test will fail on Zope 2.8.1,
46 which incorrectly ignored its 'handle_errors' argument):
48 >>> print http(r"""
49 ... GET /test_folder_1_/ftf/+/protectedaddform.html HTTP/1.1
50 ... """, handle_errors=False)
51 Traceback (most recent call last):
52 ...
53 Unauthorized: ...
55 Now let's add a piece of our sample content object to test more things
56 on it:
58 >>> print http(r"""
59 ... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
60 ... Authorization: Basic manager:r00t
61 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
62 ... Content-Length: 527
63 ...
64 ... -----------------------------968064918930967154199105236
65 ... Content-Disposition: form-data; name="field.title"
66 ...
67 ... title
68 ... -----------------------------968064918930967154199105236
69 ... Content-Disposition: form-data; name="field.description"
70 ...
71 ...
72 ... -----------------------------968064918930967154199105236
73 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
74 ...
75 ... Add
76 ... -----------------------------968064918930967154199105236
77 ... Content-Disposition: form-data; name="add_input_name"
78 ...
79 ... edittest
80 ... -----------------------------968064918930967154199105236--
81 ... """, handle_errors=False)
82 HTTP/1.1 302 Moved Temporarily
83 ...
84 Location: http://localhost/test_folder_1_/ftf/manage_main
85 ...
87 Having added this piece of content, we can access it under its URL:
89 >>> print http(r"""
90 ... GET /test_folder_1_/ftf/edittest HTTP/1.1
91 ... """, handle_errors=False)
92 HTTP/1.1 200 OK
93 ...
95 We can also verify that the title was set correctly, and the not
96 specified attribute is the default value:
98 >>> edittest = self.folder.ftf.edittest
99 >>> edittest.title
100 u'title'
101 >>> edittest.description #XXX shouldn't we get a u'' here???
104 Edit forms
105 ----------
107 First, it's important to note that forms validate user input.
108 Therefore, if we specify invalid data, our object won't change:
110 >>> print http(r"""
111 ... POST /test_folder_1_/ftf/edittest/@@edit.html HTTP/1.1
112 ... Authorization: Basic manager:r00t
113 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
114 ... Content-Length: 418
115 ...
116 ... -----------------------------968064918930967154199105236
117 ... Content-Disposition: form-data; name="field.title"
118 ...
119 ...
120 ... -----------------------------968064918930967154199105236
121 ... Content-Disposition: form-data; name="field.description"
122 ...
123 ... BarDescription
124 ... -----------------------------968064918930967154199105236
125 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
126 ...
127 ... Change
128 ... -----------------------------968064918930967154199105236--
129 ... """, handle_errors=False)
130 HTTP/1.1 200 OK
131 ...
132 There are <strong>1</strong> input errors.
133 ...
135 We will see that nothing has changed:
137 >>> edittest.title
138 u'title'
139 >>> edittest.description #XXX shouldn't we get a u'' here???
141 However, when we specify the correct fields:
143 >>> print http(r"""
144 ... POST /test_folder_1_/ftf/edittest/@@edit.html HTTP/1.1
145 ... Authorization: Basic manager:r00t
146 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
147 ... Content-Length: 426
148 ...
149 ... -----------------------------968064918930967154199105236
150 ... Content-Disposition: form-data; name="field.title"
151 ...
152 ... FooTitle
153 ... -----------------------------968064918930967154199105236
154 ... Content-Disposition: form-data; name="field.description"
155 ...
156 ... FooDescription
157 ... -----------------------------968064918930967154199105236
158 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
159 ...
160 ... Change
161 ... -----------------------------968064918930967154199105236--
162 ... """, handle_errors=False)
163 HTTP/1.1 200 OK
164 ...
166 We will see that nothing has changed:
168 >>> edittest.title
169 u'FooTitle'
170 >>> edittest.description
171 u'FooDescription'
174 Unicode-safety of forms
175 -----------------------
177 Even though ZPublisher does not support unicode, automatically
178 generated forms do. In the following we will enter the following two
179 chinese sequences (How do you do? and I'm doing good) in forms
180 (they're encoded in UTF-8 here):
182 >>> ni_hao = '\xe4\xbd\xa0\xe5\xa5\xbd'
183 >>> wo_hen_hao = '\346\210\221\345\276\210\345\245\275'
185 First, it's imaginable that we make a mistake and enter one of the
186 phrases in the integer field:
188 >>> print http(r"""
189 ... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
190 ... Authorization: Basic manager:r00t
191 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
192 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
193 ... Content-Length: 418
194 ...
195 ... -----------------------------968064918930967154199105236
196 ... Content-Disposition: form-data; name="field.title"
197 ...
198 ... ChineseTitle
199 ... -----------------------------968064918930967154199105236
200 ... Content-Disposition: form-data; name="field.description"
201 ...
202 ... ChineseDescription
203 ... -----------------------------968064918930967154199105236
204 ... Content-Disposition: form-data; name="field.somenumber"
205 ...
206 ... %s
207 ... -----------------------------968064918930967154199105236
208 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
209 ...
210 ... Add
211 ... -----------------------------968064918930967154199105236
212 ... Content-Disposition: form-data; name="add_input_name"
213 ...
214 ... unicodetest
215 ... -----------------------------968064918930967154199105236--
216 ... """ % ni_hao, handle_errors=False)
217 HTTP/1.1 200 OK
218 ...
219 There are <strong>1</strong> input errors.
220 ...
222 When we enter the unicode data in the right fields (the text fields),
223 the form will submit correctly and create the object:
225 >>> print http(r"""
226 ... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
227 ... Authorization: Basic manager:r00t
228 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
229 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
230 ... Content-Length: 418
231 ...
232 ... -----------------------------968064918930967154199105236
233 ... Content-Disposition: form-data; name="field.title"
234 ...
235 ... %s
236 ... -----------------------------968064918930967154199105236
237 ... Content-Disposition: form-data; name="field.description"
238 ...
239 ... %s
240 ... -----------------------------968064918930967154199105236
241 ... Content-Disposition: form-data; name="field.somenumber"
242 ...
243 ... 0
244 ... -----------------------------968064918930967154199105236
245 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
246 ...
247 ... Add
248 ... -----------------------------968064918930967154199105236
249 ... Content-Disposition: form-data; name="add_input_name"
250 ...
251 ... unicodetest
252 ... -----------------------------968064918930967154199105236--
253 ... """ % (ni_hao, wo_hen_hao), handle_errors=False)
254 HTTP/1.1 302 Moved Temporarily
255 ...
256 Location: http://localhost/test_folder_1_/ftf/manage_main
257 ...
259 We can test the object has the correct values, as unicode strings, of
260 course:
262 >>> unicodetest = self.folder.ftf.unicodetest
263 >>> unicodetest.title == ni_hao.decode('utf-8')
264 True
265 >>> unicodetest.description == wo_hen_hao.decode('utf-8')
266 True
267 >>> unicodetest.somenumber
268 0
270 Of course, the same should apply to edit forms. First, we happen to
271 again make the mistake of entering unicode data in the integer field:
273 >>> print http(r"""
274 ... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
275 ... Authorization: Basic manager:r00t
276 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
277 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
278 ... Content-Length: 418
279 ...
280 ... -----------------------------968064918930967154199105236
281 ... Content-Disposition: form-data; name="field.title"
282 ...
283 ... ChineseTitle
284 ... -----------------------------968064918930967154199105236
285 ... Content-Disposition: form-data; name="field.description"
286 ...
287 ... ChineseDescription
288 ... -----------------------------968064918930967154199105236
289 ... Content-Disposition: form-data; name="field.somenumber"
290 ...
291 ... %s
292 ... -----------------------------968064918930967154199105236
293 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
294 ...
295 ... Change
296 ... -----------------------------968064918930967154199105236--
297 ... """ % ni_hao, handle_errors=False)
298 HTTP/1.1 200 OK
299 ...
300 There are <strong>1</strong> input errors.
301 ...
303 We see that the object hasn't changed:
305 >>> unicodetest.title == ni_hao.decode('utf-8')
306 True
307 >>> unicodetest.description == wo_hen_hao.decode('utf-8')
308 True
309 >>> unicodetest.somenumber
310 0
312 Now we provide some valid form data:
314 >>> print http(r"""
315 ... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
316 ... Authorization: Basic manager:r00t
317 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
318 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
319 ... Content-Length: 418
320 ...
321 ... -----------------------------968064918930967154199105236
322 ... Content-Disposition: form-data; name="field.title"
323 ...
324 ... %s
325 ... -----------------------------968064918930967154199105236
326 ... Content-Disposition: form-data; name="field.description"
327 ...
328 ... %s
329 ... -----------------------------968064918930967154199105236
330 ... Content-Disposition: form-data; name="field.somenumber"
331 ...
332 ... 1
333 ... -----------------------------968064918930967154199105236
334 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
335 ...
336 ... Change
337 ... -----------------------------968064918930967154199105236--
338 ... """ % (wo_hen_hao, ni_hao), handle_errors=False)
339 HTTP/1.1 200 OK
340 ...
342 We see that the object's data has changed:
344 >>> unicodetest.title == wo_hen_hao.decode('utf-8')
345 True
346 >>> unicodetest.description == ni_hao.decode('utf-8')
347 True
348 >>> unicodetest.somenumber
349 1
351 Let's also not forget about List widgets. Let's see if we can add an
352 element to the list:
354 >>> print http(r"""
355 ... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
356 ... Authorization: Basic manager:r00t
357 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
358 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
359 ... Content-Length: 418
360 ...
361 ... -----------------------------968064918930967154199105236
362 ... Content-Disposition: form-data; name="field.title"
363 ...
364 ... %s
365 ... -----------------------------968064918930967154199105236
366 ... Content-Disposition: form-data; name="field.description"
367 ...
368 ... %s
369 ... -----------------------------968064918930967154199105236
370 ... Content-Disposition: form-data; name="field.somenumber"
371 ...
372 ... 1
373 ... -----------------------------968064918930967154199105236
374 ... Content-Disposition: form-data; name="field.somelist.add"
375 ...
376 ... Add
377 ... -----------------------------968064918930967154199105236--
378 ... """ % (wo_hen_hao, ni_hao), handle_errors=False)
379 HTTP/1.1 200 OK
380 ...
381 ...<input class="textType" id="field.somelist.0." name="field.somelist.0." size="20" type="text" value="" />...
382 ...
384 Now, let's enter some more Chinese:
386 >>> de_guo = '\345\276\267\345\233\275'
388 >>> print http(r"""
389 ... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
390 ... Authorization: Basic manager:r00t
391 ... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
392 ... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
393 ... Content-Length: 418
394 ...
395 ... -----------------------------968064918930967154199105236
396 ... Content-Disposition: form-data; name="field.title"
397 ...
398 ... %s
399 ... -----------------------------968064918930967154199105236
400 ... Content-Disposition: form-data; name="field.description"
401 ...
402 ... %s
403 ... -----------------------------968064918930967154199105236
404 ... Content-Disposition: form-data; name="field.somenumber"
405 ...
406 ... 1
407 ... -----------------------------968064918930967154199105236
408 ... Content-Disposition: form-data; name="field.somelist.0."
409 ...
410 ... %s
411 ... -----------------------------968064918930967154199105236
412 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
413 ...
414 ... Change
415 ... -----------------------------968064918930967154199105236--
416 ... """ % (wo_hen_hao, ni_hao, de_guo), handle_errors=False)
417 HTTP/1.1 200 OK
418 ...
420 The object's data will have changed accordingly:
422 >>> unicodetest.somelist == [de_guo.decode('utf-8')]
423 True
426 Object widget:
427 --------------
429 A little more complex is the ``ObjectWidget``. Here we simply test
430 that the edit form works:
432 >>> from Products.Five.form.tests.schemacontent import \
433 ... manage_addComplexSchemaContent
434 >>> n = manage_addComplexSchemaContent(self.folder.ftf, 'objecttest')
436 >>> print http(r"""
437 ... GET /test_folder_1_/ftf/objecttest/@@edit.html HTTP/1.1
438 ... """, handle_errors=False)
439 HTTP/1.1 200 OK
440 ...
443 i18n:
444 -----
446 And now the add form in German:
448 >>> print http(r"""
449 ... GET /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
450 ... Accept-Language: de
451 ... Authorization: Basic manager:r00t
452 ... """, handle_errors=False)
453 HTTP/1.1 200 OK
454 ...Felderinhalt hinzuf...
455 ...Eine kurz...Titel...
456 ...Eine ausf...Beschreibung...
457 ...Irgendeine Zahl...
458 ...Irgendeine Liste...
459 ...hinzuf...
460 ...Auffrischen...
461 ...Hinzuf...
462 ...Objektname...
464 The same with an input error:
466 >>> print http(r"""
467 ... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
468 ... Accept-Language: de
469 ... Authorization: Basic manager:r00t
470 ... Content-Length: 670
471 ... Content-Type: multipart/form-data; boundary=---------------------------19588947601368617292863650127
472 ...
473 ... -----------------------------19588947601368617292863650127
474 ... Content-Disposition: form-data; name="field.title"
475 ...
476 ...
477 ... -----------------------------19588947601368617292863650127
478 ... Content-Disposition: form-data; name="field.description"
479 ...
480 ...
481 ... -----------------------------19588947601368617292863650127
482 ... Content-Disposition: form-data; name="field.somenumber"
483 ...
484 ... 0
485 ... -----------------------------19588947601368617292863650127
486 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
487 ...
488 ... Hinzufxgen
489 ... -----------------------------19588947601368617292863650127
490 ... Content-Disposition: form-data; name="add_input_name"
491 ...
492 ...
493 ... -----------------------------19588947601368617292863650127--
494 ... """, handle_errors=False)
495 HTTP/1.1 200 OK
496 ...Felderinhalt hinzuf...
497 ...Ein Fehler ist aufgetreten...
498 ...Es gab <strong>1</strong> Eingabefehler...
499 ...Eine kurz...Titel...
500 ...Erforderliche Eingabe fehlt...
501 ...Eine ausf...Beschreibung...
502 ...Irgendeine Zahl...
503 ...Irgendeine Liste...
504 ...hinzuf...
505 ...Auffrischen...
506 ...Hinzuf...
507 ...Objektname...
509 And now the translated edit form:
511 >>> from Products.Five.form.tests.schemacontent import \
512 ... manage_addFieldContent
513 >>> dummy = manage_addFieldContent(self.folder.ftf, 'i18ntest', 'titel')
515 >>> print http(r"""
516 ... GET /test_folder_1_/ftf/i18ntest/edit.html HTTP/1.1
517 ... Accept-Language: de
518 ... Authorization: Basic manager:r00t
519 ... """, handle_errors=False)
520 HTTP/1.1 200 OK
521 ...Felderinhalt bearbeiten...
522 ...Eine kurz...Titel...
523 ...Eine ausf...Beschreibung...
524 ...Irgendeine Zahl...
525 ...Irgendeine Liste...
526 ...hinzuf...
527 ...Auffrischen...
528 ...Abschicken...
530 Again with an input error:
532 >>> print http(r"""
533 ... POST /test_folder_1_/ftf/i18ntest/edit.html HTTP/1.1
534 ... Accept-Language: de
535 ... Authorization: Basic manager:r00t
536 ... Content-Length: 550
537 ... Content-Type: multipart/form-data; boundary=---------------------------13070562555632576681565633754
538 ...
539 ... -----------------------------13070562555632576681565633754
540 ... Content-Disposition: form-data; name="field.title"
541 ...
542 ...
543 ... -----------------------------13070562555632576681565633754
544 ... Content-Disposition: form-data; name="field.description"
545 ...
546 ...
547 ... -----------------------------13070562555632576681565633754
548 ... Content-Disposition: form-data; name="field.somenumber"
549 ...
550 ... 0
551 ... -----------------------------13070562555632576681565633754
552 ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
553 ...
554 ... Abschicken
555 ... -----------------------------13070562555632576681565633754--
556 ... """, handle_errors=False)
557 HTTP/1.1 200 OK
558 ...Felderinhalt bearbeiten...
559 ...Ein Fehler ist aufgetreten...
560 ...Es gab <strong>1</strong> Eingabefehler...
561 ...Eine kurz...Titel...
562 ...Erforderliche Eingabe fehlt...
563 ...Eine ausf...Beschreibung...
564 ...Irgendeine Zahl...
565 ...Irgendeine Liste...
566 ...hinzuf...
567 ...Auffrischen...
568 ...Abschicken...
571 Clean up
572 --------
574 Finally, we need to clean up:
576 >>> from zope.app.tests.placelesssetup import tearDown
577 >>> tearDown()