Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Tests stolen from https://github.com/zopefoundation/zope.publisher/pull/15/files
and mangled beyond recognition as is my habit.

Co-Authored-By: Brian Sutherland <brian@sutherland.es>
  • Loading branch information
mgedmin and jinty committed Jul 10, 2019
1 parent e2922ae commit 6f162e9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/zope/publisher/tests/test_browserrequest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
Expand Down Expand Up @@ -282,6 +283,43 @@ def testForm(self):
self.assertEqual(request.form,
{u"a": u"5", u"b": 6})

def testFormMultipartUTF8(self):
extra = {
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'multipart/form_data; boundary=-123',
}
body = b'\n'.join([
b'---123',
b'Content-Disposition: form-data; name="a"',
b'',
b'5',
b'---123',
b'Content-Disposition: form-data; name="b:int"',
b'',
b'6',
b'---123',
b'Content-Disposition: form-data; name="street"',
b'',
b'\xe6\xb1\x89\xe8\xaf\xad/\xe6\xbc\xa2\xe8\xaa\x9e',
b'---123--',
b'',
])
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form[u"street"], unicode))
self.assertEqual(u"汉语/漢語", request.form['street'])

def testFormURLEncodedUTF8(self):
extra = {
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
}
body = b'a=5&b:int=6&street=\xe6\xb1\x89\xe8\xaf\xad/\xe6\xbc\xa2\xe8\xaa\x9e'
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form[u"street"], unicode))
self.assertEqual(u"汉语/漢語", request.form['street'])

def testFormNoEncodingUsesUTF8(self):
encoded = 'K\xc3\xb6hlerstra\xc3\x9fe'
extra = {
Expand Down

0 comments on commit 6f162e9

Please sign in to comment.