Fix test_app to run in Python 3

--HG--
branch : py3k
master
Dustin C. Hatch 2012-11-30 14:16:57 -06:00
parent dc79fea9db
commit 232bb17d6f
1 changed files with 6 additions and 6 deletions

View File

@ -33,7 +33,7 @@ class ResponseMaker(object):
def __init__(self, http_version=1.1):
self.http_version = http_version
self.headers = ''
self.body = ''
self.body = b''
def start_response(self, status, response_headers):
self.headers += 'HTTP/{0} {1}\r\n'.format(self.http_version, status)
@ -78,7 +78,7 @@ def test_favicon():
app_iter = app(environ, response.start_response)
response.finish_response(app_iter)
assert response.headers.startswith('HTTP/1.1 200'), response.headers
assert response.body.startswith('\x00\x00\x01\x00'), response.body
assert response.body.startswith(b'\x00\x00\x01\x00'), response.body
def test_allow_header_disallowed():
'''HTTP 405 is returned for disallowed HTTP request methods
@ -138,7 +138,7 @@ def test_emulated_method():
})
body = environ['wsgi.input']
body.seek(0)
body.write('_method=PUT')
body.write(b'_method=PUT')
body.seek(0)
response = ResponseMaker()
app_iter = app(environ, response.start_response)
@ -358,7 +358,7 @@ def test_httperror_response():
'''
def controller(request):
raise webob.exc.HTTPClientError()
raise webob.exc.HTTPClientError('NotFound')
app = milla.app.Application(StubResolver(controller))
environ = testing_environ()
@ -366,7 +366,7 @@ def test_httperror_response():
app_iter = app(environ, response.start_response)
response.finish_response(app_iter)
assert response.headers.startswith('HTTP/1.1 400'), response.headers
assert webob.exc.HTTPClientError.explanation in response.body, response.body
assert b'NotFound' in response.body, response.body
def test_single_start_response():
'''Ensure start_response is only called once'''
@ -393,4 +393,4 @@ def test_single_start_response():
response.finish_response(app_iter)
assert start_response.call_count == 1, start_response.call_count
assert response.headers.startswith('HTTP/1.1 200 OK'), response.headers
assert response.body == 'test', response.body
assert response.body == b'test', response.body