diff --git a/src/zope/server/http/tests/test_wsgiserver.py b/src/zope/server/http/tests/test_wsgiserver.py index 7b32c9a..b4381e9 100644 --- a/src/zope/server/http/tests/test_wsgiserver.py +++ b/src/zope/server/http/tests/test_wsgiserver.py @@ -54,8 +54,8 @@ class Conflict(Exception): Pseudo ZODB conflict error. """ -ERROR_RESPONSE = "error occurred" -RESPONSE = "normal response" +ERROR_RESPONSE = b"error occurred" +RESPONSE = b"normal response" class DummyException(Exception): value = "Dummy Exception to test start_response" @@ -181,7 +181,7 @@ def application(environ, start_response): self.port = self.server.socket.getsockname()[1] self.run_loop = 1 - self.thread = Thread(target=self.loop) + self.thread = Thread(target=self.loop, name='test_wsgiserver') self.thread.start() sleep(0.1) # Give the thread some time to start. @@ -196,7 +196,7 @@ def loop(self): while self.run_loop: poll(0.1, socket_map) - def invokeRequest(self, path='/', add_headers=None, request_body='', + def invokeRequest(self, path='/', add_headers=None, request_body=b'', return_response=False): h = HTTPConnection(LOCALHOST, self.port) h.putrequest('GET', path) @@ -216,7 +216,7 @@ def invokeRequest(self, path='/', add_headers=None, request_body='', if length: response_body = response.read(length) else: - response_body = '' + response_body = b'' self.assertEqual(length, len(response_body)) @@ -228,7 +228,7 @@ def testDeeperPath(self): self.assertEqual(status, 200) expect_response = 'URL invoked: http://%s:%d/folder/item' % ( LOCALHOST, self.port) - self.assertEqual(response_body, expect_response) + self.assertEqual(response_body, expect_response.encode()) def testNotFound(self): status, response_body = self.invokeRequest('/foo/bar') @@ -271,12 +271,12 @@ def testServerAsProxy(self): self.assertEqual( response.getheader('Via'), 'zope.server.http (Browser)') # And the content got here too. - self.assertEqual(response.read(), 'Proxied Content') + self.assertEqual(response.read(), b'Proxied Content') def testWSGIVariables(self): # Assert that the environment contains all required WSGI variables status, response_body = self.invokeRequest('/wsgi') - wsgi_variables = set(response_body.split()) + wsgi_variables = set(response_body.decode().split()) self.assertEqual(wsgi_variables, set(['wsgi.version', 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors', 'wsgi.multithread', @@ -284,31 +284,31 @@ def testWSGIVariables(self): def testWSGIVersion(self): status, response_body = self.invokeRequest('/wsgi/version') - self.assertEqual("(1, 0)", response_body) + self.assertEqual(b"(1, 0)", response_body) def testWSGIURLScheme(self): status, response_body = self.invokeRequest('/wsgi/url_scheme') - self.assertEqual('http', response_body) + self.assertEqual(b'http', response_body) def testWSGIMultithread(self): status, response_body = self.invokeRequest('/wsgi/multithread') - self.assertEqual('True', response_body) + self.assertEqual(b'True', response_body) def testWSGIMultiprocess(self): status, response_body = self.invokeRequest('/wsgi/multiprocess') - self.assertEqual('True', response_body) + self.assertEqual(b'True', response_body) def testWSGIRunOnce(self): status, response_body = self.invokeRequest('/wsgi/run_once') - self.assertEqual('False', response_body) + self.assertEqual(b'False', response_body) def testWSGIProxy(self): status, response_body = self.invokeRequest( 'https://zope.org:8080/wsgi/proxy_scheme') - self.assertEqual('https', response_body) + self.assertEqual(b'https', response_body) status, response_body = self.invokeRequest( 'https://zope.org:8080/wsgi/proxy_host') - self.assertEqual('zope.org:8080', response_body) + self.assertEqual(b'zope.org:8080', response_body) def test_ensure_multiple_task_write_calls(self): # In order to get data out as fast as possible, the WSGI server needs @@ -316,7 +316,7 @@ def test_ensure_multiple_task_write_calls(self): orig_app = self.server.application def app(eviron, start_response): start_response('200 Ok', []) - return ['This', 'is', 'my', 'response.'] + return [b'This', b'is', b'my', b'response.'] self.server.application = app class FakeTask: @@ -444,13 +444,14 @@ def __init__(self, value): def __iter__(self): return self - def next(self): - return self._iter.next() + def __next__(self): + return next(self._iter) + next = __next__ def close(self): self.closed = True - iterator = CloseableIterator(["Klaatu", "barada", "nikto"]) + iterator = CloseableIterator([b"Klaatu", b"barada", b"nikto"]) def app(environ, start_response): start_response("200 Ok", [], None) return iterator @@ -484,7 +485,7 @@ def _getServerClass(self): def testWSGIVariables(self): # Assert that the environment contains all required WSGI variables status, response_body = self.invokeRequest('/wsgi') - wsgi_variables = set(response_body.split()) + wsgi_variables = set(response_body.decode().split()) self.assertEqual(wsgi_variables, set(['wsgi.version', 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors', 'wsgi.multithread',