def test_full_request_response(): service = Service("Boo", "http://boo") service.schema(xs.complexType("Foo")(xs.sequence()(xs.element("foo", xs.string, maxOccurs=xs.unbounded)))) @service.expose(xs.element("fooReq", "Foo"), "Foo") def foo(request): return {"foo": [r + "foo" for r in request.foo]} open("/tmp/wow.xml", "w").write(service.get_wsdl("http://localhost/")) cl = Client("some address", transport=DirectSudsTransport(service), cache=None) result = cl.service.foo(["one", "two"]) assert result == ["onefoo", "twofoo"]
def test_aliased_types_in_params(): service = Service("Boo", "http://boo") service.schema(xs.complexType(name="paramType")(xs.sequence()(xs.element("foo", xs.string)))) @service.expose(response=xs.string) def concat(param=xs.array("paramType")): return "".join(r.foo for r in param) open("/tmp/wow.xml", "w").write(service.get_wsdl("http://localhost/")) cl = Client("some address", transport=DirectSudsTransport(service), cache=None) result = cl.service.concat([{"foo": "boo"}, {"foo": "bar"}]) assert result == "boobar"
def test_complex_return_type(): service = Service("Boo", "http://boo") service.schema(xs.element("addResponse")(xs.cts(xs.element("foo", xs.string), xs.element("bar", xs.string)))) @service.expose def add(x=xs.int, y=xs.int): return {"foo": str(x + y), "bar": str(x - y)} # open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client("some address", transport=DirectSudsTransport(service), cache=None) result = cl.service.add("1", "10") assert result.foo == "11" assert result.bar == "-9"
def test_full_request_response(): service = Service('Boo', 'http://boo') service.schema( xs.complexType('Foo')(xs.sequence()(xs.element( 'foo', xs.string, maxOccurs=xs.unbounded)))) @service.expose(xs.element('fooReq', 'Foo'), 'Foo') def foo(request): return {'foo': [r + 'foo' for r in request.foo]} open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client('some address', transport=DirectSudsTransport(service), cache=None) result = cl.service.foo(['one', 'two']) assert result == ['onefoo', 'twofoo']
def test_aliased_types_in_params(): service = Service('Boo', 'http://boo') service.schema( xs.complexType(name='paramType')(xs.sequence()(xs.element( 'foo', xs.string)))) @service.expose(response=xs.string) def concat(param=xs.array('paramType')): return ''.join(r.foo for r in param) open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client('some address', transport=DirectSudsTransport(service), cache=None) result = cl.service.concat([{'foo': 'boo'}, {'foo': 'bar'}]) assert result == 'boobar'
def test_complex_return_type(): service = Service('Boo', 'http://boo') service.schema( xs.element('addResponse')(xs.cts(xs.element('foo', xs.string), xs.element('bar', xs.string)))) @service.expose def add(x=xs.int, y=xs.int): return {'foo': str(x + y), 'bar': str(x - y)} #open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client('some address', transport=DirectSudsTransport(service), cache=None) result = cl.service.add('1', '10') assert result.foo == '11' assert result.bar == '-9'
def test_header(): service = Service('Boo', 'http://boo') service.schema( xs.element('AuthHeader')(xs.cts(xs.element('what', xs.string)))) def auth(func): @service.header('AuthHeader') @service.wraps(func) def inner(request, *args): if request.header.what == 'auth': return func(*args) else: return 'blam' return inner @auth @service.expose(response=xs.string) def upper(string=xs.string): return string.upper() #open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client('some address', transport=DirectSudsTransport(service), cache=None) token = cl.factory.create('AuthHeader') token.what = 'auth' cl.set_options(soapheaders=token) result = cl.service.upper('boo') assert result == 'BOO' token = cl.factory.create('AuthHeader') token.what = 'abracadabra' cl.set_options(soapheaders=token) result = cl.service.upper('boo') assert result == 'blam'
def test_header(): service = Service("Boo", "http://boo") service.schema(xs.element("AuthHeader")(xs.cts(xs.element("what", xs.string)))) def auth(func): @service.header("AuthHeader") @service.wraps(func) def inner(request, *args): if request.header.what == "auth": return func(*args) else: return "blam" return inner @auth @service.expose(response=xs.string) def upper(string=xs.string): return string.upper() # open('/tmp/wow.xml', 'w').write(service.get_wsdl('http://localhost/')) cl = Client("some address", transport=DirectSudsTransport(service), cache=None) token = cl.factory.create("AuthHeader") token.what = "auth" cl.set_options(soapheaders=token) result = cl.service.upper("boo") assert result == "BOO" token = cl.factory.create("AuthHeader") token.what = "abracadabra" cl.set_options(soapheaders=token) result = cl.service.upper("boo") assert result == "blam"