Skip to content

Instantly share code, notes, and snippets.

@plq
Last active December 14, 2015 05:49
Show Gist options
  • Select an option

  • Save plq/5037952 to your computer and use it in GitHub Desktop.

Select an option

Save plq/5037952 to your computer and use it in GitHub Desktop.
spyne testcase
import suds
client = suds.client.Client("http://127.0.0.1:8080/?wsdl", cache=None)
result = client.service.test(6000.0)
print result
INFO:root:Spyne version: '2.9.3'
INFO:root:lxml version: '3.1.0'
INFO:root:Float constraints: lt: Decimal('Infinity') le: Decimal('Infinity') gt: Decimal('-Infinity') ge: Decimal('-Infinity')
INFO:root:Integer constraints: lt: Decimal('Infinity') le: Decimal('Infinity') gt: Decimal('-Infinity') ge: Decimal('-Infinity')
DEBUG:spyne.interface._base:populating '__main__.Test ({Test.Test}Test)' types...
DEBUG:spyne.interface._base: adding class "<class 'spyne.model.complex.test'>" for '{test}test'
DEBUG:spyne.interface._base: adding class "<class 'spyne.model.primitive.Float'>" for '{http://www.w3.org/2001/XMLSchema}float'
DEBUG:spyne.interface._base: adding class "<class 'spyne.model.complex.testResponse'>" for '{test}testResponse'
DEBUG:spyne.interface._base: adding class "<class 'spyne.model.primitive.Integer'>" for '{http://www.w3.org/2001/XMLSchema}integer'
DEBUG:spyne.interface._base:populating '__main__.Test' methods...
DEBUG:spyne.interface._base: adding method 'test' to match '{test}test' tag.
DEBUG:spyne.interface._base:From this point on, you're not supposed to make any changes to the class & method structure of the exposed services.
DEBUG:spyne.interface.xml_schema._base:generating schema for targetNamespace='test', prefix: 'tns' in dir '/tmp/.private/plq/tmpVfnw8x'
DEBUG:spyne.interface.xml_schema._base:writing '/tmp/.private/plq/tmpVfnw8x/tns.xsd' for ns test
DEBUG:spyne.interface.xml_schema._base:building schema...
DEBUG:spyne.interface.xml_schema._base:schema <lxml.etree.XMLSchema object at 0x115a6e0> built, cleaning up...
DEBUG:spyne.interface.xml_schema._base:removed '/tmp/.private/plq/tmpVfnw8x'
DEBUG:spyne.interface.xml_schema._base:generating schema for targetNamespace='test', prefix: 'tns' in dir '/tmp/.private/plq/tmpzIQN4B'
DEBUG:spyne.interface.xml_schema._base:writing '/tmp/.private/plq/tmpzIQN4B/tns.xsd' for ns test
DEBUG:spyne.interface.xml_schema._base:building schema...
DEBUG:spyne.interface.xml_schema._base:schema <lxml.etree.XMLSchema object at 0x115e910> built, cleaning up...
DEBUG:spyne.interface.xml_schema._base:removed '/tmp/.private/plq/tmpzIQN4B'
DEBUG:spyne.util.appreg:Registering <spyne.application.Application object at 0x115d810> as ('test', 'Application')
comet.in.arskom.com.tr - - [26/Feb/2013 14:16:32] "GET /?wsdl HTTP/1.1" 200 2189
DEBUG:spyne.protocol.xml:Method request string: {test}test
DEBUG:spyne.protocol.xml:<SOAP-ENV:Envelope xmlns:ns0="test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:test>
<ns0:quota>6000.0</ns0:quota>
</ns0:test>
</ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:spyne.protocol.soap.soap11:Response <?xml version='1.0' encoding='ASCII'?>
<senv:Envelope xmlns:tns="test" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Body>
<tns:testResponse>
<tns:testResult>10</tns:testResult>
</tns:testResponse>
</senv:Body>
</senv:Envelope>
comet.in.arskom.com.tr - - [26/Feb/2013 14:16:32] "POST / HTTP/1.1" 200 237
listening on: http://127.0.0.1:8080/
WSDL: http://127.0.0.1:8080/?wsdl
Traceback (most recent call last):
File "server.py", line 53, in <module>
server.serve_forever()
File "/usr/lib64/python2.7/SocketServer.py", line 225, in serve_forever
r, w, e = select.select([self], [], [], poll_interval)
KeyboardInterrupt
import pkg_resources
import spyne
from spyne.service import ServiceBase
from spyne.decorator import rpc
from spyne.model.primitive import *
from spyne.model.complex import *
class Test(ServiceBase):
@rpc(Float, _returns=Integer)
def test(ctx, quota):
return 10
if __name__ == "__main__":
from spyne.protocol.soap import Soap11
from spyne.application import Application
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("spyne.protocol.xml").setLevel(logging.DEBUG)
logging.info('Spyne version: %r' % spyne.__version__)
logging.info('lxml version: %r' % pkg_resources.get_distribution("lxml").version)
logging.info('Float constraints: lt: %r le: %r gt: %r ge: %r' % (
Float.Attributes.lt,
Float.Attributes.le,
Float.Attributes.gt,
Float.Attributes.ge,
))
logging.info('Integer constraints: lt: %r le: %r gt: %r ge: %r' % (
Integer.Attributes.lt,
Integer.Attributes.le,
Integer.Attributes.gt,
Integer.Attributes.ge,
))
app = Application([Test], "test", in_protocol=Soap11(validator="soft"), out_protocol=Soap11(cleanup_namespaces=True))
host = "127.0.0.1"
port = 8080
server = make_server(host, port, WsgiApplication(app))
print "listening on: http://%s:%s/" % (host, port)
print "WSDL: http://%s:%s/?wsdl" % (host, port)
server.serve_forever()
@azurit
Copy link

azurit commented Feb 26, 2013

DEBUG:spyne.interface._base:populating '__main__.test ({test.test}test)' types...
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.complex.test'>" for '{test}test'
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.primitive.Float'>" for '{http://www.w3.org/2001/XMLSchema}float'
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.complex.testResponse'>" for '{test}testResponse'   
DEBUG:spyne.interface._base:    adding class "<class 'spyne.model.primitive.Integer'>" for '{http://www.w3.org/2001/XMLSchema}integer'
DEBUG:spyne.interface._base:populating '__main__.test' methods...
DEBUG:spyne.interface._base:    adding method 'test' to match '{test}test' tag.
DEBUG:spyne.interface._base:From this point on, you're not supposed to make any changes to the class & method structure of the exposed services.
DEBUG:spyne.interface.xml_schema._base:generating schema for targetNamespace='test', prefix: 'tns' in dir '/tmp/tmp21up2i'
DEBUG:spyne.interface.xml_schema._base:writing '/tmp/tmp21up2i/tns.xsd' for ns test
DEBUG:spyne.interface.xml_schema._base:building schema...
DEBUG:spyne.interface.xml_schema._base:schema <lxml.etree.XMLSchema object at 0x8ade504> built, cleaning up...
DEBUG:spyne.interface.xml_schema._base:removed '/tmp/tmp21up2i'
DEBUG:spyne.interface.xml_schema._base:generating schema for targetNamespace='test', prefix: 'tns' in dir '/tmp/tmpr6qIPD'
DEBUG:spyne.interface.xml_schema._base:writing '/tmp/tmpr6qIPD/tns.xsd' for ns test
DEBUG:spyne.interface.xml_schema._base:building schema...
DEBUG:spyne.interface.xml_schema._base:schema <lxml.etree.XMLSchema object at 0x8ade694> built, cleaning up...
DEBUG:spyne.interface.xml_schema._base:removed '/tmp/tmpr6qIPD'
DEBUG:spyne.util.appreg:Registering <spyne.application.Application object at 0x8addfec> as ('test', 'Application')
listening on: http://127.0.0.1:8080/
WSDL: http://127.0.0.1:8080/?wsdl
localhost - - [26/Feb/2013 13:57:32] "GET /?wsdl HTTP/1.1" 200 2189
DEBUG:spyne.protocol.soap.soap11:ValueError(u'Unicode strings with encoding declaration are not supported.',) -- falling back to str decoding.
DEBUG:spyne.protocol.xml:Method request string: {test}test
DEBUG:spyne.protocol.xml:<SOAP-ENV:Envelope xmlns:ns0="test" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <ns1:Body>
    <ns0:test>
      <ns0:quota>6000.0</ns0:quota>
    </ns0:test>
  </ns1:Body>
</SOAP-ENV:Envelope>

ERROR:spyne.server._base:Fault(Client.ValidationError: 'The value "\'6000.0\'" could not be validated.')
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/server/_base.py", line 82, in get_in_object
    message=self.app.in_protocol.REQUEST)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/soap/soap11.py", line 252, in deserialize
    ctx.in_object = self.from_element(body_class, ctx.in_body_doc)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/_base.py", line 161, in from_element
    return handler(self, cls, element)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/model.py", line 64, in wrapper
    return func(prot, cls, element)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/model.py", line 234, in complex_from_element
    value = prot.from_element(member, c)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/_base.py", line 161, in from_element
    return handler(self, cls, element)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/model.py", line 64, in wrapper
    return func(prot, cls, element)
  File "/usr/local/lib/python2.6/dist-packages/spyne-2.9.3-py2.6.egg/spyne/protocol/xml/model.py", line 79, in base_from_element
    raise ValidationError(element.text)
ValidationError: Fault(Client.ValidationError: 'The value "\'6000.0\'" could not be validated.')
ERROR:spyne.server.wsgi:Fault(Client.ValidationError: 'The value "\'6000.0\'" could not be validated.')
DEBUG:spyne.protocol.soap.soap11:Response <?xml version='1.0' encoding='ASCII'?>
<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="test" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <senv:Body>
    <senv:Fault>
      <faultcode>senv:Client.ValidationError</faultcode>
      <faultstring>The value "'6000.0'" could not be validated.</faultstring>
      <faultactor></faultactor>
    </senv:Fault>
  </senv:Body>
</senv:Envelope>

localhost - - [26/Feb/2013 13:57:32] "POST / HTTP/1.1" 500 875

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment