CherryPy / test /

import test

def setup_server():
    import os
    curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
    import cherrypy
    def test_app(environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type', 'text/plain')]
        start_response(status, response_headers)
        yield 'Hello, world!\n'
        yield 'This is a wsgi app running within CherryPy!\n\n'
        keys = environ.keys()
        for k in keys:
            yield '%s: %s\n' % (k,environ[k])
    class Root:
        def index(self):
            return "I'm a regular CherryPy page handler!" = True
    class HostedWSGI(object):
        _cp_config = {'tools.wsgiapp.on': True,
                      '': test_app,
    cherrypy.config.update({'log_to_screen': False,
                            'environment': 'production',
                            'show_tracebacks': True,
    conf0 = {'/static': {'tools.staticdir.on': True,
                         'tools.staticdir.root': curdir,
                         'tools.staticdir.dir': 'static',
    cherrypy.tree.mount(HostedWSGI(), '/hosted/app0', conf0)

import helper

class WSGIAppTest(helper.CPWebCase):
    wsgi_output = '''Hello, world!
This is a wsgi app running within CherryPy!'''

    def test_01_standard_app(self):
        self.assertBody("I'm a regular CherryPy page handler!")
    def test_02_tools(self):
        self.assertHeader("Content-Type", "text/plain")
    def test_04_static_subdir(self):
        self.assertStatus('200 OK')
        self.assertHeader('Content-Type', 'text/html')
        self.assertBody('Hello, world\r\n')

if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.