How to use the pyodata.v2.model.PolicyIgnore 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_client.py View on Github external
"{0}/$metadata".format(SERVICE_URL),
        content_type='application/xml',
        body=metadata,
        status=200)

    namespaces = {
        'edmx': "customEdmxUrl.com",
        'edm': 'customEdmUrl.com'
    }

    custom_config = Config(
        xml_namespaces=namespaces,
        default_error_policy=PolicyFatal(),
        custom_error_policies={
            ParserError.ANNOTATION: PolicyWarning(),
            ParserError.ASSOCIATION: PolicyIgnore()
        })

    with pytest.raises(PyODataException) as e_info:
        client = pyodata.Client(SERVICE_URL, requests, config=custom_config, namespaces=namespaces)

    assert str(e_info.value) == 'You cannot pass namespaces and config at the same time'

    client = pyodata.Client(SERVICE_URL, requests, namespaces=namespaces)

    mock_warning.assert_called_with(
        'Passing namespaces directly is deprecated. Use class Config instead',
        DeprecationWarning
    )
    assert isinstance(client, pyodata.v2.service.Service)
    assert client.schema.config.namespaces == namespaces
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_config_set_default_error_policy():
    """ Test configurability of policies """
    config = Config(
        custom_error_policies={
            ParserError.ANNOTATION: PolicyWarning()
        }
    )

    assert isinstance(config.err_policy(ParserError.ENTITY_TYPE), PolicyFatal)
    assert isinstance(config.err_policy(ParserError.ANNOTATION), PolicyWarning)

    config.set_default_error_policy(PolicyIgnore())

    assert isinstance(config.err_policy(ParserError.ENTITY_TYPE), PolicyIgnore)
    assert isinstance(config.err_policy(ParserError.ANNOTATION), PolicyIgnore)
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
"""
    )

    metadata = MetadataBuilder(xml_builder.serialize())

    with pytest.raises(RuntimeError) as typ_ex_info:
        metadata.build()
    assert typ_ex_info.value.args[0] == 'Target Property NoExisting of EntityType(Dict) as defined in ' \
                                        'ValueHelper(Dict/NoExisting) does not exist'

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

    metadata.build()
    assert PolicyIgnore.resolve is mock_resolve
    mock_resolve.assert_called_once()

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

    metadata.build()

    assert_logging_policy(mock_warning,
                          'RuntimeError',
                          'Target Property NoExisting of EntityType(Dict) as defined in ValueHelper(Dict/NoExisting)'
                          ' does not exist'
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)
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_config_set_default_error_policy():
    """ Test configurability of policies """
    config = Config(
        custom_error_policies={
            ParserError.ANNOTATION: PolicyWarning()
        }
    )

    assert isinstance(config.err_policy(ParserError.ENTITY_TYPE), PolicyFatal)
    assert isinstance(config.err_policy(ParserError.ANNOTATION), PolicyWarning)

    config.set_default_error_policy(PolicyIgnore())

    assert isinstance(config.err_policy(ParserError.ENTITY_TYPE), PolicyIgnore)
    assert isinstance(config.err_policy(ParserError.ANNOTATION), PolicyIgnore)
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()
    assert isinstance(schema.associations[0], NullAssociation)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.associations[0].Any
    assert typ_ex_info.value.args[0] == 'Cannot access this association. An error occurred during parsing ' \
                                        'association metadata due to that annotation has been omitted.'