How to use the zeep.xsd.Element function in zeep

To help you get started, we’ve selected a few zeep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mvantellingen / python-zeep / tests / test_xsd_valueobjects.py View on Github external
def test_choice():
    xsd_type = xsd.ComplexType(
        xsd.Sequence([
            xsd.Choice([
                xsd.Element('item_1', xsd.String()),
                xsd.Element('item_2', xsd.String())
            ])
        ])
    )
    args = tuple([])
    kwargs = {'item_2': 'value-2'}
    result = valueobjects._process_signature(xsd_type, args, kwargs)
    assert result == {'item_1': None, 'item_2': 'value-2'}
github mvantellingen / python-zeep / tests / test_xsd_valueobjects.py View on Github external
def test_choice_sequences_no_match():
    xsd_type = xsd.ComplexType(
        xsd.Sequence([
            xsd.Choice([
                xsd.Sequence([
                    xsd.Element('item_1', xsd.String()),
                    xsd.Element('item_2', xsd.String())
                ]),
                xsd.Sequence([
                    xsd.Element('item_3', xsd.String()),
                    xsd.Element('item_4', xsd.String())
                ]),
            ])
        ])
    )
    args = tuple([])
    with pytest.raises(TypeError):
        kwargs = {'item_1': 'value-1', 'item_3': 'value-3'}
        valueobjects._process_signature(xsd_type, args, kwargs)
github mvantellingen / python-zeep / tests / test_xsd.py View on Github external
def test_create_node():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Sequence(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "username"),
                        xsd.String(),
                    ),
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "password"),
                        xsd.String(),
                    ),
                ]
            ),
            [xsd.Attribute("attr", xsd.String())],
        ),
    )

    # sequences
    obj = custom_type(username="foo", password="bar", attr="x")
github mvantellingen / python-zeep / tests / test_xsd_indicators_all.py View on Github external
def test_build_occurs_1():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.All(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_1"),
                        xsd.String(),
                    ),
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_2"),
                        xsd.String(),
                    ),
                ]
            )
        ),
    )
github mvantellingen / python-zeep / tests / test_xsd_valueobjects.py View on Github external
def test_pickle():
    xsd_type = xsd.ComplexType(
        xsd.Sequence(
            [xsd.Element("item_1", xsd.String()), xsd.Element("item_2", xsd.String())]
        )
    )

    obj = xsd_type(item_1="x", item_2="y")

    data = pickle.dumps(obj)
    obj_rt = pickle.loads(data)

    assert obj.item_1 == "x"
    assert obj.item_2 == "y"
    assert obj_rt.item_1 == "x"
    assert obj_rt.item_2 == "y"
github mvantellingen / python-zeep / tests / test_xsd_parse.py View on Github external
etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Sequence(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_1"),
                        xsd.String(),
                    ),
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_2"),
                        xsd.ComplexType(
                            xsd.Sequence(
                                [
                                    xsd.Choice(
                                        [
                                            xsd.Element(
                                                "{http://tests.python-zeep.org/}item_2a1",
                                                xsd.String(),
                                                min_occurs=0,
                                            ),
                                            xsd.Element(
                                                "{http://tests.python-zeep.org/}item_2a2",
                                                xsd.String(),
                                                min_occurs=0,
                                            ),
                                        ]
                                    ),
                                    xsd.Element(
                                        "{http://tests.python-zeep.org/}item_2b",
                                        xsd.String(),
                                    ),
                                ]
github mvantellingen / python-zeep / tests / test_xsd_valueobjects.py View on Github external
def test_choice_sequences_no_match_last():
    xsd_type = xsd.ComplexType(
        xsd.Sequence(
            [
                xsd.Choice(
                    [
                        xsd.Sequence(
                            [
                                xsd.Element("item_1", xsd.String()),
                                xsd.Element("item_2", xsd.String()),
                            ]
                        ),
                        xsd.Sequence(
                            [
                                xsd.Element("item_3", xsd.String()),
                                xsd.Element("item_4", xsd.String()),
                            ]
                        ),
                    ]
                )
            ]
        )
    )
    args = tuple([])
    with pytest.raises(TypeError):
        kwargs = {"item_2": "value-2", "item_4": "value-4"}
        valueobjects._process_signature(xsd_type, args, kwargs)
github mvantellingen / python-zeep / tests / test_xsd.py View on Github external
),
                        ]
                    ),
                    xsd.Choice(
                        [
                            xsd.Element(
                                etree.QName("http://tests.python-zeep.org/", "item_5"),
                                xsd.String(),
                            ),
                            xsd.Element(
                                etree.QName("http://tests.python-zeep.org/", "item_6"),
                                xsd.String(),
                            ),
                            xsd.Sequence(
                                [
                                    xsd.Element(
                                        etree.QName(
                                            "http://tests.python-zeep.org/", "item_7"
                                        ),
                                        xsd.String(),
                                    ),
                                    xsd.Element(
                                        etree.QName(
                                            "http://tests.python-zeep.org/", "item_8"
                                        ),
                                        xsd.String(),
                                    ),
                                ]
                            ),
                        ]
                    ),
                ]
github mvantellingen / python-zeep / src / zeep / wsdl / messages / mime.py View on Github external
)

            if message.element:
                self.body = message.element
            else:
                elm = xsd.Element(self.part_name, message.type)
                self.body = xsd.Element(
                    self.operation.name, xsd.ComplexType(xsd.Sequence([elm]))
                )
        else:
            children = []
            for name, message in self.abstract.parts.items():
                if message.element:
                    elm = message.element.clone(name)
                else:
                    elm = xsd.Element(name, message.type)
                children.append(elm)
            self.body = xsd.Element(
                self.operation.name, xsd.ComplexType(xsd.Sequence(children))
            )
github mvantellingen / python-zeep / src / zeep / helpers.py View on Github external
def create_xml_soap_map(values):
    """Create an http://xml.apache.org/xml-soap#Map value."""
    Map = xsd.ComplexType(
        xsd.Sequence(
            [xsd.Element("item", xsd.AnyType(), min_occurs=1, max_occurs="unbounded")]
        ),
        qname=etree.QName("{http://xml.apache.org/xml-soap}Map"),
    )

    KeyValueData = xsd.Element(
        "{http://xml.apache.org/xml-soap}KeyValueData",
        xsd.ComplexType(
            xsd.Sequence(
                [xsd.Element("key", xsd.AnyType()), xsd.Element("value", xsd.AnyType())]
            )
        ),
    )

    return Map(
        item=[
            KeyValueData(