Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support EnumTypes that do not specify values #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion odata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,16 @@ def _parse_enumtype(self, xmlq, enumtype_element, schema_name):
'fully_qualified_name': '.'.join([schema_name, enum_name]),
'members': []
}
next_value = 0
for enum_member in xmlq(enumtype_element, 'edm:Member'):
member_name = enum_member.attrib['Name']
member_value = int(enum_member.attrib['Value'])
member_value = enum_member.attrib.get('Value', next_value)
member_value = int(member_value)
enum['members'].append({
'name': member_name,
'value': member_value,
})
next_value += 1
return enum

def parse_document(self, doc):
Expand Down
9 changes: 8 additions & 1 deletion odata/tests/demo_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Property Name="Category" Type="Edm.String"/>
<Property Name="Price" Type="Edm.Decimal"/>
<Property Name="ColorSelection" Type="d.ColorSelection"/>
<Property Name="ShippingRestriction" Type="d.ShippingRestriction"/>
<Property Name="ExampleComputed" Type="Edm.Int32">
<Annotation Term="Org.OData.Core.V1.Computed" Bool="true" />
</Property>
Expand All @@ -40,6 +41,12 @@
<Member Name="Blue" Value="2"/>
<Member Name="Green" Value="3"/>
</EnumType>
<EnumType Name="ShippingRestriction">
<Member Name="Unrestricted" />
<Member Name="Fragile" />
<Member Name="Heavy" />
<Member Name="Oversize" />
</EnumType>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="DemoService">
<Action Name="DemoAction" IsBound="true">
Expand Down Expand Up @@ -72,4 +79,4 @@
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
</edmx:Edmx>
6 changes: 6 additions & 0 deletions odata/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def test_read(self):

self.assertIn('DemoUnboundAction', Service.actions)

ColorSelection = Service.types['DemoService.Models.ColorSelection']
self.assertEqual(ColorSelection.Red.value, 1)
ShippingRestriction = Service.types[
'DemoService.Models.ShippingRestriction']
self.assertEqual(ShippingRestriction.Fragile.value, 1)

def test_computed_value_in_insert(self):
with responses.RequestsMock() as rsps:
rsps.add(rsps.GET, 'http://demo.local/odata/$metadata/',
Expand Down