Skip to content

Commit

Permalink
add test and fix for issue #126
Browse files Browse the repository at this point in the history
  • Loading branch information
Matula authored and filak-sap committed Oct 15, 2021
1 parent 5731a4c commit 21a99b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyodata/v2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,12 @@ def build(self):
raise TypeError(f'Expected bytes or str type on metadata_xml, got : {type(self._xml)}')

namespaces = self._config.namespaces
xml = etree.parse(mdf)

try:
xml = etree.parse(mdf)
except etree.XMLSyntaxError as ex:
raise PyODataParserError('Metadata document syntax error') from ex

edmx = xml.getroot()

try:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_model_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,3 +1449,17 @@ def test_struct_type_has_property_yes():
struct_type._properties['proprty'] = 'ugly test hack'

assert struct_type.has_proprty('proprty')

def test_invalid_xml(xml_builder_factory):
"""Test for invalid XML"""
xml_builder = xml_builder_factory()
xml_builder.add_schema('Test', """
<EntityType Name="C_AssetTPType" sap:label="Asset" sap:content-version="1">
<Property Name="IN_AssetIsResearchAndDev" Type="Edm.String" sap:label="R & D Asset" sap:quickinfo="India: R & D Asset"/>
</EntityType>
""")
xml = xml_builder.serialize()

with pytest.raises(PyODataParserError) as e_info:
MetadataBuilder(xml).build()
assert str(e_info.value) == 'Metadata document syntax error'

0 comments on commit 21a99b5

Please sign in to comment.