summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-21 15:59:26 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-21 15:59:26 +0200
commitad47e4d46b3d6d5705243fbf68ad5ecc34108264 (patch)
treea597abeacd6b71f7ee91dc8b3a4025faabca99a3 /tests
parentb4187e5d61acb98ffb86767c82a60280db7833f3 (diff)
downloadpaste-ad47e4d46b3d6d5705243fbf68ad5ecc34108264.tar.gz
Fix request, session and urlmap tests on Python 3
HTTP body must be bytes
Diffstat (limited to 'tests')
-rw-r--r--tests/test_request.py6
-rw-r--r--tests/test_session.py22
-rw-r--r--tests/test_urlmap.py10
3 files changed, 25 insertions, 13 deletions
diff --git a/tests/test_request.py b/tests/test_request.py
index f5b59d6..072304d 100644
--- a/tests/test_request.py
+++ b/tests/test_request.py
@@ -4,17 +4,21 @@
from paste.fixture import *
from paste.request import *
from paste.wsgiwrappers import WSGIRequest
+import six
def simpleapp(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
request = WSGIRequest(environ)
- return [
+ body = [
'Hello world!\n', 'The get is %s' % str(request.GET),
' and Val is %s\n' % request.GET.get('name'),
'The languages are: %s\n' % request.languages,
'The accepttypes is: %s\n' % request.match_accept(['text/html', 'application/xml'])]
+ if six.PY3:
+ body = [line.encode('utf8') for line in body]
+ return body
def test_gets():
app = TestApp(simpleapp)
diff --git a/tests/test_session.py b/tests/test_session.py
index ca4de0c..b67bda5 100644
--- a/tests/test_session.py
+++ b/tests/test_session.py
@@ -1,5 +1,6 @@
from paste.session import SessionMiddleware
from paste.fixture import TestApp
+import six
info = []
@@ -12,9 +13,12 @@ def wsgi_app(environ, start_response):
if pi == '/get2':
sess = environ['paste.session.factory']()
if 'info' in sess:
- return [str(sess['info'])]
+ body = str(sess['info'])
+ if six.PY3:
+ body = body.encode('utf8')
+ return [body]
else:
- return ['no-info']
+ return [b'no-info']
if pi in ('/put1', '/put2'):
if pi == '/put1':
sess = environ['paste.session.factory']()
@@ -23,30 +27,30 @@ def wsgi_app(environ, start_response):
if pi == '/put2':
sess = environ['paste.session.factory']()
sess['info'] = info[0]
- return ['foo']
+ return [b'foo']
wsgi_app = SessionMiddleware(wsgi_app)
def test_app1():
app = TestApp(wsgi_app)
res = app.get('/get1')
- assert res.body == 'no-info'
+ assert res.body == b'no-info'
res = app.get('/get2')
- assert res.body == 'no-info'
+ assert res.body ==b'no-info'
info[:] = ['test']
res = app.get('/put1')
res = app.get('/get1')
- assert res.body == 'test'
+ assert res.body == b'test'
res = app.get('/get2')
- assert res.body == 'test'
+ assert res.body == b'test'
def test_app2():
app = TestApp(wsgi_app)
info[:] = ['fluff']
res = app.get('/put2')
res = app.get('/get1')
- assert res.body == 'fluff'
+ assert res.body == b'fluff'
res = app.get('/get2')
- assert res.body == 'fluff'
+ assert res.body == b'fluff'
diff --git a/tests/test_urlmap.py b/tests/test_urlmap.py
index 9f77ca2..f7ec729 100644
--- a/tests/test_urlmap.py
+++ b/tests/test_urlmap.py
@@ -1,11 +1,15 @@
from paste.urlmap import *
from paste.fixture import *
+import six
def make_app(response_text):
def app(environ, start_response):
headers = [('Content-type', 'text/html')]
start_response('200 OK', headers)
- return [response_text % environ]
+ body = response_text % environ
+ if six.PY3:
+ body = body.encode('ascii')
+ return [body]
return app
def test_map():
@@ -44,6 +48,6 @@ def test_404():
mapper = URLMap({})
app = TestApp(mapper, extra_environ={'HTTP_ACCEPT': 'text/html'})
res = app.get("/-->%0D<script>alert('xss')</script>", status=404)
- assert '--><script' not in res.body
+ assert b'--><script' not in res.body
res = app.get("/--%01><script>", status=404)
- assert '--\x01><script>' not in res.body
+ assert b'--\x01><script>' not in res.body