Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
def test_simple_args():
xsd_type = xsd.ComplexType(
xsd.Sequence(
[xsd.Element("item_1", xsd.String()), xsd.Element("item_2", xsd.String())]
)
)
args = tuple(["value-1", "value-2"])
kwargs = {}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {"item_1": "value-1", "item_2": "value-2"}
def test_xsi():
org_type = xsd.Element(
"{https://tests.python-zeep.org/}original",
xsd.ComplexType(
xsd.Sequence(
[
xsd.Element("username", xsd.String()),
xsd.Element("password", xsd.String()),
]
)
),
)
alt_type = xsd.Element(
"{https://tests.python-zeep.org/}alternative",
xsd.ComplexType(
xsd.Sequence(
[
xsd.Element("username", xsd.String()),
xsd.Element("password", xsd.String()),
]
)
),
)
instance = alt_type(username="mvantellingen", password="geheim")
def test_simple_args_attributes():
xsd_type = xsd.ComplexType(
xsd.Sequence(
[xsd.Element("item_1", xsd.String()), xsd.Element("item_2", xsd.String())]
),
[xsd.Attribute("attr_1", xsd.String())],
)
args = tuple(["value-1", "value-2", "bla"])
kwargs = {}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {"item_1": "value-1", "item_2": "value-2", "attr_1": "bla"}
def test_simple_args_attributes_as_kwargs():
xsd_type = xsd.ComplexType(
xsd.Sequence(
[xsd.Element("item_1", xsd.String()), xsd.Element("item_2", xsd.String())]
),
[xsd.Attribute("attr_1", xsd.String())],
)
args = tuple(["value-1", "value-2"])
kwargs = {"attr_1": "bla"}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {"item_1": "value-1", "item_2": "value-2", "attr_1": "bla"}
def test_build_objects():
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.Group(
etree.QName("http://tests.python-zeep.org/", "groupie"),
xsd.Sequence(
[
xsd.Element(
etree.QName(
"http://tests.python-zeep.org/", "password"
),
xsd.String(),
)
]
),
),
]
)
def test_build_min_occurs_2_max_occurs_2():
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/", "item_1"),
xsd.String(),
),
xsd.Element(
etree.QName("http://tests.python-zeep.org/", "item_2"),
xsd.String(),
),
],
min_occurs=2,
max_occurs=2,
)
),
)
assert custom_type.signature()
elm = custom_type(
_value_1=[
def test_build_pare_other_order():
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(),
),
]
)
),
)
xml = load_xml(
"""
bar
foo
"""
)
def test_simple_kwargs():
xsd_type = xsd.ComplexType(
xsd.Sequence([
xsd.Element('item_1', xsd.String()),
xsd.Element('item_2', xsd.String())
]))
args = tuple([])
kwargs = {'item_1': 'value-1', 'item_2': 'value-2'}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {
'item_1': 'value-1',
'item_2': 'value-2',
}
xsd_type = xsd.ComplexType(
xsd.Sequence(
[
xsd.Choice(
[
xsd.Sequence(
[
xsd.Element("item_1", xsd.String()),
xsd.Element("item_2", xsd.String(), min_occurs=0),
]
),
xsd.Sequence(
[
xsd.Element("item_1", xsd.String()),
xsd.Element("item_2", xsd.String()),
xsd.Element("item_3", xsd.String()),
]
),
]
)
]
)
)
args = tuple([])
kwargs = {"item_1": "value-1"}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {"item_1": "value-1", "item_2": None, "item_3": None}