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 cStringIO, urllib, time, sys, traceback
import odict 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(): def date_time_string():
"""Return the current date and time formatted for a message header.""" """Return the current date and time formatted for a message header."""
WEEKS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] WEEKS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
@ -85,7 +98,7 @@ class WSGIAdaptor:
soc.write("HTTP/1.1 %s\r\n"%state["status"]) soc.write("HTTP/1.1 %s\r\n"%state["status"])
h = state["headers"] h = state["headers"]
if 'server' not in h: if 'server' not in h:
h["Server"] = [version.NAMEVERSION] h["Server"] = [self.sversion]
if 'date' not in h: if 'date' not in h:
h["Date"] = [date_time_string()] h["Date"] = [date_time_string()]
soc.write(str(h)) soc.write(str(h))

View File

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