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_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_choice_sequences_no_match_nested():
xsd_type = xsd.ComplexType(
xsd.Sequence([
xsd.Choice([
xsd.Sequence([
xsd.Element('item_1', xsd.String()),
xsd.Element('item_2', xsd.String())
]),
])
])
)
args = tuple([])
kwargs = {'item_1': 'value-1'}
value = valueobjects._process_signature(xsd_type, args, kwargs)
assert value == {
'item_1': 'value-1',
'item_2': None,
}
def test_simple_mixed():
xsd_type = xsd.ComplexType(
xsd.Sequence([
xsd.Element('item_1', xsd.String()),
xsd.Element('item_2', xsd.String())
]))
args = tuple(['value-1'])
kwargs = {'item_2': 'value-2'}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {
'item_1': 'value-1',
'item_2': 'value-2',
}
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)
),
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)
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([])
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',
'item_3': None,
'item_4': None,
}
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_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_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'}
xsd_type = xsd.ComplexType(
xsd.Sequence(
[
xsd.Choice(
[
xsd.Element("item_1", xsd.String(), max_occurs=2),
xsd.Element("item_2", xsd.String()),
],
max_occurs=2,
)
]
)
)
args = tuple([])
kwargs = {"_value_1": [{"item_1": ["foo", "bar"]}, {"item_2": "bla"}]}
result = valueobjects._process_signature(xsd_type, args, kwargs)
assert result == {"_value_1": [{"item_1": ["foo", "bar"]}, {"item_2": "bla"}]}