コード例 #1
0
ファイル: test_schema.py プロジェクト: baverman/dropthesoap
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
ファイル: test_schema.py プロジェクト: baverman/dropthesoap
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
コード例 #3
0
ファイル: test_schema.py プロジェクト: baverman/dropthesoap
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'