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 Dummy:
13 def index(self):
14 return "I said good day!"
15
16 class City:
17
18 def __init__(self, name):
19 self.name = name
20 self.population = 10000
21
22 def index(self, **kwargs):
23 return "Welcome to %s, pop. %s" % (self.name, self.population)
24 index._cp_config = {'tools.response_headers.on': True,
25 'tools.response_headers.headers': [('Content-Language', 'en-GB')]}
26
27 def update(self, **kwargs):
28 self.population = kwargs['pop']
29 return "OK"
30
31 d = cherrypy.dispatch.RoutesDispatcher()
32 d.connect(name='hounslow', route='hounslow', controller=City('Hounslow'))
33 d.connect(name='surbiton', route='surbiton', controller=City('Surbiton'),
34 action='index', conditions=dict(method=['GET']))
35 d.mapper.connect('surbiton', controller='surbiton',
36 action='update', conditions=dict(method=['POST']))
37 d.connect('main', ':action', controller=Dummy())
38
39 conf = {'/': {'request.dispatch': d}}
40 cherrypy.tree.mount(root=None, config=conf)
41 cherrypy.config.update({'environment': 'test_suite'})
42
43
44 from cherrypy.test import helper
45
67
68 if __name__ == '__main__':
69 setup_server()
70 helper.testmain()
71