summaryrefslogtreecommitdiff
path: root/py3/cherrypy/test/test_wsgi_ns.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2011-02-25 22:38:17 +0000
committerRobert Brewer <fumanchu@aminus.org>2011-02-25 22:38:17 +0000
commitfd8b1e2a2662d965f05a14c2c72701decd81697c (patch)
treef6b7f89ffb181bc940c7d9b3541f01f25b49699d /py3/cherrypy/test/test_wsgi_ns.py
parent5450bb603f7e0cf91d216225d3fa3f524710bcd6 (diff)
downloadcherrypy-git-trunk.tar.gz
Bringing python3 back into trunk with its own py3 folder; what was in trunk goes in the py2 folder, and we can use a single setup.py to install either, depending on the version of Python that runs setup.py install.trunk
Diffstat (limited to 'py3/cherrypy/test/test_wsgi_ns.py')
-rw-r--r--py3/cherrypy/test/test_wsgi_ns.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/py3/cherrypy/test/test_wsgi_ns.py b/py3/cherrypy/test/test_wsgi_ns.py
new file mode 100644
index 00000000..99dbc578
--- /dev/null
+++ b/py3/cherrypy/test/test_wsgi_ns.py
@@ -0,0 +1,80 @@
+import cherrypy
+from cherrypy.test import helper
+
+
+class WSGI_Namespace_Test(helper.CPWebCase):
+
+ def setup_server():
+
+ class WSGIResponse(object):
+
+ def __init__(self, appresults):
+ self.appresults = appresults
+ self.iter = iter(appresults)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ return next(self.iter)
+
+ def close(self):
+ if hasattr(self.appresults, "close"):
+ self.appresults.close()
+
+
+ class ChangeCase(object):
+
+ def __init__(self, app, to=None):
+ self.app = app
+ self.to = to
+
+ def __call__(self, environ, start_response):
+ res = self.app(environ, start_response)
+ class CaseResults(WSGIResponse):
+ def __next__(this):
+ return getattr(next(this.iter), self.to)()
+ return CaseResults(res)
+
+ class Replacer(object):
+
+ def __init__(self, app, map={}):
+ self.app = app
+ self.map = map
+
+ def __call__(self, environ, start_response):
+ res = self.app(environ, start_response)
+ class ReplaceResults(WSGIResponse):
+ def __next__(this):
+ line = next(this.iter)
+ for k, v in self.map.items():
+ line = line.replace(k, v)
+ return line
+ return ReplaceResults(res)
+
+ class Root(object):
+
+ def index(self):
+ return "HellO WoRlD!"
+ index.exposed = True
+
+
+ root_conf = {'wsgi.pipeline': [('replace', Replacer)],
+ 'wsgi.replace.map': {b'L': b'X', b'l': b'r'},
+ }
+
+ app = cherrypy.Application(Root())
+ app.wsgiapp.pipeline.append(('changecase', ChangeCase))
+ app.wsgiapp.config['changecase'] = {'to': 'upper'}
+ cherrypy.tree.mount(app, config={'/': root_conf})
+ setup_server = staticmethod(setup_server)
+
+
+ def test_pipeline(self):
+ if not cherrypy.server.httpserver:
+ return self.skip()
+
+ self.getPage("/")
+ # If body is "HEXXO WORXD!", the middleware was applied out of order.
+ self.assertBody("HERRO WORRD!")
+