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_exception_raised_if_bad_data():
"""Verifies SerializationException is raised when trying to serialize bad data"""
data = "We can't serialize this"
serializer = XMLSerializer()
with pytest.raises(SerializationException):
serializer.serialize(data=data)
def test_xml_serializer():
"""Verifies that data is correctly serialized to XML"""
data = {"action": "add", "article": [{"idArticle": 666, "amount": 2}, {"idArticle": 101, "amount": 5}]}
serializer = XMLSerializer()
serialized_data = serializer.serialize(data=data)
assert '\n' in serialized_data
assert "2" in serialized_data
assert "666" in serialized_data
assert "5" in serialized_data
assert "101" in serialized_data
assert "add" in serialized_data
assert "" in serialized_data
def resolve(self, api_map=None, data=None, params=None, auth=None, **kwargs):
"""
Params:
`api_map`: Dict with urls and methods for the request
`data`: Data sent to MKM in PUT, POST and DELETE requests
`kwargs`: Optional additional parameters to be attached to the url
Return:
`response`: Returns the response received from the server
"""
self.setup(api_map=api_map, **kwargs)
if isinstance(data, dict):
serializer = XMLSerializer()
data = serializer.serialize(data=data)
return self.api.request(url=self.url, method=self.method, data=data, params=params, auth_params=auth)