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

root/branches/cp3-wsgi-remix/test/test_config.py

Revision 1096 (checked in by fumanchu, 3 years ago)

Root and config are now isolated per app:

  1. object_path is now called path_info, and there's a new request.script_name attribute. This should equal the mount point of the current application.
  2. cherrypy.root is gone, use cherrypy.request.app.root for now instead. Perhaps cherrypy.root will reappear and point to that.
  3. cherrypy.tree.mount_points has been replaced with cherrypy.tree.apps, a dict of the form {script_name: Application(root, conf)}.
  4. The [global] config namespace is now contained in a flat cherrypy.config.globalconf dict.
  5. Got rid of handling favicon.ico and the "*" URI (although they may return someday).
  6. Upshot is that e.g. test_objectmapping.py takes 1/3 the time as CP 2.2.
  7. Moved request body size check into _cprequest from _cpwsgi.
  8. Fixed lib/wsgiapp and made a tool for it.
  • Property svn:eol-style set to native
Line 
1 """Tests for the CherryPy configuration system."""
2 import test
3 test.prefer_parent_path()
4
5 import StringIO
6 import cherrypy
7
8
9 def setup_server():
10    
11     class Root:
12        
13         _cp_config = {'foo': 'this',
14                       'bar': 'that'}
15        
16         def index(self, key):
17             return cherrypy.config.get(key, "None")
18         index.exposed = True
19         global_ = index
20         xyz = index
21    
22     class Foo:
23        
24         _cp_config = {'foo': 'this2',
25                       'baz': 'that2'}
26        
27         def index(self, key):
28             return cherrypy.config.get(key, "None")
29         index.exposed = True
30         nex = index
31        
32         def bar(self, key):
33             return cherrypy.config.get(key, "None")
34         bar.exposed = True
35         bar._cp_config = {'foo': 'this3', 'bax': 'this4'}
36    
37     class Env:
38        
39         def index(self, key):
40             return str(cherrypy.config.get(key, "None"))
41         index.exposed = True
42         prod = index
43         embed = index
44    
45     root = Root()
46     root.foo = Foo()
47     cherrypy.tree.mount(root)
48    
49     cherrypy.config.update({'log_to_screen': False,
50                             'environment': 'production',
51                             'show_tracebacks': True,
52                             })
53    
54     _env_conf = {'/': {'environment': 'development'},
55                  '/prod': {'environment': 'production'},
56                  '/embed': {'environment': 'embedded'},
57                  }
58     cherrypy.tree.mount(Env(), "/env", _env_conf)
59    
60     # Shortcut syntax--should get put in the "global" bucket
61     cherrypy.config.update({'luxuryyacht': 'throatwobblermangrove'})
62
63
64 #                             Client-side code                             #
65
66 import helper
67
68 class ConfigTests(helper.CPWebCase):
69    
70     def testConfig(self):
71         tests = [
72             ('/',        'nex', 'None'),
73             ('/',        'foo', 'this'),
74             ('/',        'bar', 'that'),
75             ('/xyz',     'foo', 'this'),
76             ('/foo/',    'foo', 'this2'),
77             ('/foo/',    'bar', 'that'),
78             ('/foo/',    'bax', 'None'),
79             ('/foo/bar', 'baz', 'that2'),
80             ('/foo/nex', 'baz', 'that2'),
81             # If 'foo' == 'this', then the mount point '/env' leaks into '/'.
82             ('/env/prod','foo', 'None'),
83         ]
84         for path, key, expected in tests:
85             self.getPage(path + "?key=" + key)
86             self.assertBody(expected)
87    
88     def testEnvironments(self):
89         for key, val in cherrypy.config.environments['development'].iteritems():
90             self.getPage("/env/?key=" + key)
91             self.assertBody(str(val))
92         for key, val in cherrypy.config.environments['production'].iteritems():
93             self.getPage("/env/prod/?key=" + key)
94             self.assertBody(str(val))
95         for key, val in cherrypy.config.environments['embedded'].iteritems():
96             self.getPage("/env/embed/?key=" + key)
97             self.assertBody(str(val))
98
99
100 if __name__ == '__main__':
101     setup_server()
102     helper.testmain()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets