How to use the pyodata.v2.model.EndRole 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_edmx_association_end_by_role():
    """Test the method end_by_role of the class Association"""

    end_from = EndRole(None, EndRole.MULTIPLICITY_ONE, 'From')
    end_to = EndRole(None, EndRole.MULTIPLICITY_ZERO_OR_ONE, 'To')

    association = Association('FooBar')
    association.end_roles.append(end_from)
    association.end_roles.append(end_to)

    assert association.end_by_role(end_from.role) == end_from
    assert association.end_by_role(end_to.role) == end_to

    with pytest.raises(KeyError) as typ_ex_info:
        association.end_by_role('Blah')
    assert typ_ex_info.value.args[0] == 'Association FooBar has no End with Role Blah'
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_edmx_association_end_by_role():
    """Test the method end_by_role of the class Association"""

    end_from = EndRole(None, EndRole.MULTIPLICITY_ONE, 'From')
    end_to = EndRole(None, EndRole.MULTIPLICITY_ZERO_OR_ONE, 'To')

    association = Association('FooBar')
    association.end_roles.append(end_from)
    association.end_roles.append(end_to)

    assert association.end_by_role(end_from.role) == end_from
    assert association.end_by_role(end_to.role) == end_to

    with pytest.raises(KeyError) as typ_ex_info:
        association.end_by_role('Blah')
    assert typ_ex_info.value.args[0] == 'Association FooBar has no End with Role Blah'
github SAP / python-pyodata / pyodata / v2 / service.py View on Github external
# entity type of navigation property
                    prop_etype = prop.to_role.entity_type

                    # cache value according to multiplicity
                    if prop.to_role.multiplicity in \
                            [model.EndRole.MULTIPLICITY_ONE,
                             model.EndRole.MULTIPLICITY_ZERO_OR_ONE]:

                        # cache None in case we receive nothing (null) instead of entity data
                        if proprties[prop.name] is None:
                            self._cache[prop.name] = None
                        else:
                            self._cache[prop.name] = EntityProxy(service, None, prop_etype, proprties[prop.name])

                    elif prop.to_role.multiplicity == model.EndRole.MULTIPLICITY_ZERO_OR_MORE:
                        # default value is empty array
                        self._cache[prop.name] = []

                        # if there are no entities available, received data consists of
                        # metadata properties only.
                        if 'results' in proprties[prop.name]:

                            # available entities are serialized in results array
                            for entity in proprties[prop.name]['results']:
                                self._cache[prop.name].append(EntityProxy(service, None, prop_etype, entity))
                    else:
                        raise PyODataException('Unknown multiplicity {0} of association role {1}'
                                               .format(prop.to_role.multiplicity, prop.to_role.name))

        # build entity key if not provided
        if self._entity_key is None:
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def from_etree(association_node, config: Config):
        name = association_node.get('Name')
        association = Association(name)

        for end in association_node.xpath('edm:End', namespaces=config.namespaces):
            end_role = EndRole.from_etree(end)
            if end_role.entity_type_info is None:
                raise RuntimeError('End type is not specified in the association {}'.format(name))
            association._end_roles.append(end_role)

        if len(association._end_roles) != 2:
            raise RuntimeError('Association {} does not have two end roles'.format(name))

        refer = association_node.xpath('edm:ReferentialConstraint', namespaces=config.namespaces)
        if len(refer) > 1:
            raise RuntimeError('In association {} is defined more than one referential constraint'.format(name))

        if not refer:
            referential_constraint = None
        else:
            referential_constraint = ReferentialConstraint.from_etree(refer[0], config)
github SAP / python-pyodata / pyodata / v2 / service.py View on Github external
# Get entity set of navigation property
        association_info = navigation_property.association_info
        association_set = self._service.schema.association_set_by_association(
            association_info.name)

        navigation_entity_set = None
        for end in association_set.end_roles:
            if association_set.end_by_entity_set(end.entity_set_name).role == navigation_property.to_role.role:
                navigation_entity_set = self._service.schema.entity_set(end.entity_set_name)

        if not navigation_entity_set:
            raise PyODataException(
                'No association set for role {} {}'.format(navigation_property.to_role, association_set.end_roles))

        roles = navigation_property.association.end_roles
        if all((role.multiplicity != model.EndRole.MULTIPLICITY_ZERO_OR_MORE for role in roles)):
            return self._get_nav_entity(key, nav_property, navigation_entity_set)

        return EntitySetProxy(
            self._service,
            navigation_entity_set,
            nav_property,
            self._entity_set.name + key.to_key_string())
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def from_etree(end_role_node):
        entity_type_info = Types.parse_type_name(end_role_node.get('Type'))
        multiplicity = end_role_node.get('Multiplicity')
        role = end_role_node.get('Role')

        return EndRole(entity_type_info, multiplicity, role)
github SAP / python-pyodata / pyodata / v2 / service.py View on Github external
else:
                        # null value is in literal form for now, convert it to python representation
                        self._cache[type_proprty.name] = type_proprty.typ.traits.from_literal(
                            type_proprty.typ.null_value)

            # then, assign all navigation properties
            for prop in self._entity_type.nav_proprties:

                if prop.name in proprties:

                    # entity type of navigation property
                    prop_etype = prop.to_role.entity_type

                    # cache value according to multiplicity
                    if prop.to_role.multiplicity in \
                            [model.EndRole.MULTIPLICITY_ONE,
                             model.EndRole.MULTIPLICITY_ZERO_OR_ONE]:

                        # cache None in case we receive nothing (null) instead of entity data
                        if proprties[prop.name] is None:
                            self._cache[prop.name] = None
                        else:
                            self._cache[prop.name] = EntityProxy(service, None, prop_etype, proprties[prop.name])

                    elif prop.to_role.multiplicity == model.EndRole.MULTIPLICITY_ZERO_OR_MORE:
                        # default value is empty array
                        self._cache[prop.name] = []

                        # if there are no entities available, received data consists of
                        # metadata properties only.
                        if 'results' in proprties[prop.name]: