aboutsummaryrefslogtreecommitdiff
path: root/dummyserver
diff options
context:
space:
mode:
Diffstat (limited to 'dummyserver')
-rw-r--r--dummyserver/handlers.py10
-rwxr-xr-xdummyserver/server.py1
-rw-r--r--dummyserver/testcase.py6
3 files changed, 15 insertions, 2 deletions
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index ca809ad..ab48b53 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -1,6 +1,7 @@
from __future__ import print_function
import gzip
+import json
import logging
import sys
import time
@@ -120,7 +121,7 @@ class TestingApp(WSGIHandler):
return Response(status='303', headers=headers)
def keepalive(self, request):
- if request.params.get('close', '0') == '1':
+ if request.params.get('close', b'0') == b'1':
headers = [('Connection', 'close')]
return Response('Closing', headers=headers)
@@ -148,7 +149,9 @@ class TestingApp(WSGIHandler):
if encoding == 'gzip':
headers = [('Content-Encoding', 'gzip')]
file_ = BytesIO()
- gzip.GzipFile('', mode='w', fileobj=file_).write(data)
+ zipfile = gzip.GzipFile('', mode='w', fileobj=file_)
+ zipfile.write(data)
+ zipfile.close()
data = file_.getvalue()
elif encoding == 'deflate':
headers = [('Content-Encoding', 'deflate')]
@@ -161,5 +164,8 @@ class TestingApp(WSGIHandler):
data = 'garbage'
return Response(data, headers=headers)
+ def headers(self, request):
+ return Response(json.dumps(request.headers))
+
def shutdown(self, request):
sys.exit()
diff --git a/dummyserver/server.py b/dummyserver/server.py
index 6c0943c..9031664 100755
--- a/dummyserver/server.py
+++ b/dummyserver/server.py
@@ -60,6 +60,7 @@ class SocketServerThread(threading.Thread):
self.ready_lock.release()
self.socket_handler(sock)
+ sock.close()
def run(self):
self.server = self._start_server()
diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py
index 518d739..73b8f2f 100644
--- a/dummyserver/testcase.py
+++ b/dummyserver/testcase.py
@@ -32,6 +32,11 @@ class SocketDummyServerTestCase(unittest.TestCase):
# Lock gets released by thread above
ready_lock.acquire()
+ @classmethod
+ def tearDownClass(cls):
+ if hasattr(cls, 'server_thread'):
+ cls.server_thread.join()
+
class HTTPDummyServerTestCase(unittest.TestCase):
scheme = 'http'
@@ -54,6 +59,7 @@ class HTTPDummyServerTestCase(unittest.TestCase):
@classmethod
def _stop_server(cls):
cls.server_thread.stop()
+ cls.server_thread.join()
@classmethod
def setUpClass(cls):