How to use the pyodata.v2.model.PolicyWarning 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())

    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_client.py View on Github external
responses.GET,
        "{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
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
def test_faulty_association_set(xml_builder_factory):
    """ Test NullAssociation being correctly assigned to invalid associations"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', """
        
           
                    
                    
            
        
       """)

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

    schema = metadata.build()
    assert isinstance(schema.association_set('toDataEntitySet'), NullAssociation)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.association_set('toDataEntitySet').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.'
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
"""

    # Test case 1. -> LocalDataProperty is faulty and ValueListProperty is valid
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', schema.format('---', value_list_property))
    xml = xml_builder.serialize()

    with pytest.raises(RuntimeError) as typ_ex_info:
        MetadataBuilder(xml).build()

    assert typ_ex_info.value.args[0] == 'ValueHelperParameter(Type) of ValueHelper(MasterEntity/Data) points to ' \
                                        'an non existing LocalDataProperty --- of EntityType(MasterEntity)'

    MetadataBuilder(xml, Config(
        default_error_policy=PolicyWarning()
    )).build()

    assert_logging_policy(mock_warning,
                          'RuntimeError',
                          'ValueHelperParameter(Type) of ValueHelper(MasterEntity/Data) points to '
                          'an non existing LocalDataProperty --- of EntityType(MasterEntity)'
                          )

    # Test case 2. -> LocalDataProperty is valid and ValueListProperty is faulty
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', schema.format(local_data_property, '---'))
    xml = xml_builder.serialize()

    with pytest.raises(RuntimeError) as typ_ex_info:
        MetadataBuilder(xml).build()