1 import os
2 curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
3
4 import cherrypy
5
6 from cherrypy.test import helper
7 import nose
8
10
12
13 try:
14 import routes
15 except ImportError:
16 raise nose.SkipTest('Install routes to test RoutesDispatcher code')
17
18 class Dummy:
19 def index(self):
20 return "I said good day!"
21
22 class City:
23
24 def __init__(self, name):
25 self.name = name
26 self.population = 10000
27
28 def index(self, **kwargs):
29 return "Welcome to %s, pop. %s" % (self.name, self.population)
30 index._cp_config = {'tools.response_headers.on': True,
31 'tools.response_headers.headers': [('Content-Language', 'en-GB')]}
32
33 def update(self, **kwargs):
34 self.population = kwargs['pop']
35 return "OK"
36
37 d = cherrypy.dispatch.RoutesDispatcher()
38 d.connect(action='index', name='hounslow', route='/hounslow',
39 controller=City('Hounslow'))
40 d.connect(name='surbiton', route='/surbiton', controller=City('Surbiton'),
41 action='index', conditions=dict(method=['GET']))
42 d.mapper.connect('/surbiton', controller='surbiton',
43 action='update', conditions=dict(method=['POST']))
44 d.connect('main', ':action', controller=Dummy())
45
46 conf = {'/': {'request.dispatch': d}}
47 cherrypy.tree.mount(root=None, config=conf)
48 setup_server = staticmethod(setup_server)
49
69