[Checkins] SVN: z3c.form/trunk/src/z3c/form/testing.txt added unit tests for file upload widget conversion

Roy Mathew roymath at yahoo.com
Mon Sep 29 14:40:03 EDT 2008


Log message for revision 91625:
  added unit tests for file upload widget conversion

Changed:
  A   z3c.form/trunk/src/z3c/form/testing.txt

-=-
Added: z3c.form/trunk/src/z3c/form/testing.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/testing.txt	                        (rev 0)
+++ z3c.form/trunk/src/z3c/form/testing.txt	2008-09-29 18:40:03 UTC (rev 91625)
@@ -0,0 +1,43 @@
+===============
+Testing support
+===============
+
+Data Converter for Testing
+--------------------------
+
+Sometimes, we want to upload binary files. Particulary in Selenium
+tests, it is nearly impossible to correctly input binary data - so we
+allow the user to specify base64 encoded data to be uploaded. This
+is accomplished by using a hidden input field that holds the value
+of the encoding desired.
+
+  >>> import zope.schema
+  >>> from z3c.form import widget
+  >>> from z3c.form import testing
+
+As in converter.txt, we want to test a file upload widget.
+
+  >>> filedata = zope.schema.Text(
+  ...     __name__='data',
+  ...     title=u'Some data to upload',)
+
+Lets try passing a simple string, and not specify any encoding.
+
+  >>> dataWidget = widget.Widget(testing.TestRequest(
+  ...    form={'data.testing': 'haha'}))
+  >>> dataWidget.name = 'data'
+
+  >>> conv = testing.TestingFileUploadDataConverter(filedata, dataWidget)
+  >>> conv.toFieldValue('')
+  'haha'
+
+And now, specify a encoded string
+
+  >>> encStr = 'hoohoo'.encode('base64')
+  >>> dataWidget = widget.Widget(testing.TestRequest(
+  ...    form={'data.testing': encStr, 'data.encoding': 'base64'}))
+  >>> dataWidget.name = 'data'
+
+  >>> conv = testing.TestingFileUploadDataConverter(filedata, dataWidget)
+  >>> conv.toFieldValue('')
+  'hoohoo'



More information about the Checkins mailing list