Back to index

python3.2  3.2.2
Public Member Functions
test.test_wsgiref.HandlerTests Class Reference
Inheritance diagram for test.test_wsgiref.HandlerTests:
Inheritance graph
[legend]
Collaboration diagram for test.test_wsgiref.HandlerTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def checkEnvironAttrs
def checkOSEnviron
def testEnviron
def testCGIEnviron
def testScheme
def testAbstractMethods
def testContentLength
def testBasicErrorOutput
def testErrorAfterOutput
def testHeaderFormats
def testBytesData

Detailed Description

Definition at line 458 of file test_wsgiref.py.


Member Function Documentation

def test.test_wsgiref.HandlerTests.checkEnvironAttrs (   self,
  handler 
)

Definition at line 460 of file test_wsgiref.py.

00460 
00461     def checkEnvironAttrs(self, handler):
00462         env = handler.environ
00463         for attr in [
00464             'version','multithread','multiprocess','run_once','file_wrapper'
00465         ]:
00466             if attr=='file_wrapper' and handler.wsgi_file_wrapper is None:
00467                 continue
00468             self.assertEqual(getattr(handler,'wsgi_'+attr),env['wsgi.'+attr])

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_wsgiref.HandlerTests.checkOSEnviron (   self,
  handler 
)

Definition at line 469 of file test_wsgiref.py.

00469 
00470     def checkOSEnviron(self,handler):
00471         empty = {}; setup_testing_defaults(empty)
00472         env = handler.environ
00473         from os import environ
00474         for k,v in environ.items():
00475             if k not in empty:
00476                 self.assertEqual(env[k],v)
00477         for k,v in empty.items():
00478             self.assertIn(k, env)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 499 of file test_wsgiref.py.

00499 
00500     def testAbstractMethods(self):
00501         h = BaseHandler()
00502         for name in [
00503             '_flush','get_stdin','get_stderr','add_cgi_vars'
00504         ]:
00505             self.assertRaises(NotImplementedError, getattr(h,name))
00506         self.assertRaises(NotImplementedError, h._write, "test")
00507 

Here is the call graph for this function:

Definition at line 558 of file test_wsgiref.py.

00558 
00559     def testBasicErrorOutput(self):
00560 
00561         def non_error_app(e,s):
00562             s('200 OK',[])
00563             return []
00564 
00565         def error_app(e,s):
00566             raise AssertionError("This should be caught by handler")
00567 
00568         h = ErrorHandler()
00569         h.run(non_error_app)
00570         self.assertEqual(h.stdout.getvalue(),
00571             ("Status: 200 OK\r\n"
00572             "Content-Length: 0\r\n"
00573             "\r\n").encode("iso-8859-1"))
00574         self.assertEqual(h.stderr.getvalue(),"")
00575 
00576         h = ErrorHandler()
00577         h.run(error_app)
00578         self.assertEqual(h.stdout.getvalue(),
00579             ("Status: %s\r\n"
00580             "Content-Type: text/plain\r\n"
00581             "Content-Length: %d\r\n"
00582             "\r\n" % (h.error_status,len(h.error_body))).encode('iso-8859-1')
00583             + h.error_body)
00584 
00585         self.assertIn("AssertionError", h.stderr.getvalue())

Here is the call graph for this function:

Definition at line 643 of file test_wsgiref.py.

00643 
00644     def testBytesData(self):
00645         def app(e, s):
00646             s("200 OK", [
00647                 ("Content-Type", "text/plain; charset=utf-8"),
00648                 ])
00649             return [b"data"]
00650 
00651         h = TestHandler()
00652         h.run(app)
00653         self.assertEqual(b"Status: 200 OK\r\n"
00654             b"Content-Type: text/plain; charset=utf-8\r\n"
00655             b"Content-Length: 4\r\n"
00656             b"\r\n"
00657             b"data",
00658             h.stdout.getvalue())
00659 
00660 # This epilogue is needed for compatibility with the Python 2.5 regrtest module

Here is the call graph for this function:

Definition at line 486 of file test_wsgiref.py.

00486 
00487     def testCGIEnviron(self):
00488         h = BaseCGIHandler(None,None,None,{})
00489         h.setup_environ()
00490         for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors':
00491             self.assertIn(key, h.environ)

Here is the call graph for this function:

Definition at line 508 of file test_wsgiref.py.

00508 
00509     def testContentLength(self):
00510         # Demo one reason iteration is better than write()...  ;)
00511 
00512         def trivial_app1(e,s):
00513             s('200 OK',[])
00514             return [e['wsgi.url_scheme'].encode('iso-8859-1')]
00515 
00516         def trivial_app2(e,s):
00517             s('200 OK',[])(e['wsgi.url_scheme'].encode('iso-8859-1'))
00518             return []
00519 
00520         def trivial_app3(e,s):
00521             s('200 OK',[])
00522             return ['\u0442\u0435\u0441\u0442'.encode("utf-8")]
00523 
00524         def trivial_app4(e,s):
00525             # Simulate a response to a HEAD request
00526             s('200 OK',[('Content-Length', '12345')])
00527             return []
00528 
00529         h = TestHandler()
00530         h.run(trivial_app1)
00531         self.assertEqual(h.stdout.getvalue(),
00532             ("Status: 200 OK\r\n"
00533             "Content-Length: 4\r\n"
00534             "\r\n"
00535             "http").encode("iso-8859-1"))
00536 
00537         h = TestHandler()
00538         h.run(trivial_app2)
00539         self.assertEqual(h.stdout.getvalue(),
00540             ("Status: 200 OK\r\n"
00541             "\r\n"
00542             "http").encode("iso-8859-1"))
00543 
00544         h = TestHandler()
00545         h.run(trivial_app3)
00546         self.assertEqual(h.stdout.getvalue(),
00547             b'Status: 200 OK\r\n'
00548             b'Content-Length: 8\r\n'
00549             b'\r\n'
00550             b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82')
00551 
00552         h = TestHandler()
00553         h.run(trivial_app4)
00554         self.assertEqual(h.stdout.getvalue(),
00555             b'Status: 200 OK\r\n'
00556             b'Content-Length: 12345\r\n'
00557             b'\r\n')

Here is the call graph for this function:

Definition at line 479 of file test_wsgiref.py.

00479 
00480     def testEnviron(self):
00481         h = TestHandler(X="Y")
00482         h.setup_environ()
00483         self.checkEnvironAttrs(h)
00484         self.checkOSEnviron(h)
00485         self.assertEqual(h.environ["X"],"Y")

Here is the call graph for this function:

Definition at line 586 of file test_wsgiref.py.

00586 
00587     def testErrorAfterOutput(self):
00588         MSG = b"Some output has been sent"
00589         def error_app(e,s):
00590             s("200 OK",[])(MSG)
00591             raise AssertionError("This should be caught by handler")
00592 
00593         h = ErrorHandler()
00594         h.run(error_app)
00595         self.assertEqual(h.stdout.getvalue(),
00596             ("Status: 200 OK\r\n"
00597             "\r\n".encode("iso-8859-1")+MSG))
00598         self.assertIn("AssertionError", h.stderr.getvalue())
00599 

Here is the call graph for this function:

Definition at line 600 of file test_wsgiref.py.

00600 
00601     def testHeaderFormats(self):
00602 
00603         def non_error_app(e,s):
00604             s('200 OK',[])
00605             return []
00606 
00607         stdpat = (
00608             r"HTTP/%s 200 OK\r\n"
00609             r"Date: \w{3}, [ 0123]\d \w{3} \d{4} \d\d:\d\d:\d\d GMT\r\n"
00610             r"%s" r"Content-Length: 0\r\n" r"\r\n"
00611         )
00612         shortpat = (
00613             "Status: 200 OK\r\n" "Content-Length: 0\r\n" "\r\n"
00614         ).encode("iso-8859-1")
00615 
00616         for ssw in "FooBar/1.0", None:
00617             sw = ssw and "Server: %s\r\n" % ssw or ""
00618 
00619             for version in "1.0", "1.1":
00620                 for proto in "HTTP/0.9", "HTTP/1.0", "HTTP/1.1":
00621 
00622                     h = TestHandler(SERVER_PROTOCOL=proto)
00623                     h.origin_server = False
00624                     h.http_version = version
00625                     h.server_software = ssw
00626                     h.run(non_error_app)
00627                     self.assertEqual(shortpat,h.stdout.getvalue())
00628 
00629                     h = TestHandler(SERVER_PROTOCOL=proto)
00630                     h.origin_server = True
00631                     h.http_version = version
00632                     h.server_software = ssw
00633                     h.run(non_error_app)
00634                     if proto=="HTTP/0.9":
00635                         self.assertEqual(h.stdout.getvalue(),b"")
00636                     else:
00637                         self.assertTrue(
00638                             re.match((stdpat%(version,sw)).encode("iso-8859-1"),
00639                                 h.stdout.getvalue()),
00640                             ((stdpat%(version,sw)).encode("iso-8859-1"),
00641                                 h.stdout.getvalue())
00642                         )

Here is the call graph for this function:

Definition at line 492 of file test_wsgiref.py.

00492 
00493     def testScheme(self):
00494         h=TestHandler(HTTPS="on"); h.setup_environ()
00495         self.assertEqual(h.environ['wsgi.url_scheme'],'https')
00496         h=TestHandler(); h.setup_environ()
00497         self.assertEqual(h.environ['wsgi.url_scheme'],'http')
00498 

Here is the call graph for this function:


The documentation for this class was generated from the following file: