1 from cherrypy.test import test
2 test.prefer_parent_path()
3
4 import os
5 curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
6
7 import cherrypy
8
9
11
12 class City:
13
14 def __init__(self, name):
15 self.name = name
16 self.population = 10000
17
18 def index(self, **kwargs):
19 return "Welcome to %s, pop. %s" % (self.name, self.population)
20 index._cp_config = {'tools.response_headers.on': True,
21 'tools.response_headers.headers': [('Content-Language', 'en-GB')]}
22
23 def update(self, **kwargs):
24 self.population = kwargs['pop']
25 return "OK"
26
27 d = cherrypy.dispatch.RoutesDispatcher()
28 d.connect(name='hounslow', route='hounslow', controller=City('Hounslow'))
29 d.connect(name='surbiton', route='surbiton', controller=City('Surbiton'),
30 action='index', conditions=dict(method=['GET']))
31 d.mapper.connect('surbiton', controller='surbiton',
32 action='update', conditions=dict(method=['POST']))
33
34 conf = {'/': {'request.dispatch': d}}
35 cherrypy.tree.mount(root=None, config=conf)
36 cherrypy.config.update({'environment': 'test_suite'})
37
38
39 from cherrypy.test import helper
40
59
60 if __name__ == '__main__':
61 setup_server()
62 helper.testmain()
63