How to use the mkmsdk.exceptions.SerializationException function in mkmsdk

To help you get started, we’ve selected a few mkmsdk 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 evonove / mkm-sdk / tests / tests_unit / test_serializer.py View on Github external
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)
github evonove / mkm-sdk / tests / tests_unit / test_exception.py View on Github external
def test_serialization_exception():
    """Test error string is formatted correctly"""
    error = SerializationException("Something wrong with serialization")

    assert str(error) == "Serialization exception. Something wrong with serialization"
github evonove / mkm-sdk / mkmsdk / serializer.py View on Github external
def serialize(self, data):
        """
        Serializes data to XML so that it can be
        sent to backend, if data is not a dictionary
        raises a SerializationException

        Params:
            `data`: A dictionary containing the data to serialize

        Return:
            `xml`: Returns a string containing data serialized to XML
        """

        if not isinstance(data, dict):
            raise SerializationException("Can't serialize data, must be a dictionary.")

        stream = StringIO()
        self.generator = XMLGenerator(stream, "utf-8")

        self.generator.startDocument()
        self.generator.startElement("request", {})

        self._parse(data)

        self.generator.endElement("request")
        self.generator.endDocument()

        return stream.getvalue()