def test_file_request_with_filename(self):
import cgi
# fill in a file upload form...
form = self.make_form()
form["user"] = "john"
data_control = form.find_control("data")
data = "blah\nbaz\n"
data_control.add_file(StringIO(data), filename="afilename")
req = form.click()
self.assert_(
get_header(req, "Content-type").startswith(
"multipart/form-data; boundary="))
# ...and check the resulting request is understood by cgi module
fs = cgi.FieldStorage(
StringIO(req.get_data()),
CaseInsensitiveDict(header_items(req)),
environ={"REQUEST_METHOD": "POST"})
self.assert_(fs["user"].value == "john")
self.assert_(fs["data"].value == data)
self.assert_(fs["data"].filename == "afilename")
评论列表
文章目录