Adapt WSGI, convert test suite to nose.

This commit is contained in:
Aldo Cortesi 2012-06-19 14:23:22 +12:00
parent c7e9051cbb
commit ce1ef55456
2 changed files with 29 additions and 10 deletions

View File

@ -1,6 +1,19 @@
import cStringIO, urllib, time, sys, traceback
import odict
class ClientConn:
def __init__(self, address):
self.address = address
class Request:
def __init__(self, client_conn, scheme, method, path, headers, content):
self.scheme, self.method, self.path = scheme, method, path
self.headers, self.content = headers, content
self.client_conn = client_conn
def date_time_string():
"""Return the current date and time formatted for a message header."""
WEEKS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
@ -85,7 +98,7 @@ class WSGIAdaptor:
soc.write("HTTP/1.1 %s\r\n"%state["status"])
h = state["headers"]
if 'server' not in h:
h["Server"] = [version.NAMEVERSION]
h["Server"] = [self.sversion]
if 'date' not in h:
h["Date"] = [date_time_string()]
soc.write(str(h))

View File

@ -1,7 +1,13 @@
import cStringIO, sys
import libpry
from netlib import wsgi
import tutils
from netlib import wsgi, odict
def treq():
cc = wsgi.ClientConn(("127.0.0.1", 8888))
h = odict.ODictCaseless()
h["test"] = ["value"]
return wsgi.Request(cc, "http", "GET", "/", h, "")
class TestApp:
@ -16,10 +22,10 @@ class TestApp:
return ['Hello', ' world!\n']
class uWSGIAdaptor(libpry.AutoTree):
class TestWSGI:
def test_make_environ(self):
w = wsgi.WSGIAdaptor(None, "foo", 80)
tr = tutils.treq()
w = wsgi.WSGIAdaptor(None, "foo", 80, "version")
tr = treq()
assert w.make_environ(tr, None)
tr.path = "/foo?bar=voing"
@ -28,8 +34,8 @@ class uWSGIAdaptor(libpry.AutoTree):
def test_serve(self):
ta = TestApp()
w = wsgi.WSGIAdaptor(ta, "foo", 80)
r = tutils.treq()
w = wsgi.WSGIAdaptor(ta, "foo", 80, "version")
r = treq()
r.host = "foo"
r.port = 80
@ -43,8 +49,8 @@ class uWSGIAdaptor(libpry.AutoTree):
assert "Server:" in val
def _serve(self, app):
w = wsgi.WSGIAdaptor(app, "foo", 80)
r = tutils.treq()
w = wsgi.WSGIAdaptor(app, "foo", 80, "version")
r = treq()
r.host = "foo"
r.port = 80
wfile = cStringIO.StringIO()