Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"{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
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)
"""
)
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'
""")
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)
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)
""")
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.'