Ejemplo n.º 1
0
def test_annot_v_l_missing_e_t(mock_warning, xml_builder_factory):
    """Test correct handling of annotations whose target type does not exist"""

    xml_builder = xml_builder_factory()
    xml_builder.add_schema(
        'MISSING_ET',
        """
        <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_ET.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_ET.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>
        """
    )

    metadata = MetadataBuilder(xml_builder.serialize())

    try:
        metadata.build()
        assert 'Expected' == 'RuntimeError'
    except RuntimeError as ex:
        assert str(ex) == 'Target Type Dict of ValueHelper(Dict/Value) does not exist'

    metadata.config.set_custom_error_policy({
        ParserError.ANNOTATION: PolicyWarning()
    })

    metadata.build()
    assert_logging_policy(mock_warning,
                          'RuntimeError',
                          'Target Type Dict of ValueHelper(Dict/Value) does not exist'
                          )
Ejemplo n.º 2
0
def test_missing_association_for_navigation_property(xml_builder_factory):
    """ Test faulty aassociations on navigation property"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', """
           <EntityType Name="MasterEntity">
               <Property Name="Key" Type="Edm.String" />
               <NavigationProperty Name="Followers" Relationship="EXAMPLE_SRV.Followers" FromRole="MasterRole"
                                    ToRole="FollowerRole"/>
           </EntityType>
       """)

    metadata = MetadataBuilder(xml_builder.serialize())

    with pytest.raises(KeyError) as typ_ex_info:
        metadata.build()
    assert typ_ex_info.value.args[0] == 'Association Followers does not exist in namespace EXAMPLE_SRV'
Ejemplo n.º 3
0
def test_faulty_association_set(xml_builder_factory):
    """ Test NullAssociation being correctly assigned to invalid associations"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', """
        <EntityContainer Name="EXAMPLE_SRV" m:IsDefaultEntityContainer="true">
           <AssociationSet Name="toDataEntitySet" Association="EXAMPLE_SRV.toDataEntity">
                    <End EntitySet="MasterEntities" Role="FromRole_toDataEntity"/>
                    <End EntitySet="DataValueHelp" Role="ToRole_toDataEntity"/>
            </AssociationSet>
        </EntityContainer>
       """)

    metadata = MetadataBuilder(
        xml_builder.serialize(),
        config=Config(
            default_error_policy=PolicyWarning()
        ))

    schema = metadata.build()
    assert isinstance(schema.association_set('toDataEntitySet'), NullAssociation)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.association_set('toDataEntitySet').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.'
Ejemplo n.º 4
0
def test_faulty_association(xml_builder_factory):
    """ Test NullAssociation being correctly assigned to invalid associations"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema('EXAMPLE_SRV', """
           <EntityType Name="MasterEntity">
               <Property Name="Key" Type="Edm.String" />
               <NavigationProperty Name="Followers" Relationship="EXAMPLE_SRV.Followers" FromRole="MasterRole"
                                    ToRole="FollowerRole"/>
           </EntityType>
           
           <EntityType Name="FollowerEntity">
               <Property Name="Key" Type="Edm.String" />
           </EntityType>

            <Association Name="Followers">
                <End Type="FaultyNamespace.MasterEntity" Multiplicity="1" Role="MasterRole"/>
                <End Type="FaultyNamespace.FollowerEntity" Multiplicity="*" Role="FollowerRole"/>
            </Association>
       """)

    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.'
Ejemplo n.º 5
0
def test_annot_v_l_missing_e_s(mock_warning, xml_builder_factory):
    """Test correct handling of annotations whose entity set does not exist"""

    xml_builder = xml_builder_factory()
    xml_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>
        """
    )

    metadata = MetadataBuilder(xml_builder.serialize())

    with pytest.raises(RuntimeError) as e_info:
        metadata.build()
    assert str(e_info.value) == 'Entity Set DataValueHelp for ValueHelper(Dict/Value) does not exist'

    metadata.config.set_custom_error_policy({
        ParserError.ANNOTATION: PolicyWarning()
    })

    metadata.build()
    assert_logging_policy(mock_warning,
                          'RuntimeError',
                          'Entity Set DataValueHelp for ValueHelper(Dict/Value) does not exist'
                          )
def test_null_type(xml_builder_factory):
    """ Test NullType being correctly assigned to invalid types"""
    xml_builder = xml_builder_factory()
    xml_builder.add_schema(
        'TEST.NAMESPACE', """
        <EntityType Name="MasterProperty">
            <Property Name="Key" Type="Edm.UnknownType" />
        </EntityType>
        
        <EnumType Name="MasterEnum" UnderlyingType="Edm.String" />
        
         <ComplexType Name="MasterComplex">
                <Property Name="Width" Type="Edm.Double" />
                <Property Name="Width" Type="Edm.Double" />
        </ComplexType>
        
        <EntityType Name="MasterEntity">
            <NavigationProperty Name="ID" />
        </EntityType>
    """)

    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)

    with pytest.raises(PyODataModelError) as typ_ex_info:
        schema.get_type(type_info).Any
    assert typ_ex_info.value.args[0] == f'Cannot access this type. An error occurred during parsing type ' \
                          f'stated in xml({schema.get_type(type_info).name}) was not found, therefore it has been ' \
                          f'replaced with NullType.'
Ejemplo n.º 7
0
def test_annot_v_l_trgt_inv_prop(mock_warning, mock_resolve, xml_builder_factory):
    """Test correct handling of annotations whose target property does not exist"""

    xml_builder = xml_builder_factory()
    xml_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>
        """
    )

    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.asser_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'
                          )