summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:32:40 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:32:40 +0200
commitc7e5265cf84a3dd6d17aed875e0849da2aa9d54d (patch)
tree1bc9a2088b991f5a07d35065bbdb6b278f5cda77 /tests
parentb7e14e36dbc093784f735949b5993e7c757c59af (diff)
downloadpaste-c7e5265cf84a3dd6d17aed875e0849da2aa9d54d.tar.gz
Fix test_registry on Python 3
HTTP body must be bytes
Diffstat (limited to 'tests')
-rw-r--r--tests/test_registry.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/tests/test_registry.py b/tests/test_registry.py
index af3a389..23cd9b6 100644
--- a/tests/test_registry.py
+++ b/tests/test_registry.py
@@ -15,19 +15,25 @@ def simpleapp(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
- return ['Hello world!\n']
+ return [b'Hello world!\n']
def simpleapp_withregistry(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
- return ['Hello world!Value is %s\n' % regobj.keys()]
+ body = 'Hello world!Value is %s\n' % regobj.keys()
+ if six.PY3:
+ body = body.encode('utf8')
+ return [body]
def simpleapp_withregistry_default(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
- return ['Hello world!Value is %s\n' % secondobj]
+ body = 'Hello world!Value is %s\n' % secondobj
+ if six.PY3:
+ body = body.encode('utf8')
+ return [body]
class RegistryUsingApp(object):
@@ -44,7 +50,10 @@ class RegistryUsingApp(object):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
- return ['Hello world!\nThe variable is %s' % str(regobj)]
+ body = 'Hello world!\nThe variable is %s' % str(regobj)
+ if six.PY3:
+ body = body.encode('utf8')
+ return [body]
class RegistryUsingIteratorApp(object):
def __init__(self, var, value):
@@ -57,7 +66,10 @@ class RegistryUsingIteratorApp(object):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
- return iter(['Hello world!\nThe variable is %s' % str(regobj)])
+ body = 'Hello world!\nThe variable is %s' % str(regobj)
+ if six.PY3:
+ body = body.encode('utf8')
+ return iter([body])
class RegistryMiddleMan(object):
def __init__(self, app, var, value, depth):
@@ -69,8 +81,11 @@ class RegistryMiddleMan(object):
def __call__(self, environ, start_response):
if 'paste.registry' in environ:
environ['paste.registry'].register(self.var, self.value)
- app_response = ['\nInserted by middleware!\nInsertValue at depth \
- %s is %s' % (self.depth, str(regobj))]
+ line = ('\nInserted by middleware!\nInsertValue at depth %s is %s'
+ % (self.depth, str(regobj)))
+ if six.PY3:
+ line = line.encode('utf8')
+ app_response = [line]
app_iter = None
app_iter = self.app(environ, start_response)
if type(app_iter) in (list, tuple):
@@ -82,8 +97,11 @@ class RegistryMiddleMan(object):
if hasattr(app_iter, 'close'):
app_iter.close()
app_response.extend(response)
- app_response.extend(['\nAppended by middleware!\nAppendValue at \
- depth %s is %s' % (self.depth, str(regobj))])
+ line = ('\nAppended by middleware!\nAppendValue at \
+ depth %s is %s' % (self.depth, str(regobj)))
+ if six.PY3:
+ line = line.encode('utf8')
+ app_response.append(line)
return app_response