Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

root/tags/cherrypy-3.0.0/cherrypy/test/test_wsgi_ns.py

Revision 1430 (checked in by fumanchu, 2 years ago)

Transformed _cptree.wsgi_handler function into _cpwsgi.CPWSGIApp class (a delegate for the Application object), and merged in the wsgi.pipeline functionality. This removes the need to call wsgi.pipeline(app) before tree.mount.

  • Property svn:eol-style set to native
Line 
1 from cherrypy.test import test
2 test.prefer_parent_path()
3
4 import cherrypy
5
6
7 def setup_server():
8    
9     class ChangeCase(object):
10        
11         def __init__(self, app, to=None):
12             self.app = app
13             self.to = to
14        
15         def __call__(self, environ, start_response):
16             res = ''.join(self.app(environ, start_response))
17             return [getattr(res, self.to)()]
18    
19     def replace(app, map={}):
20         def replace_app(environ, start_response):
21             for line in app(environ, start_response):
22                 for k, v in map.iteritems():
23                     line = line.replace(k, v)
24                 yield line
25         return replace_app
26    
27     class Root(object):
28        
29         def index(self):
30             return "HellO WoRlD!"
31         index.exposed = True
32    
33    
34     root_conf = {'wsgi.pipeline': [('replace', replace)],
35                  'wsgi.replace.map': {'L': 'X', 'l': 'r'},
36                  }
37    
38     cherrypy.config.update({'environment': 'test_suite'})
39    
40     app = cherrypy.Application(Root())
41     app.wsgiapp.pipeline.append(('changecase', ChangeCase))
42     app.wsgiapp.config['changecase'] = {'to': 'upper'}
43     cherrypy.tree.mount(app, config={'/': root_conf})
44
45
46 from cherrypy.test import helper
47
48
49 class WSGI_Namespace_Test(helper.CPWebCase):
50    
51     def test_pipeline(self):
52         if not cherrypy.server.httpservers:
53             print "skipped ",
54             return
55        
56         self.getPage("/")
57         # If body is "HEXXO WORXD!", the middleware was applied out of order.
58         self.assertBody("HERRO WORRD!")
59
60 if __name__ == '__main__':
61     setup_server()
62     helper.testmain()
63
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets