コード例 #1
0
def test_unsupported_enum_underlying_type(metadata_builder_factory):
    """Test if parser will parse only allowed underlying types"""
    builder = metadata_builder_factory()
    builder.add_schema('Test', '<EnumType Name="UnsupportedEnumType" UnderlyingType="Edm.Bool" />')
    xml = builder.serialize()

    try:
        Edmx.parse(xml)
    except PyODataParserError as ex:
        assert str(ex).startswith(f'Type Edm.Bool is not valid as underlying type for EnumType - must be one of')
コード例 #2
0
def test_whitelisted_edm_namespace(mock_from_etree, metadata_builder_factory):
    """Test correct handling of whitelisted Microsoft's edm namespace"""

    builder = metadata_builder_factory()
    builder.namespaces['edm'] = 'http://schemas.microsoft.com/ado/2009/11/edm'
    builder.add_schema('', '')
    xml = builder.serialize()

    Edmx.parse(xml)
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
コード例 #3
0
def test_missing_schema(metadata_builder_factory):
    """Test correct handling of missing Schema tag in xml"""

    builder = metadata_builder_factory()
    builder.schema_is_enabled = False
    xml = builder.serialize()

    try:
        Edmx.parse(xml)
    except PyODataParserError as ex:
        assert str(ex) == 'Metadata document is missing the element Schema'
コード例 #4
0
def test_namespace_whitelist(mock_from_etree, metadata_builder_factory):
    """Test correct handling of whitelisted namespaces"""

    builder = metadata_builder_factory()
    builder.namespaces['edmx'] = 'http://docs.oasis-open.org/odata/ns/edmx'
    builder.namespaces['edm'] = 'http://docs.oasis-open.org/odata/ns/edm'
    builder.add_schema('', '')
    xml = builder.serialize()

    Edmx.parse(xml)
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
コード例 #5
0
def test_enum_value_out_of_range(metadata_builder_factory):
    """Test if parser will check for values ot of range defined by underlying type"""
    builder = metadata_builder_factory()
    builder.add_schema('Test', """
        <EnumType Name="Num" UnderlyingType="Edm.Byte">
            <Member Name="TooBig" Value="-130" />
        </EnumType>
        """)
    xml = builder.serialize()

    try:
        Edmx.parse(xml)
    except PyODataParserError as ex:
        assert str(ex) == f'Value -130 is out of range for type Edm.Byte'
コード例 #6
0
def test_annot_v_l_trgt_inv_prop(metadata_builder_factory):
    """Test correct handling of annotations whose target property does not exist"""

    builder = metadata_builder_factory()
    builder.add_schema(
        'MISSING_TP', """
        <EntityType Name="Dict" sap:content-version="1">
         <Key><PropertyRef Name="Key"/></Key>
         <Property Name="Key" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:value-list="standard"/>
         <Property Name="Value" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:value-list="standard"/>
        </EntityType>
        <EntityType Name="Database" sap:content-version="1">
         <Key><PropertyRef Name="Data"/></Key>
         <Property Name="Data" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:value-list="standard"/>
        </EntityType>
        <EntityContainer Name="EXAMPLE_SRV" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
         <EntitySet Name="DataValueHelp" EntityType="MISSING_TP.Database" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:searchable="true" sap:content-version="1"/>
        </EntityContainer>
        <Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="MISSING_TP.Dict/NoExisting">
         <Annotation Term="com.sap.vocabularies.Common.v1.ValueList">
          <Record>
           <PropertyValue Property="Label" String="Data"/>
           <PropertyValue Property="CollectionPath" String="DataValueHelp"/>
           <PropertyValue Property="SearchSupported" Bool="true"/>
           <PropertyValue Property="Parameters">
            <Collection>
             <Record Type="com.sap.vocabularies.Common.v1.ValueListParameterOut">
              <PropertyValue Property="LocalDataProperty" PropertyPath="Value"/>
              <PropertyValue Property="ValueListProperty" String="Data"/>
             </Record>
            </Collection>
           </PropertyValue>
          </Record>
         </Annotation>
        </Annotations>
        """)

    try:
        Edmx.parse(builder.serialize())
        assert 'Expected' == 'RuntimeError'
    except RuntimeError as ex:
        assert str(
            ex
        ) == 'Target Property NoExisting of EntityType(Dict) as defined in ValueHelper(Dict/NoExisting) does not exist'
コード例 #7
0
def test_unsupported_schema_n(mock_from_etree, metadata_builder_factory):
    """Test correct handling of non-whitelisted Schema namespaces"""

    builder = metadata_builder_factory()
    edm = 'wedonotsupportthisnamespace.com'
    builder.namespaces['edm'] = edm
    builder.add_schema('', '')
    xml = builder.serialize()

    Edmx.parse(xml, {'edm': edm})
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()

    try:
        Edmx.parse(xml)
    except PyODataParserError as ex:
        assert str(ex) == f'Unsupported Schema namespace - {edm}'

    mock_from_etree.assert_called_once()
コード例 #8
0
def test_annot_v_l_missing_e_s(metadata_builder_factory):
    """Test correct handling of annotations whose entity set does not exist"""

    builder = metadata_builder_factory()
    builder.add_schema(
        'MISSING_ES', """
        <EntityType Name="Dict" sap:content-version="1">
         <Key><PropertyRef Name="Key"/></Key>
         <Property Name="Key" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:value-list="standard"/>
         <Property Name="Value" Type="Edm.String" Nullable="false" sap:unicode="false" sap:label="Key" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:value-list="standard"/>
        </EntityType>
        <Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="MISSING_ES.Dict/Value">
         <Annotation Term="com.sap.vocabularies.Common.v1.ValueList">
          <Record>
           <PropertyValue Property="Label" String="Data"/>
           <PropertyValue Property="CollectionPath" String="DataValueHelp"/>
           <PropertyValue Property="SearchSupported" Bool="true"/>
           <PropertyValue Property="Parameters">
            <Collection>
             <Record Type="com.sap.vocabularies.Common.v1.ValueListParameterOut">
              <PropertyValue Property="LocalDataProperty" PropertyPath="Value"/>
              <PropertyValue Property="ValueListProperty" String="Data"/>
             </Record>
            </Collection>
           </PropertyValue>
          </Record>
         </Annotation>
        </Annotations>
        """)

    try:
        Edmx.parse(builder.serialize())
        assert 'Expected' == 'RuntimeError'
    except RuntimeError as ex:
        assert str(
            ex
        ) == 'Entity Set DataValueHelp for ValueHelper(Dict/Value) does not exist'
コード例 #9
0
ファイル: conftest.py プロジェクト: pmcarlos/python-pyodata
def schema(metadata):
    """Parsed metadata"""

    # pylint: disable=redefined-outer-name

    return Edmx.parse(metadata)
コード例 #10
0
def test_namespace_with_periods(metadata_builder_factory):
    """Make sure Namespace can contain period"""

    builder = metadata_builder_factory()
    builder.add_schema(
        'Several.Levels.Of.Names', """
        <EntityType Name="Dict" sap:content-version="1">
         <Key><PropertyRef Name="Key"/></Key>
         <Property Name="Key" Type="Edm.String" Nullable="false"/>
         <Property Name="Value" Type="Edm.String" Nullable="false"/>
        </EntityType>

        <EntityType Name="Database" sap:content-version="1">
         <Key><PropertyRef Name="Data"/></Key>
         <Property Name="Data" Type="Edm.String" Nullable="false"/>
         <NavigationProperty Name="Tables" Relationship="Several.Levels.Of.Names.DatabaseTables" ToRole="Table" FromRole="Schema"/>
        </EntityType>

        <Association Name="DatabaseTables">
          <End Type="Several.Levels.Of.Names.Dict" Role="Table" Multiplicity="*"/>
          <End Type="Several.Levels.Of.Names.Database" Role="Schema" Multiplicity="0"/>
          <ReferentialConstraint>
            <Principal Role="Schema">
              <PropertyRef Name="Data"/>
            </Principal>
            <Dependent Role="Table">
              <PropertyRef Name="Key"/>
            </Dependent>
          </ReferentialConstraint>
        </Association>

        <EntityContainer Name="EXAMPLE_SRV">
         <EntitySet Name="Schemas" EntityType="Several.Levels.Of.Names.Database"/>
         <EntitySet Name="Tables" EntityType="Several.Levels.Of.Names.Dict"/>
         <AssociationSet Name="SchemaTablesSet" Association="Several.Levels.Of.Names.DatabaseTables">
           <End Role="Table" EntitySet="Tables"/>
           <End Role="Schema" EntitySet="Schemas"/>
         </AssociationSet>
        </EntityContainer>
        """)

    schema = Edmx.parse(builder.serialize())

    db_entity = schema.entity_type('Database')

    nav_prop = db_entity.nav_proprty('Tables')

    assert str(nav_prop) == 'NavigationTypeProperty(Tables)'

    assert str(nav_prop.to_role) == 'EndRole(Table)'
    assert str(nav_prop.to_role.entity_type) == 'EntityType(Dict)'

    association_info = nav_prop.association_info

    association_set = schema.association_set_by_association(
        association_info.name, association_info.namespace)

    assert association_set is not None

    end_role = association_set.end_by_role(nav_prop.to_role.role)

    assert end_role is not None
コード例 #11
0
def schema(metadata):
    parsed_schema = Edmx.parse(metadata)
    return parsed_schema