yield u"world" yield europoundUnicode index.exposed = True cherrypy.root = Root() cherrypy.config.update({ 'server.log_to_screen': False, 'server.environment': 'production', 'gzip_filter.on': True, 'encoding_filter.on': True, }) import helper class CombinedFiltersTest(helper.CPWebCase): def testCombinedFilters(self): expectedResult = (u"Hello,world" + europoundUnicode).encode('utf-8') zbuf = StringIO.StringIO() zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9) zfile.write(expectedResult) zfile.close() self.getPage("/", headers=[("Accept-Encoding", "gzip")]) self.assertInBody(zbuf.getvalue()[:3]) if __name__ == '__main__': setup_server() helper.testmain()
"server.socketHost": helper.CPWebCase.HOST, "server.socketPort": helper.CPWebCase.PORT, }, "/xmlrpc": {"xmlRpcFilter.on": True}, } ) class XmlRpcFilterTest(helper.CPWebCase): def testXmlRpcFilter(self): proxy = xmlrpclib.ServerProxy("http://localhost:%s/xmlrpc/" % (self.PORT)) self.assertEqual(proxy.return_single_item_list(), [42]) self.assertEqual(proxy.return_string(), "here is a string") self.assertEqual(proxy.return_tuple(), list(("here", "is", 1, "tuple"))) self.assertEqual(proxy.return_dict(), {"a": 1, "c": 3, "b": 2}) self.assertEqual(proxy.return_composite(), [{"a": 1, "z": 26}, "hi", ["welcome", "friend"]]) self.assertEqual(proxy.return_int(), 42) self.assertEqual(proxy.return_float(), 3.14) self.assertEqual(proxy.return_datetime(), xmlrpclib.DateTime((2003, 10, 7, 8, 1, 0, 1, 280, -1))) self.assertEqual(proxy.return_boolean(), True) self.assertEqual(proxy.test_argument_passing(22), 22 * 2) if __name__ == "__main__": from cherrypy import _cpwsgi serverClass = _cpwsgi.WSGIServer helper.testmain(serverClass)
# only the "final" index method should do so. self.getPage("/dir1/dir2/5/3/sir") self.assertBody("default for dir1, param is:('dir2', '5', '3', 'sir')") def testExpose(self): self.mount_point = mp # Test the cherrypy.expose function/decorator self.getPage("/exposing/base") self.assertBody("expose works!") self.getPage("/exposing/1") self.assertBody("expose works!") self.getPage("/exposing/2") self.assertBody("expose works!") self.getPage("/exposingnew/base") self.assertBody("expose works!") self.getPage("/exposingnew/1") self.assertBody("expose works!") self.getPage("/exposingnew/2") self.assertBody("expose works!") if __name__ == "__main__": helper.testmain(WSGIServer)