[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ convenience
function for writing POST requests in functional doctests;
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Apr 22 12:50:34 EDT 2005
Log message for revision 30109:
convenience function for writing POST requests in functional doctests;
one test has been converted to serve as a demonstration and test
Changed:
U Zope3/trunk/src/zope/app/demo/widget/help/textareawidget.txt
U Zope3/trunk/src/zope/app/testing/functional.py
-=-
Modified: Zope3/trunk/src/zope/app/demo/widget/help/textareawidget.txt
===================================================================
--- Zope3/trunk/src/zope/app/demo/widget/help/textareawidget.txt 2005-04-22 16:21:14 UTC (rev 30108)
+++ Zope3/trunk/src/zope/app/demo/widget/help/textareawidget.txt 2005-04-22 16:50:28 UTC (rev 30109)
@@ -136,50 +136,18 @@
Add a TextWidget using the addform::
- >>> print http(r"""
+ >>> print post(r"""
... POST /widgets/+/addDemoTextAreaWidget.html%3D HTTP/1.1
... Authorization: Basic mgr:mgrpw
- ... Content-Type: multipart/form-data; boundary=---------------------------7d5ae0c0aea
- ... Referer: http://localhost:8081/widgets/+/addDemoTextAreaWidget.html=
- ...
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.standard"
- ...
- ... textarea
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.required"
- ...
- ... textarea
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.constraint"
- ...
- ... constraint
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.default"
- ...
- ... default
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.min_length"
- ...
- ... abcdef
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.max_length"
- ...
- ... abcdef
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="field.min_max"
- ...
- ... abcdef
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
- ...
- ... Add
- ... -----------------------------7d5ae0c0aea
- ... Content-Disposition: form-data; name="add_input_name"
- ...
- ... textarea
- ... -----------------------------7d5ae0c0aea--
- ... """)
+ ... """, {"field.standard": "textarea",
+ ... "field.required": "textarea",
+ ... "field.constraint": "constraint",
+ ... "field.default": "default",
+ ... "field.min_length": "abcdef",
+ ... "field.max_length": "abcdef",
+ ... "field.min_max": "abcdef",
+ ... "UPDATE_SUBMIT": "Add",
+ ... "add_input_name": "textarea"})
HTTP/1.1 303 See Other
...
<div class="row">
@@ -289,4 +257,4 @@
title="zope.schema.Text field with min_lenght = 5 and max_length = 10">min_max</label>
</div>
<div class="field"><textarea cols="60" id="field.min_max" name="field.min_max" rows="15" >abcdef</textarea></div>
- </div...
\ No newline at end of file
+ </div...
Modified: Zope3/trunk/src/zope/app/testing/functional.py
===================================================================
--- Zope3/trunk/src/zope/app/testing/functional.py 2005-04-22 16:21:14 UTC (rev 30108)
+++ Zope3/trunk/src/zope/app/testing/functional.py 2005-04-22 16:50:28 UTC (rev 30109)
@@ -604,6 +604,29 @@
return response
+ def post(self, request_string, form_fields={}, handle_errors=True):
+ """Encode and perform a POST request.
+
+ This always creates multipart/form-data submissions.
+ """
+ request_string = request_string.strip()
+ if not request_string.startswith("POST "):
+ raise TypeError("request must be a POST")
+ boundary = "--------------------------------------455234523"
+ if form_fields:
+ request_string += "\nContent-Type: multipart/form-data; boundary="
+ request_string += boundary
+ request_string += "\n\n"
+ if form_fields:
+ for name, value in form_fields.iteritems():
+ request_string += "--" + boundary + "\n"
+ request_string += 'Content-Disposition: form-data; name="'
+ request_string += name + '"\n\n'
+ request_string += value + "\n"
+ request_string += "--" + boundary + "--\n"
+ return self.__call__(request_string, handle_errors)
+
+
def chooseRequestClass(self, method, path, environment):
"""Choose and return a request class and a publication class"""
@@ -637,6 +660,7 @@
def FunctionalDocFileSuite(*paths, **kw):
globs = kw.setdefault('globs', {})
globs['http'] = HTTPCaller()
+ globs['post'] = globs['http'].post
globs['getRootFolder'] = getRootFolder
globs['sync'] = sync
More information about the Zope3-Checkins
mailing list