summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2010-09-02 00:19:48 +0200
committerHelmut Grohne <helmut@subdivi.de>2010-09-02 00:19:48 +0200
commit86935b4ee3c46374d061522f0c53e40d94e9a24d (patch)
tree0c19ca7934c41085531bccbd2d76f78751656ff9
parentfcdeea671fc7b5fdbd204e2cd5f66c07f8ccca09 (diff)
downloadwsgitools-86935b4ee3c46374d061522f0c53e40d94e9a24d.tar.gz
employ wsgiref.validate.validator in the test suite
-rwxr-xr-xtest.py44
1 files changed, 35 insertions, 9 deletions
diff --git a/test.py b/test.py
index 73b1cbb..13b7fb2 100755
--- a/test.py
+++ b/test.py
@@ -1,12 +1,19 @@
-#!/usr/bin/env python2.5
+#!/usr/bin/env python
import unittest
import doctest
-
+import wsgiref.validate
+# Cannot use io module as it is broken in 2.6.
+# Writing a str to a io.StringIO results in an exception.
+try:
+ import cStringIO as io
+except ImportError:
+ import StringIO as io
try:
from hashlib import md5
except ImportError:
from md5 import md5
+import sys
try:
next
@@ -20,7 +27,21 @@ class Request:
@type case: unittest.TestCase
"""
self.testcase = case
- self.environ = dict(REQUEST_METHOD="GET")
+ self.environ = dict(
+ REQUEST_METHOD="GET",
+ SERVER_NAME="localhost",
+ SERVER_PORT="80",
+ SCRIPT_NAME="",
+ PATH_INFO="",
+ QUERY_STRING="")
+ self.environ.update({
+ "wsgi.version": (1, 0),
+ "wsgi.input": io.StringIO(),
+ "wsgi.errors": sys.stderr,
+ "wsgi.url_scheme": "http",
+ "wsgi.multithread": False,
+ "wsgi.multiprocess": False,
+ "wsgi.run_once": False})
def setenv(self, key, value):
"""
@@ -48,6 +69,7 @@ class Request:
return req
def __call__(self, app):
+ app = wsgiref.validate.validator(app)
res = Result(self.testcase)
def write(data):
res.writtendata.append(data)
@@ -55,7 +77,10 @@ class Request:
res.statusdata = status
res.headersdata = headers
return write
- res.returneddata = app(self.environ, start_response)
+ iterator = app(self.environ, start_response)
+ self.returneddata = list(iterator)
+ if hasattr(iterator, "close"):
+ iterator.close()
return res
class Result:
@@ -105,8 +130,8 @@ from wsgitools import applications
class StaticContentTest(unittest.TestCase):
def setUp(self):
- self.app = applications.StaticContent("200 Found", [("Spam", "Egg")],
- "nothing")
+ self.app = applications.StaticContent(
+ "200 Found", [("Content-Type", "text/plain")], "nothing")
self.req = Request(self)
def testGet(self):
@@ -125,9 +150,11 @@ from wsgitools import digest
class AuthDigestMiddlewareTest(unittest.TestCase):
def setUp(self):
- self.staticapp = applications.StaticContent("200 Found", [], "success")
+ self.staticapp = applications.StaticContent(
+ "200 Found", [("Content-Type", "text/plain")], "success")
token_gen = digest.AuthTokenGenerator("foo", lambda _: "baz")
- self.app = digest.AuthDigestMiddleware(self.staticapp, token_gen)
+ self.app = digest.AuthDigestMiddleware(
+ wsgiref.validate.validator(self.staticapp), token_gen)
self.req = Request(self)
def test401(self):
@@ -165,7 +192,6 @@ fullsuite.addTest(alltests(AuthDigestMiddlewareTest))
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
- import sys
if "profile" in sys.argv:
try:
import cProfile as profile