예제 #1
0
def test_dict_instantiation_for_aliased_types():
    schema = xs.schema(Namespace('http://boo', 'boo'))(
        xs.complexType('Point')(xs.attribute('x', xs.int),
                                xs.attribute('y', xs.int)),
        xs.complexType('Vector')(xs.sequence()(xs.element('a', 'Point'),
                                               xs.element('b', 'Point'))),
        xs.element('Request')(xs.cts(
            xs.element('vector', 'Vector', minOccurs=0,
                       maxOccurs=xs.unbounded))),
    )

    request = schema['Request'].instance(vector=[{
        'a': {
            'x': 1,
            'y': 2
        },
        'b': {
            'x': 3,
            'y': 4
        }
    }])
    assert validate(schema, request)
    obj = schema.fromstring(tostring(request))
    assert obj.vector[0].a.x == 1
    assert obj.vector[0].a.y == 2
    assert obj.vector[0].b.x == 3
    assert obj.vector[0].b.y == 4
예제 #2
0
def test_simple_content():
    Request = xs.element('Request')(xs.complexType()(xs.simpleContent()(
        xs.extension(xs.string)(xs.attribute('lang', xs.string)))))

    schema = xs.schema(Namespace('http://boo', 'boo'))(Request, )

    request = Request.instance(value='message', lang='en')
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.value == 'message'
    assert obj.lang == 'en'
예제 #3
0
def test_attributes():
    Request = xs.element('Request')(xs.complexType()(xs.sequence()(xs.element(
        'x', xs.int)), xs.attribute('y', xs.int)))

    schema = xs.schema(Namespace('http://boo', 'boo'))(Request, )

    request = Request.instance(x=15, y=20)
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.x == 15
    assert obj.y == 20
예제 #4
0
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"]
예제 #5
0
def test_dict_instantiation_for_aliased_types():
    schema = xs.schema(Namespace('http://boo', 'boo'))(
        xs.complexType('Point')(
            xs.attribute('x', xs.int),
            xs.attribute('y', xs.int)),

        xs.complexType('Vector')(
            xs.sequence()(
                xs.element('a', 'Point'),
                xs.element('b', 'Point'))),

        xs.element('Request')(xs.cts(
            xs.element('vector', 'Vector', minOccurs=0, maxOccurs=xs.unbounded))),
    )

    request = schema['Request'].instance(vector=[{'a':{'x':1, 'y':2}, 'b':{'x':3, 'y':4}}])
    assert validate(schema, request)
    obj = schema.fromstring(tostring(request))
    assert obj.vector[0].a.x == 1
    assert obj.vector[0].a.y == 2
    assert obj.vector[0].b.x == 3
    assert obj.vector[0].b.y == 4
예제 #6
0
def test_type_aliases():
    schema = xs.schema(Namespace('http://boo',
                                 'boo'))(xs.complexType(name='fooType')(
                                     xs.sequence()(xs.element('x', xs.string),
                                                   xs.element('y', xs.int))),
                                         xs.element('Request')(xs.cts(
                                             xs.element('foo', 'fooType'))))

    request = schema['Request'].instance(foo={'x': 'boo', 'y': 100})
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.foo.x == 'boo'
    assert obj.foo.y == 100
예제 #7
0
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"
예제 #8
0
def test_attributes():
    Request = xs.element('Request')(
        xs.complexType()(
            xs.sequence()(
                xs.element('x', xs.int)),
            xs.attribute('y', xs.int)))

    schema = xs.schema(Namespace('http://boo', 'boo'))(
        Request,
    )

    request = Request.instance(x=15, y=20)
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.x == 15
    assert obj.y == 20
예제 #9
0
def test_type_aliases():
    schema = xs.schema(Namespace('http://boo', 'boo'))(
        xs.complexType(name='fooType')(
            xs.sequence()(
                xs.element('x', xs.string),
                xs.element('y', xs.int))),

        xs.element('Request')(xs.cts(
            xs.element('foo', 'fooType')))
    )

    request = schema['Request'].instance(foo={'x':'boo', 'y':100})
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.foo.x == 'boo'
    assert obj.foo.y == 100
예제 #10
0
def test_simple_content():
    Request = xs.element('Request')(
        xs.complexType()(
            xs.simpleContent()(
                xs.extension(xs.string)(
                    xs.attribute('lang', xs.string)))))

    schema = xs.schema(Namespace('http://boo', 'boo'))(
        Request,
    )

    request = Request.instance(value='message', lang='en')
    assert validate(schema, request)

    obj = schema.fromstring(tostring(request))
    assert obj.value == 'message'
    assert obj.lang == 'en'
예제 #11
0
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']
예제 #12
0
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'