Changeset 1377
- Timestamp:
- 09/26/06 01:06:21
- Files:
-
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/test_encoding.py (moved) (moved from trunk/cherrypy/test/test_decodingencoding.py) (5 diffs)
- trunk/cherrypy/test/test_gzip.py (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/test.py
r1350 r1377 334 334 'test_core', 335 335 'test_tools', 336 'test_ decodingencoding',336 'test_encoding', 337 337 'test_etags', 338 'test_gzip',339 338 'test_objectmapping', 340 339 'test_misc_tools', trunk/cherrypy/test/test_encoding.py
r1376 r1377 2 2 test.prefer_parent_path() 3 3 4 import gzip, StringIO 4 5 import cherrypy 5 6 europoundUnicode = u'\x80\xa3' 7 europoundUtf8 = u'\x80\xa3'.encode('utf-8') 6 8 sing = u"\u6bdb\u6cfd\u4e1c: Sing, Little Birdie?" 7 9 sing8 = sing.encode('utf-8') … … 19 21 return sing 20 22 mao_zedong.exposed = True 21 22 cherrypy.tree.mount(Root()) 23 24 class GZIP: 25 def index(self): 26 yield "Hello, world" 27 index.exposed = True 28 29 def noshow(self): 30 # Test for ticket #147, where yield showed no exceptions (content- 31 # encoding was still gzip even though traceback wasn't zipped). 32 raise IndexError() 33 yield "Here be dragons" 34 noshow.exposed = True 35 36 def noshow_stream(self): 37 # Test for ticket #147, where yield showed no exceptions (content- 38 # encoding was still gzip even though traceback wasn't zipped). 39 raise IndexError() 40 yield "Here be dragons" 41 noshow_stream.exposed = True 42 noshow_stream._cp_config = {'response.stream': True} 43 23 44 cherrypy.config.update({ 24 45 'environment': 'test_suite', … … 26 47 'tools.decode.on': True, 27 48 }) 49 50 root = Root() 51 root.gzip = GZIP() 52 cherrypy.tree.mount(root, config={'/gzip': {'tools.gzip.on': True}}) 53 28 54 29 55 … … 31 57 32 58 33 class DecodingEncodingTest(helper.CPWebCase):59 class EncodingTests(helper.CPWebCase): 34 60 35 def testDecoding Encoding(self):61 def testDecoding(self): 36 62 europoundUtf8 = europoundUnicode.encode('utf-8') 37 63 self.getPage('/?param=%s' % europoundUtf8) 38 64 self.assertBody(europoundUtf8) 39 65 66 def testEncoding(self): 40 67 # Default encoding should be utf-8 41 68 self.getPage('/mao_zedong') … … 70 97 "us-ascii, ISO-8859-1, x-mac-ce. We tried these " 71 98 "charsets: x-mac-ce, us-ascii, ISO-8859-1.") 99 100 def testGzip(self): 101 zbuf = StringIO.StringIO() 102 zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9) 103 zfile.write("Hello, world") 104 zfile.close() 72 105 106 self.getPage('/gzip/', headers=[("Accept-Encoding", "gzip")]) 107 self.assertInBody(zbuf.getvalue()[:3]) 108 self.assertHeader("Vary", "Accept-Encoding") 109 110 # Test when gzip is denied. 111 self.getPage('/gzip/', headers=[("Accept-Encoding", "identity")]) 112 self.assertNoHeader("Vary") 113 self.assertBody("Hello, world") 114 115 self.getPage('/gzip/', headers=[("Accept-Encoding", "gzip;q=0")]) 116 self.assertNoHeader("Vary") 117 self.assertBody("Hello, world") 118 119 self.getPage('/gzip/', headers=[("Accept-Encoding", "*;q=0")]) 120 self.assertStatus(406) 121 self.assertNoHeader("Vary") 122 self.assertErrorPage(406, "identity, gzip") 123 124 # Test for ticket #147 125 self.getPage('/gzip/noshow', headers=[("Accept-Encoding", "gzip")]) 126 self.assertNoHeader('Content-Encoding') 127 self.assertStatus(500) 128 self.assertErrorPage(500, pattern="IndexError\n") 129 130 # In this case, there's nothing we can do to deliver a 131 # readable page, since 1) the gzip header is already set, 132 # and 2) we may have already written some of the body. 133 # The fix is to never stream yields when using gzip. 134 self.getPage('/gzip/noshow_stream', 135 headers=[("Accept-Encoding", "gzip")]) 136 self.assertHeader('Content-Encoding', 'gzip') 137 self.assertMatchesBody(r"Unrecoverable error in the server.$") 138 73 139 74 140 if __name__ == "__main__":

