コード例 #1
0
def test_sequence_parse_anytype_obj():
    value_type = xsd.ComplexType(
        xsd.Sequence([
            xsd.Element('{http://tests.python-zeep.org/}value', xsd.Integer()),
        ]))

    schema = Schema(
        etree.Element('{http://www.w3.org/2001/XMLSchema}Schema',
                      targetNamespace='http://tests.python-zeep.org/'))

    root = list(schema._schemas.values())[0]
    root.register_type('{http://tests.python-zeep.org/}something', value_type)

    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'container'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'item_1'),
                    xsd.AnyType()),
            ])))
    expected = etree.fromstring("""
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """)
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100
コード例 #2
0
def test_parse_anytype_obj():
    value_type = xsd.ComplexType(children=[
        xsd.Element('{http://tests.python-zeep.org/}value', xsd.Integer()),
    ])

    schema = xsd.Schema()
    schema.register_type('{http://tests.python-zeep.org/}something',
                         value_type)

    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'container'),
        xsd.ComplexType(children=[
            xsd.Element(etree.QName('http://tests.python-zeep.org/', 'item_1'),
                        xsd.AnyType()),
        ]))
    expected = etree.fromstring("""
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """)
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100
コード例 #3
0
ファイル: helpers.py プロジェクト: argotty2010/ClienteWSDL
def guess_xsd_type(obj):
    """Return the XSD Type for the given object"""
    if isinstance(obj, bool):
        return xsd.Boolean()
    if isinstance(obj, int):
        return xsd.Integer()
    if isinstance(obj, float):
        return xsd.Float()
    if isinstance(obj, datetime.datetime):
        return xsd.DateTime()
    if isinstance(obj, datetime.date):
        return xsd.Date()
    return xsd.String()
コード例 #4
0
def test_sequence_parse_anytype_obj():
    value_type = xsd.ComplexType(
        xsd.Sequence(
            [xsd.Element("{http://tests.python-zeep.org/}value", xsd.Integer())]
        )
    )

    schema = Schema(
        etree.Element(
            "{http://www.w3.org/2001/XMLSchema}Schema",
            targetNamespace="http://tests.python-zeep.org/",
        )
    )

    root = schema.root_document
    root.register_type("{http://tests.python-zeep.org/}something", value_type)

    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "container"),
        xsd.ComplexType(
            xsd.Sequence(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_1"),
                        xsd.AnyType(),
                    )
                ]
            )
        ),
    )
    expected = etree.fromstring(
        """
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """
    )
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100
コード例 #5
0
def test_sequence_parse_anytype_obj():
    value_type = xsd.ComplexType(
        xsd.Sequence([
            xsd.Element(
                '{http://tests.python-zeep.org/}value',
                xsd.Integer()),
        ])
    )

    parser_context = ParserContext()
    schema = SchemaDocument(
        etree.Element('{http://www.w3.org/2001/XMLSchema}Schema'),
        transport=None,
        location=None,
        parser_context=parser_context,
        base_url=None)

    schema._target_namespace = 'http://tests.python-zeep.org/'
    schema.register_type('{http://tests.python-zeep.org/}something', value_type)

    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'container'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'item_1'),
                    xsd.AnyType()),
            ])
        ))
    expected = etree.fromstring("""
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """)
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100