How to use the pyodata.exceptions.PyODataModelError 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
assert typ.traits.to_literal(23) == '23L'
    assert typ.traits.from_literal('345L') == 345
    assert typ.traits.from_json('345L') == 345
    assert typ.traits.from_literal('345') == 345
    assert typ.traits.from_json('345') == 345
    assert typ.traits.from_literal('0') == 0
    assert typ.traits.from_json('0') == 0
    assert typ.traits.from_literal('0L') == 0
    assert typ.traits.from_json('0L') == 0

    # GUIDs
    typ = Types.from_name('Edm.Guid')
    assert repr(typ.traits) == 'EdmPrefixedTypTraits'
    assert typ.traits.to_literal('000-0000') == "guid'000-0000'"
    assert typ.traits.from_literal("guid'1234-56'") == '1234-56'
    with pytest.raises(PyODataModelError) as e_info:
        typ.traits.from_literal("'1234-56'")
    assert str(e_info.value).startswith("Malformed value '1234-56' for primitive")
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
decl = schema._decls[namespace]

            for association in schema_node.xpath('edm:Association', namespaces=config.namespaces):
                assoc = Association.from_etree(association, config)
                try:
                    for end_role in assoc.end_roles:
                        try:
                            # search and assign entity type (it must exist)
                            if end_role.entity_type_info.namespace is None:
                                end_role.entity_type_info.namespace = namespace

                            etype = schema.entity_type(end_role.entity_type_info.name, end_role.entity_type_info.namespace)

                            end_role.entity_type = etype
                        except KeyError:
                            raise PyODataModelError(
                                f'EntityType {end_role.entity_type_info.name} does not exist in Schema '
                                f'Namespace {end_role.entity_type_info.namespace}')

                    if assoc.referential_constraint is not None:
                        role_names = [end_role.role for end_role in assoc.end_roles]
                        principal_role = assoc.referential_constraint.principal

                        # Check if the role was defined in the current association
                        if principal_role.name not in role_names:
                            raise RuntimeError(
                                'Role {} was not defined in association {}'.format(principal_role.name, assoc.name))

                        # Check if principal role properties exist
                        role_name = principal_role.name
                        entity_type_name = assoc.end_by_role(role_name).entity_type_name
                        schema.check_role_property_names(principal_role, entity_type_name, namespace)
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
try:
                                vh_type = schema.typ(annotation.proprty_entity_type_name,
                                                     namespace=annotation.element_namespace)
                            except KeyError:
                                raise RuntimeError(f'Target Type {annotation.proprty_entity_type_name} '
                                                   f'of {annotation} does not exist')

                            try:
                                target_proprty = vh_type.proprty(annotation.proprty_name)
                            except KeyError:
                                raise RuntimeError(f'Target Property {annotation.proprty_name} '
                                                   f'of {vh_type} as defined in {annotation} does not exist')

                            annotation.proprty = target_proprty
                            target_proprty.value_helper = annotation
                    except (RuntimeError, PyODataModelError) as ex:
                        config.err_policy(ParserError.ANNOTATION).resolve(ex)

        return schema
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def entity_type(self, value):

        if self._entity_type is not None:
            raise PyODataModelError('Cannot replace {0} of {1} to {2}'.format(self._entity_type, self, value))

        if value.name != self._entity_type_info.name:
            raise PyODataModelError('{0} cannot be the type of {1}'.format(value, self))

        self._entity_type = value
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def to_literal(self, value):
        """Convert python datetime representation to literal format

           None: this could be done also via formatting string:
           value.strftime('%Y-%m-%dT%H:%M:%S.%f')
        """

        if not isinstance(value, datetime.datetime):
            raise PyODataModelError(
                'Cannot convert value of type {} to literal. Datetime format is required.'.format(type(value)))

        # Sets timezone to none to avoid including timezone information in the literal form.
        return super(EdmDateTimeTypTraits, self).to_literal(value.replace(tzinfo=None).isoformat())
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def _check_scale_value(self):
        if self._scale > self._precision:
            raise PyODataModelError('Scale value ({}) must be less than or equal to precision value ({})'
                                    .format(self._scale, self._precision))
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def __getattr__(self, item):
        raise PyODataModelError('Cannot access this association. An error occurred during parsing '
                                'association metadata due to that annotation has been omitted.')
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def association(self, value):

        if self._association is not None:
            raise PyODataModelError('Cannot replace {0} of {1} to {2}'.format(self._association, self, value))

        if value.name != self._association_info.name:
            raise PyODataModelError('{0} cannot be the type of {1}'.format(value, self))

        self._association = value
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def check_role_property_names(self, role, entity_type_name, namespace):
        for proprty in role.property_names:
            try:
                entity_type = self.entity_type(entity_type_name, namespace)
            except KeyError:
                raise PyODataModelError('EntityType {} does not exist in Schema Namespace {}'
                                        .format(entity_type_name, namespace))
            try:
                entity_type.proprty(proprty)
            except KeyError:
                raise PyODataModelError('Property {} does not exist in {}'.format(proprty, entity_type.name))