How to use the pyodata.v2.model.MetadataBuilder 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_missing_association_for_navigation_property(xml_builder_factory):
    """ Test faulty aassociations on navigation property"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', """
           
               
               
           
       """)

    metadata = MetadataBuilder(xml_builder.serialize())

    with pytest.raises(KeyError) as typ_ex_info:
        metadata.build()
    assert typ_ex_info.value.args[0] == 'Association Followers does not exist in namespace EXAMPLE_SRV'
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
"""
    )

    metadata = MetadataBuilder(xml_builder.serialize())

    with pytest.raises(RuntimeError) as e_info:
        metadata.build()
    assert str(e_info.value) == 'Entity Set DataValueHelp for ValueHelper(Dict/Value) does not exist'

    metadata.config.set_custom_error_policy({
        ParserError.ANNOTATION: PolicyWarning()
    })

    metadata.build()
    assert_logging_policy(mock_warning,
                          'RuntimeError',
                          'Entity Set DataValueHelp for ValueHelper(Dict/Value) does not exist'
                          )
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_missing_schema(xml_builder_factory):
    """Test correct handling of missing Schema tag in xml"""

    xml_builder = xml_builder_factory()
    xml_builder.schema_is_enabled = False
    xml = xml_builder.serialize()

    try:
        MetadataBuilder(xml).build()
    except PyODataParserError as ex:
        assert str(ex) == 'Metadata document is missing the element Schema'
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_unsupported_enum_underlying_type(xml_builder_factory):
    """Test if parser will parse only allowed underlying types"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('Test', '')
    xml = xml_builder.serialize()

    try:
        MetadataBuilder(xml).build()
    except PyODataParserError as ex:
        assert str(ex).startswith(f'Type Edm.Bool is not valid as underlying type for EnumType - must be one of')
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_whitelisted_edm_namespace_2007_05(mock_from_etree, xml_builder_factory):
    """Test correct handling of whitelisted Microsoft's edm namespace"""

    xml_builder = xml_builder_factory()
    xml_builder.namespaces['edm'] = 'http://schemas.microsoft.com/ado/2007/05/edm'
    xml_builder.add_schema('', '')
    xml = xml_builder.serialize()

    MetadataBuilder(xml).build()
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_whitelisted_edm_namespace(mock_from_etree, xml_builder_factory):
    """Test correct handling of whitelisted Microsoft's edm namespace"""

    xml_builder = xml_builder_factory()
    xml_builder.namespaces['edm'] = 'http://schemas.microsoft.com/ado/2009/11/edm'
    xml_builder.add_schema('', '')
    xml = xml_builder.serialize()

    MetadataBuilder(xml).build()
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_namespace_whitelist(mock_from_etree, xml_builder_factory):
    """Test correct handling of whitelisted namespaces"""

    xml_builder = xml_builder_factory()
    xml_builder.namespaces['edmx'] = 'http://docs.oasis-open.org/odata/ns/edmx'
    xml_builder.namespaces['edm'] = 'http://docs.oasis-open.org/odata/ns/edm'
    xml_builder.add_schema('', '')
    xml = xml_builder.serialize()

    MetadataBuilder(xml).build()
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_missing_data_service(xml_builder_factory):
    """Test correct handling of missing DataService tag in xml"""

    xml_builder = xml_builder_factory()
    xml_builder.data_services_is_enabled = False
    xml = xml_builder.serialize()

    try:
        MetadataBuilder(xml).build()
    except PyODataParserError as ex:
        assert str(ex) == 'Metadata document is missing the element DataServices'
github SAP / python-pyodata / pyodata / client.py View on Github external
else:
                logger.info('Using static metadata')

            if config is not None and namespaces is not None:
                raise PyODataException('You cannot pass namespaces and config at the same time')

            if config is None:
                config = pyodata.v2.model.Config()

            if namespaces is not None:
                warnings.warn("Passing namespaces directly is deprecated. Use class Config instead", DeprecationWarning)
                config.namespaces = namespaces

            # create model instance from received metadata
            logger.info('Creating OData Schema (version: %d)', odata_version)
            schema = pyodata.v2.model.MetadataBuilder(metadata, config=config).build()

            # create service instance based on model we have
            logger.info('Creating OData Service (version: %d)', odata_version)
            service = pyodata.v2.service.Service(url, schema, connection)

            return service

        raise PyODataException('No implementation for selected odata version {}'.format(odata_version))