Changeset 20
- Timestamp:
- 02/28/07 10:40:14 (2 years ago)
- Files:
-
- trunk/tgwebservices/controllers.py (modified) (1 diff)
- trunk/tgwebservices/tests/fixtures.py (modified) (1 diff)
- trunk/tgwebservices/tests/test_xml.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tgwebservices/controllers.py
r19 r20 226 226 227 227 def newfunc(self, **kw): 228 request = cherrypy.request 228 229 if "xml_body" in kw and len(kw) == 1: 229 230 body = kw.pop("xml_body") 231 kw = _handle_xml_params(body, input_types) 232 elif request.headers.get("Content-Type", "") \ 233 .startswith("text/xml"): 234 try: 235 clen = int(request.headers.get('Content-Length')) or 0 236 data = request.body.read(clen) 237 body = et.fromstring(data) 238 except SyntaxError: 239 raise validators.Invalid("Request XML is invalid", "", 240 None) 230 241 kw = _handle_xml_params(body, input_types) 231 242 else: trunk/tgwebservices/tests/fixtures.py
r1 r20 87 87 def getcomprop(self): 88 88 return ComplexProperty() 89 90 @wsexpose(FancyValue) 91 @wsvalidate(FancyValue) 92 def tenyearsolder(self, person): 93 person.age = person.age + 10 94 return person 89 95 90 96 class InnerService(WebServicesController): trunk/tgwebservices/tests/test_xml.py
r1 r20 1 1 """Tests for HTTP+XML services""" 2 3 import cStringIO as StringIO 2 4 3 5 import cherrypy … … 18 20 print output 19 21 assert output == """<result><faultcode>Client</faultcode><faultstring>foo is not a valid parameter (valid values are: ['value'])</faultstring></result>""" 22 23 def test_complex_input(): 24 cherrypy.root = ComplexService("http://foo.bar.baz/") 25 request = """<request> 26 <person><name>Fred</name><age>22</age></person> 27 </request>""" 28 testutil.create_request("/tenyearsolder", rfile=StringIO.StringIO(request), 29 method="POST", 30 headers={"Content-Length" : str(len(request)), 31 "Content-Type" : 32 "text/xml; charset=utf-8"}) 33 output = cherrypy.response.body[0] 34 print output 35 assert output == """<result><age>32</age><computed>Hello!</computed>""" \ 36 """<name>Fred</name></result>"""
