aboutsummaryrefslogtreecommitdiff
path: root/dummyserver
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:39 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:39 -0700
commit0f393d00b51bc54c5075447e4a8b21f0bed6acd8 (patch)
tree401c9f6c345c8ec7818e2d3341086a1b889b3bc4 /dummyserver
parent73be7d6cc85a90ab4f67ffc27dc7eae672f7741f (diff)
downloadpython-urllib3-0f393d00b51bc54c5075447e4a8b21f0bed6acd8.tar
python-urllib3-0f393d00b51bc54c5075447e4a8b21f0bed6acd8.tar.gz
Imported Upstream version 1.9
Diffstat (limited to 'dummyserver')
-rw-r--r--dummyserver/handlers.py28
-rwxr-xr-xdummyserver/server.py2
-rw-r--r--dummyserver/testcase.py7
3 files changed, 32 insertions, 5 deletions
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index 5d6e2e6..72faa1a 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -1,5 +1,6 @@
from __future__ import print_function
+import collections
import gzip
import json
import logging
@@ -41,11 +42,12 @@ class TestingApp(WSGIHandler):
Simple app that performs various operations, useful for testing an HTTP
library.
- Given any path, it will attempt to convert it will load a corresponding
- local method if it exists. Status code 200 indicates success, 400 indicates
- failure. Each method has its own conditions for success/failure.
+ Given any path, it will attempt to load a corresponding local method if
+ it exists. Status code 200 indicates success, 400 indicates failure. Each
+ method has its own conditions for success/failure.
"""
def __call__(self, environ, start_response):
+ """ Call the correct method in this class based on the incoming URI """
req = HTTPRequest(environ)
req.params = {}
@@ -172,6 +174,25 @@ class TestingApp(WSGIHandler):
def headers(self, request):
return Response(json.dumps(request.headers))
+ def successful_retry(self, request):
+ """ Handler which will return an error and then success
+
+ It's not currently very flexible as the number of retries is hard-coded.
+ """
+ test_name = request.headers.get('test-name', None)
+ if not test_name:
+ return Response("test-name header not set",
+ status="400 Bad Request")
+
+ if not hasattr(self, 'retry_test_names'):
+ self.retry_test_names = collections.defaultdict(int)
+ self.retry_test_names[test_name] += 1
+
+ if self.retry_test_names[test_name] >= 2:
+ return Response("Retry successful!")
+ else:
+ return Response("need to keep retrying!", status="418 I'm A Teapot")
+
def shutdown(self, request):
sys.exit()
@@ -207,7 +228,6 @@ def _parse_header(line):
params.pop(0) # get rid of the dummy again
pdict = {}
for name, value in params:
- print(repr(value))
value = email.utils.collapse_rfc2231_value(value)
if len(value) >= 2 and value[0] == '"' and value[-1] == '"':
value = value[1:-1]
diff --git a/dummyserver/server.py b/dummyserver/server.py
index 22de456..99f0835 100755
--- a/dummyserver/server.py
+++ b/dummyserver/server.py
@@ -58,7 +58,7 @@ class SocketServerThread(threading.Thread):
self.port = sock.getsockname()[1]
# Once listen() returns, the server socket is ready
- sock.listen(1)
+ sock.listen(0)
if self.ready_event:
self.ready_event.set()
diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py
index 35769ef..335b2f2 100644
--- a/dummyserver/testcase.py
+++ b/dummyserver/testcase.py
@@ -40,6 +40,13 @@ class SocketDummyServerTestCase(unittest.TestCase):
class HTTPDummyServerTestCase(unittest.TestCase):
+ """ A simple HTTP server that runs when your test class runs
+
+ Have your unittest class inherit from this one, and then a simple server
+ will start when your tests run, and automatically shut down when they
+ complete. For examples of what test requests you can send to the server,
+ see the TestingApp in dummyserver/handlers.py.
+ """
scheme = 'http'
host = 'localhost'
host_alt = '127.0.0.1' # Some tests need two hosts