Skip to content

Commit 83ba295

Browse files
committed
Schema: make MaxLengh compliant with the spec
The attribute MaxLength MAY be specified and the attribute may hold the constant 'max'. TODO - the attribute MAY be specified only for the Binary, String, and Stream types.
1 parent f4c41ce commit 83ba295

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

pyodata/v2/model.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,24 @@ def from_name(name):
127127

128128
return Typ.Types[name]
129129

130-
131130
class VariableDeclaration(Identifier):
132131

132+
MAXIMUM_LENGTH = -1
133+
133134
def __init__(self, name, typ, nullable, max_length, precision):
134135
super(VariableDeclaration, self).__init__(name)
135136

136137
self._typ = Typ.from_name(typ)
137138

138139
self._nullable = bool(nullable)
139-
self._max_length = int(max_length if max_length is not None else 0)
140+
141+
if not max_length:
142+
self._max_length = None
143+
elif max_length.upper() == 'MAX':
144+
self._max_length = VariableDeclaration.MAXIMUM_LENGTH
145+
else:
146+
self._max_length = int(max_length)
147+
140148
self._precision = precision
141149

142150
@property

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def metadata():
1212
<Key><PropertyRef Name="Key"/></Key>
1313
<Property Name="Key" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false"/>
1414
<Property Name="DataType" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false"/>
15-
<Property Name="Data" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Data" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:text="DataName"/>
15+
<Property Name="Data" Type="Edm.String" MaxLength="Max" Nullable="false" sap:unicode="false" sap:label="Data" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:text="DataName"/>
1616
<Property Name="DataName" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Data" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
1717
</EntityType>
1818
<EntityType Name="DataEntity" sap:content-version="1" sap:value-list="true" sap:label="Data entities">

tests/test_model_v2.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from pyodata.v2.model import Edmx, Typ
6+
from pyodata.v2.model import Edmx, Typ, EntityTypeProperty
77

88

99
def test_edmx(metadata):
@@ -34,6 +34,7 @@ def test_edmx(metadata):
3434
master_prop_data = master_entity.proprty('Data')
3535
assert master_prop_data.text_proprty.name == 'DataName'
3636
assert master_prop_data.visible
37+
assert master_prop_data.max_length == EntityTypeProperty.MAXIMUM_LENGTH
3738

3839
master_prop_data_vh = master_prop_data.value_helper
3940
assert str(master_prop_data_vh) == 'ValueHelper(MasterEntity/Data)'
@@ -84,7 +85,7 @@ def test_edmx(metadata):
8485
assert param.name == 'Param'
8586
assert param.typ.name == 'Edm.String'
8687
assert not param.nullable
87-
assert param.max_length == 0
88+
assert param.max_length is None
8889
assert param.mode == 'In'
8990
assert param.typ.traits.to_odata('Foo') == "'Foo'"
9091
assert param.typ.traits.from_odata("'Foo'") == 'Foo'

0 commit comments

Comments
 (0)