"""Tests for HTTP+XML services""" import cStringIO as StringIO import cherrypy from turbogears import testutil from tgwebservices.tests.fixtures import * def test_simple(): cherrypy.root = MyService("http://foo.bar.baz") testutil.create_request("/times2?value=5") output = cherrypy.response.body[0] print output assert output == """10""" def test_xml_error(): testutil.create_request("/times2?value=5&foo=1") output = cherrypy.response.body[0] print output assert output == """Clientfoo is not a valid parameter (valid values are: ['value'])""" def test_complex_input(): cherrypy.root = ComplexService("http://foo.bar.baz/") request = """ Fred22 """ testutil.create_request("/tenyearsolder", rfile=StringIO.StringIO(request), method="POST", headers={"Content-Length" : str(len(request)), "Content-Type" : "text/xml; charset=utf-8"}) output = cherrypy.response.body[0] print output assert output == """32Hello!""" \ """Fred"""