1 from cherrypy.test import test
2 test.prefer_parent_path()
3
4
22
23 def test_empty_string_app(environ, start_response):
24 status = '200 OK'
25 response_headers = [('Content-type', 'text/plain')]
26 start_response(status, response_headers)
27 return ['Hello', '', ' ', '', 'world']
28
29 def reversing_middleware(app):
30 def _app(environ, start_response):
31 results = app(environ, start_response)
32 if not isinstance(results, basestring):
33 results = "".join(results)
34 results = list(results)
35 results.reverse()
36 return ["".join(results)]
37 return _app
38
39 class Root:
40 def index(self):
41 return "I'm a regular CherryPy page handler!"
42 index.exposed = True
43
44
45 class HostedWSGI(object):
46 _cp_config = {'tools.wsgiapp.on': True,
47 'tools.wsgiapp.app': test_app,
48 }
49
50 cherrypy.config.update({'environment': 'test_suite'})
51 cherrypy.tree.mount(Root())
52
53 conf0 = {'/static': {'tools.staticdir.on': True,
54 'tools.staticdir.root': curdir,
55 'tools.staticdir.dir': 'static',
56 }}
57 cherrypy.tree.mount(HostedWSGI(), '/hosted/app0', conf0)
58 cherrypy.tree.graft(test_app, '/hosted/app1')
59 cherrypy.tree.graft(test_empty_string_app, '/hosted/app3')
60
61
62
63 app = cherrypy.Application(Root(), script_name=None)
64 cherrypy.tree.graft(reversing_middleware(app), '/hosted/app2')
65
66 from cherrypy.test import helper
67
68
70
71 wsgi_output = '''Hello, world!
72 This is a wsgi app running within CherryPy!'''
73
77
82
88
93
100
105
106 if __name__ == '__main__':
107 setup_server()
108 helper.testmain()
109