summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:01:04 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:01:04 +0200
commit5e7e91f896904d274f45570de60fe100fbaec0b7 (patch)
tree5e179a000b1ad119edd0d925d41ed470f78afcc9 /tests
parentad47e4d46b3d6d5705243fbf68ad5ecc34108264 (diff)
downloadpaste-5e7e91f896904d274f45570de60fe100fbaec0b7.tar.gz
Fix WSGIResponse on Python 3
HTTP body must be bytes. Don't check if __iter__() method to check if content is a list or tuple, because bytes and str now have this method on Python 3. Instead, check explicitly for bytes and str types using the six module. Port wsgiwrappers test to Python 3, fix bytes/unicode issues: * HTTP body must be bytes * Filenames are native strings, request ensures that filenames are unicode
Diffstat (limited to 'tests')
-rw-r--r--tests/test_wsgiwrappers.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/test_wsgiwrappers.py b/tests/test_wsgiwrappers.py
index 0448c69..833b4f2 100644
--- a/tests/test_wsgiwrappers.py
+++ b/tests/test_wsgiwrappers.py
@@ -4,6 +4,7 @@
import cgi
from paste.fixture import TestApp
from paste.wsgiwrappers import WSGIRequest, WSGIResponse
+import six
class AssertApp(object):
def __init__(self, assertfunc):
@@ -79,23 +80,23 @@ def test_wsgirequest_charset_fileupload():
assert isinstance(fs, cgi.FieldStorage)
assert isinstance(fs.filename, str)
assert fs.filename == '寿司.txt'
- assert fs.value == 'Sushi'
+ assert fs.value == b'Sushi'
request.charset = 'UTF-8'
assert len(request.POST) == 1
assert isinstance(request.POST.keys()[0], str)
fs = request.POST['thefile']
assert isinstance(fs, cgi.FieldStorage)
- assert isinstance(fs.filename, unicode)
+ assert isinstance(fs.filename, six.text_type)
assert fs.filename == u'寿司.txt'
- assert fs.value == 'Sushi'
+ assert fs.value == b'Sushi'
request.charset = None
- assert fs.value == 'Sushi'
+ assert fs.value == b'Sushi'
return []
app = TestApp(handle_fileupload)
- res = app.post('/', upload_files=[('thefile', '寿司.txt', 'Sushi')])
+ res = app.post('/', upload_files=[('thefile', '寿司.txt', b'Sushi')])
def test_wsgiresponse_charset():
response = WSGIResponse(mimetype='text/html; charset=UTF-8')
@@ -106,7 +107,7 @@ def test_wsgiresponse_charset():
response.write('test3')
status, headers, content = response.wsgi_response()
for data in content:
- assert isinstance(data, str)
+ assert isinstance(data, six.binary_type)
WSGIResponse.defaults._push_object(dict(content_type='text/html',
charset='iso-8859-1'))
@@ -117,7 +118,7 @@ def test_wsgiresponse_charset():
response.write('test3')
status, headers, content = response.wsgi_response()
for data in content:
- assert isinstance(data, str)
+ assert isinstance(data, six.binary_type)
finally:
WSGIResponse.defaults._pop_object()
@@ -130,7 +131,7 @@ def test_wsgiresponse_charset():
response.write(u'test1')
status, headers, content = response.wsgi_response()
for data in content:
- assert isinstance(data, unicode)
+ assert isinstance(data, six.text_type)
finally:
WSGIResponse.defaults._pop_object()
@@ -141,6 +142,6 @@ def test_wsgiresponse_charset():
response.write(u'test1')
status, headers, content = response.wsgi_response()
for data in content:
- assert isinstance(data, unicode)
+ assert isinstance(data, six.text_type)
finally:
WSGIResponse.defaults._pop_object()