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

root/tags/cherrypy-3.0.0/cherrypy/test/test_http.py

Revision 1275 (checked in by fumanchu, 2 years ago)

Overhaul of config system:

  1. New docstring for config module!
  2. Put all entries into a config namespace. New deadlock, log, request and response namespaces.
  3. Request and response entries now directly modify attributes of cherrypy.request and .response, and consumer code looks up those attributes, not config. This also allows interactive inspection of defaults.
  4. Removed 'log_config' config entry. Use engine.on_start_engine_list.append(config.log_config) instead.
  5. Old 'dispatch' entry is now 'request.dispatch'.
  6. New log entries: log.error.file, log.error.function, log.access.file, log.access.function, log.screen.
  7. 'server.max_request_body_size' is now 'request.max_body_size'.
  8. environments now only apply to globalconf.
  9. The 'development' environment has been removed, since its settings were all the default anyway.
  10. The 'embedded' environment has been removed, since it duplicates the 'production' environment now.
  11. There's a new 'test_suite' environment.
  12. Removed log_file_not_found (from static.py).

Something still needs to be done to config.wrap, so it can take dotted names as kwarg keys.

  • Property svn:eol-style set to native
Line 
1 """Tests for managing HTTP issues (malformed requests, etc).
2
3 Some of these tests check timeouts, etcetera, and therefore take a long
4 time to run. Therefore, this module should probably not be included in
5 the 'comprehensive' test suite (test.py).
6 """
7
8 from cherrypy.test import test
9 test.prefer_parent_path()
10
11 import gc
12 import httplib
13 import threading
14 import cherrypy
15 from cherrypy import _cprequest
16
17
18 data = object()
19
20 def get_instances(cls):
21     return [x for x in gc.get_objects() if isinstance(x, cls)]
22
23 def setup_server():
24    
25     class Root:
26         def index(self, *args, **kwargs):
27             cherrypy.request.thing = data
28             return "Hello world!"
29         index.exposed = True
30        
31         def gc_stats(self):
32             return "%s %s %s %s" % (gc.collect(),
33                                     len(get_instances(_cprequest.Request)),
34                                     len(get_instances(_cprequest.Response)),
35                                     len(gc.get_referrers(data)))
36         gc_stats.exposed = True
37     cherrypy.tree.mount(Root())
38     cherrypy.config.update({'environment': 'test_suite'})
39
40
41 from cherrypy.test import helper
42
43 class HTTPTests(helper.CPWebCase):
44    
45     def test_sockets(self):
46         # By not including a Content-Length header, cgi.FieldStorage
47         # will hang. Verify that CP times out the socket and responds
48         # with 411 Length Required.
49         c = httplib.HTTPConnection("localhost:%s" % self.PORT)
50         c.request("POST", "/")
51         self.assertEqual(c.getresponse().status, 411)
52
53
54 class ReferenceTests(helper.CPWebCase):
55    
56     def test_threadlocal_garbage(self):
57         def getpage():
58             self.getPage('/')
59             self.assertBody("Hello world!")
60        
61         ts = []
62         for _ in range(25):
63             t = threading.Thread(target=getpage)
64             ts.append(t)
65             t.start()
66        
67         for t in ts:
68             t.join()
69        
70         self.getPage("/gc_stats")
71         self.assertBody("0 1 1 1")
72
73
74 if __name__ == '__main__':
75     setup_server()
76     helper.testmain()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets