How to use the pyodata.v2.model.NullType 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
metadata = MetadataBuilder(
        xml_builder.serialize(),
        config=Config(
            default_error_policy=PolicyIgnore()
        ))

    schema = metadata.build()

    type_info = TypeInfo(namespace=None, name='MasterProperty', is_collection=False)
    assert isinstance(schema.get_type(type_info).proprty('Key').typ, NullType)

    type_info = TypeInfo(namespace=None, name='MasterEnum', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    type_info = TypeInfo(namespace=None, name='MasterComplex', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    type_info = TypeInfo(namespace=None, name='MasterEntity', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.get_type(type_info).Any
    assert typ_ex_info.value.args[0] == f'Cannot access this type. An error occurred during parsing type ' \
                          f'stated in xml({schema.get_type(type_info).name}) was not found, therefore it has been ' \
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
""")

    metadata = MetadataBuilder(
        xml_builder.serialize(),
        config=Config(
            default_error_policy=PolicyIgnore()
        ))

    schema = metadata.build()

    type_info = TypeInfo(namespace=None, name='MasterProperty', is_collection=False)
    assert isinstance(schema.get_type(type_info).proprty('Key').typ, NullType)

    type_info = TypeInfo(namespace=None, name='MasterEnum', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    type_info = TypeInfo(namespace=None, name='MasterComplex', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    type_info = TypeInfo(namespace=None, name='MasterEntity', is_collection=False)
    assert isinstance(schema.get_type(type_info), NullType)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.get_type(type_info).Any
    assert typ_ex_info.value.args[0] == f'Cannot access this type. An error occurred during parsing type ' \
                          f'stated in xml({schema.get_type(type_info).name}) was not found, therefore it has been ' \
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
for stype in itertools.chain(schema.entity_types, schema.complex_types):
            if isinstance(stype, NullType):
                continue

            if stype.kind == Typ.Kinds.Complex:
                # skip collections (no need to assign any types since type of collection
                # items is resolved separately
                if stype.is_collection:
                    continue

                for prop in stype.proprties():
                    try:
                        prop.typ = schema.get_type(prop.type_info)
                    except PyODataModelError as ex:
                        config.err_policy(ParserError.PROPERTY).resolve(ex)
                        prop.typ = NullType(prop.type_info.name)

        # pylint: disable=too-many-nested-blocks
        # Then, process Associations nodes because they refer EntityTypes and
        # they are referenced by AssociationSets.
        for schema_node in schema_nodes:
            namespace = schema_node.get('Namespace')
            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
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
for complex_type in schema_node.xpath('edm:ComplexType', namespaces=config.namespaces):
                try:
                    ctype = ComplexType.from_etree(complex_type, config)
                except (KeyError, AttributeError) as ex:
                    config.err_policy(ParserError.COMPLEX_TYPE).resolve(ex)
                    ctype = NullType(complex_type.get('Name'))

                decl.add_complex_type(ctype)

            for entity_type in schema_node.xpath('edm:EntityType', namespaces=config.namespaces):
                try:
                    etype = EntityType.from_etree(entity_type, config)
                except (KeyError, AttributeError) as ex:
                    config.err_policy(ParserError.ENTITY_TYPE).resolve(ex)
                    etype = NullType(entity_type.get('Name'))

                decl.add_entity_type(etype)

        # resolve types of properties
        for stype in itertools.chain(schema.entity_types, schema.complex_types):
            if isinstance(stype, NullType):
                continue

            if stype.kind == Typ.Kinds.Complex:
                # skip collections (no need to assign any types since type of collection
                # items is resolved separately
                if stype.is_collection:
                    continue

                for prop in stype.proprties():
                    try:
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
for enum_type in schema_node.xpath('edm:EnumType', namespaces=config.namespaces):
                try:
                    etype = EnumType.from_etree(enum_type, namespace, config)
                except (PyODataParserError, AttributeError) as ex:
                    config.err_policy(ParserError.ENUM_TYPE).resolve(ex)
                    etype = NullType(enum_type.get('Name'))

                decl.add_enum_type(etype)

            for complex_type in schema_node.xpath('edm:ComplexType', namespaces=config.namespaces):
                try:
                    ctype = ComplexType.from_etree(complex_type, config)
                except (KeyError, AttributeError) as ex:
                    config.err_policy(ParserError.COMPLEX_TYPE).resolve(ex)
                    ctype = NullType(complex_type.get('Name'))

                decl.add_complex_type(ctype)

            for entity_type in schema_node.xpath('edm:EntityType', namespaces=config.namespaces):
                try:
                    etype = EntityType.from_etree(entity_type, config)
                except (KeyError, AttributeError) as ex:
                    config.err_policy(ParserError.ENTITY_TYPE).resolve(ex)
                    etype = NullType(entity_type.get('Name'))

                decl.add_entity_type(etype)

        # resolve types of properties
        for stype in itertools.chain(schema.entity_types, schema.complex_types):
            if isinstance(stype, NullType):
                continue
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
'Role {} was not defined in association {}'.format(dependent_role.name, assoc.name))

                        # Check if dependent role properties exist
                        role_name = dependent_role.name
                        entity_type_name = assoc.end_by_role(role_name).entity_type_name
                        schema.check_role_property_names(dependent_role, entity_type_name, namespace)
                except (PyODataModelError, RuntimeError) as ex:
                    config.err_policy(ParserError.ASSOCIATION).resolve(ex)
                    decl.associations[assoc.name] = NullAssociation(assoc.name)
                else:
                    decl.associations[assoc.name] = assoc

        # resolve navigation properties
        for stype in schema.entity_types:
            # skip null type
            if isinstance(stype, NullType):
                continue

            # skip collections
            if stype.is_collection:
                continue

            for nav_prop in stype.nav_proprties:
                try:
                    assoc = schema.association(nav_prop.association_info.name, nav_prop.association_info.namespace)
                    nav_prop.association = assoc
                except KeyError as ex:
                    config.err_policy(ParserError.ASSOCIATION).resolve(ex)
                    nav_prop.association = NullAssociation(nav_prop.association_info.name)

        # Then, process EntitySet, FunctionImport and AssociationSet nodes.
        for schema_node in schema_nodes:
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
# Parse Schema nodes by parts to get over the problem of not-yet known
        # entity types referenced by entity sets, function imports and
        # annotations.

        # First, process EnumType, EntityType and ComplexType nodes. They have almost no dependencies on other elements.
        for schema_node in schema_nodes:
            namespace = schema_node.get('Namespace')
            decl = Schema.Declaration(namespace)
            schema._decls[namespace] = decl

            for enum_type in schema_node.xpath('edm:EnumType', namespaces=config.namespaces):
                try:
                    etype = EnumType.from_etree(enum_type, namespace, config)
                except (PyODataParserError, AttributeError) as ex:
                    config.err_policy(ParserError.ENUM_TYPE).resolve(ex)
                    etype = NullType(enum_type.get('Name'))

                decl.add_enum_type(etype)

            for complex_type in schema_node.xpath('edm:ComplexType', namespaces=config.namespaces):
                try:
                    ctype = ComplexType.from_etree(complex_type, config)
                except (KeyError, AttributeError) as ex:
                    config.err_policy(ParserError.COMPLEX_TYPE).resolve(ex)
                    ctype = NullType(complex_type.get('Name'))

                decl.add_complex_type(ctype)

            for entity_type in schema_node.xpath('edm:EntityType', namespaces=config.namespaces):
                try:
                    etype = EntityType.from_etree(entity_type, config)
                except (KeyError, AttributeError) as ex: