How to use the pyodata.exceptions.PyODataException function in pyodata

To help you get started, we’ve selected a few pyodata 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 SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_complex_serializer(schema):
    """Test de/serializer of complex edm types"""

    # pylint: disable=redefined-outer-name

    # encode without edm type information
    with pytest.raises(PyODataException) as e_info:
        EdmStructTypeSerializer().to_literal(None, 'something')
    assert str(e_info.value).startswith('Cannot encode value something')

    # decode without edm type information
    with pytest.raises(PyODataException) as e_info:
        EdmStructTypeSerializer().from_json(None, 'something')
    assert str(e_info.value).startswith('Cannot decode value something')

    # entity without properties
    entity_type = EntityType('Box', 'Box', False)
    srl = EdmStructTypeSerializer()
    assert srl.to_literal(entity_type, 'something') == {}
    assert srl.from_json(entity_type, 'something') == {}

    # entity with properties of ODATA primitive types
    entity_type = schema.entity_type('TemperatureMeasurement')
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_complex_serializer(schema):
    """Test de/serializer of complex edm types"""

    # pylint: disable=redefined-outer-name

    # encode without edm type information
    with pytest.raises(PyODataException) as e_info:
        EdmStructTypeSerializer().to_literal(None, 'something')
    assert str(e_info.value).startswith('Cannot encode value something')

    # decode without edm type information
    with pytest.raises(PyODataException) as e_info:
        EdmStructTypeSerializer().from_json(None, 'something')
    assert str(e_info.value).startswith('Cannot decode value something')

    # entity without properties
    entity_type = EntityType('Box', 'Box', False)
    srl = EdmStructTypeSerializer()
    assert srl.to_literal(entity_type, 'something') == {}
    assert srl.from_json(entity_type, 'something') == {}

    # entity with properties of ODATA primitive types
    entity_type = schema.entity_type('TemperatureMeasurement')
    assert srl.to_literal(entity_type, {'ignored-key': 'ignored-value', 'Sensor': 'x'}) == {'Sensor': "'x'"}
    assert srl.from_json(entity_type, {'ignored-key': 'ignored-value', 'Sensor': "'x'"}) == {'Sensor': 'x'}
github SAP / python-pyodata / pyodata / v2 / service.py View on Github external
representation.
        """

        if isinstance(entity, list):
            return [EntityCreateRequest._build_values(entity_type, item) for item in entity]

        values = {}
        for key, val in entity.items():
            try:
                val = entity_type.proprty(key).typ.traits.to_json(val)
            except KeyError:
                try:
                    nav_prop = entity_type.nav_proprty(key)
                    val = EntityCreateRequest._build_values(nav_prop.typ, val)
                except KeyError:
                    raise PyODataException('Property {} is not declared in {} entity type'.format(
                        key, entity_type.name))

            values[key] = val

        return values
github SAP / python-pyodata / pyodata / v2 / service.py View on Github external
def parameter(self, name, value):
        '''Sets value of parameter.'''

        # check if param is valid (is declared in metadata)
        try:
            param = self._function_import.get_parameter(name)

            # add parameter as custom query argument
            self.custom(param.name, param.typ.traits.to_literal(value))
        except KeyError:
            raise PyODataException('Function import {0} does not have pararmeter {1}'
                                   .format(self._function_import.name, name))

        return self
github SAP / python-pyodata / pyodata / exceptions.py View on Github external
"""PyOData exceptions hierarchy"""


class PyODataException(Exception):
    """Base class for all PyOData exceptions

       Raised when an error is detected that does not fall in any of the other categories.
    """


class PyODataModelError(PyODataException):
    """Raised when model error occurs"""


class PyODataParserError(PyODataException):
    """Raised when parser error occurs"""


class ExpressionError(PyODataException):
    """Raise when runtime logical expression error occurs"""


class HttpError(PyODataException):
    """Raised when unexpected HTTP status code is received """

    VendorType = None

    def __new__(cls, message, response):
        if HttpError.VendorType is not None:
            return super(HttpError, cls).__new__(HttpError.VendorType, message, response)
github SAP / python-pyodata / pyodata / exceptions.py View on Github external
class PyODataException(Exception):
    """Base class for all PyOData exceptions

       Raised when an error is detected that does not fall in any of the other categories.
    """


class PyODataModelError(PyODataException):
    """Raised when model error occurs"""


class PyODataParserError(PyODataException):
    """Raised when parser error occurs"""


class ExpressionError(PyODataException):
    """Raise when runtime logical expression error occurs"""


class HttpError(PyODataException):
    """Raised when unexpected HTTP status code is received """

    VendorType = None

    def __new__(cls, message, response):
        if HttpError.VendorType is not None:
            return super(HttpError, cls).__new__(HttpError.VendorType, message, response)

        return super(HttpError, cls).__new__(cls, message, response)

    def __init__(self, message, response):
        super(HttpError, self).__init__(message)
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def from_json(edm_type, value):

        # pylint: disable=no-self-use
        if not edm_type:
            raise PyODataException('Cannot decode value {} without complex type information'.format(value))

        result = {}
        for type_prop in edm_type.proprties():
            if type_prop.name in value:
                result[type_prop.name] = type_prop.typ.traits.from_json(value[type_prop.name])

        return result
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def __getattr__(self, item):
        member = next(filter(lambda x: x.name == item, self._member), None)
        if member is None:
            raise PyODataException(f'EnumType {self} has no member {item}')

        return member
github SAP / python-pyodata / pyodata / exceptions.py View on Github external
"""PyOData exceptions hierarchy"""


class PyODataException(Exception):
    """Base class for all PyOData exceptions

       Raised when an error is detected that does not fall in any of the other categories.
    """


class PyODataModelError(PyODataException):
    """Raised when model error occurs"""


class PyODataParserError(PyODataException):
    """Raised when parser error occurs"""


class ExpressionError(PyODataException):
    """Raise when runtime logical expression error occurs"""


class HttpError(PyODataException):
    """Raised when unexpected HTTP status code is received """

    VendorType = None