コード例 #1
0
    async def test_nested_proj(self):
        """Nested projections with AddAttributeGroup"""
        test_name = 'test_nested_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        outer_att_group = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes,
            'OuterAttributeGroup')  # type: CdmAttributeGroupDefinition
        inner_att_group = ProjectionTestUtils.validate_attribute_group(
            self, outer_att_group.members, 'InnerAttributeGroup')

        self.assertEqual(5, len(inner_att_group.members))
        self.assertEqual('name', inner_att_group.members[0].name)
        self.assertEqual('age', inner_att_group.members[1].name)
        self.assertEqual('address', inner_att_group.members[2].name)
        self.assertEqual('phoneNumber', inner_att_group.members[3].name)
        self.assertEqual('email', inner_att_group.members[4].name)
コード例 #2
0
    async def test_combine_ops_proj(self):
        """Test AddAttributeGroup and IncludeAttributes operations in the same projection"""
        test_name = 'test_combine_ops_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Included attributes: ['age', 'phoneNumber']
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonAttributeGroup', 3)
        self.assertEqual(5, len(att_group_definition.members))
        self.assertEqual('name', att_group_definition.members[0].name)
        self.assertEqual('age', att_group_definition.members[1].name)
        self.assertEqual('address', att_group_definition.members[2].name)
        self.assertEqual('phoneNumber', att_group_definition.members[3].name)
        self.assertEqual('email', att_group_definition.members[4].name)

        # Check the attributes coming from the IncludeAttribute operation
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[2].name)
コード例 #3
0
    async def test_type_attribute_proj(self):
        """Test resolving a type attribute with an add attribute group operation"""
        test_name = 'test_type_attribute_proj'
        entity_name = 'Person'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'AddressAttributeGroup', 5, 2)
        self.assertEqual('address', att_group_definition.members[0].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)
コード例 #4
0
    async def test_entity_attribute(self):
        """Test resolving an entity attribute using resolution guidance"""
        test_name = 'test_entity_attribute'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['structured'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonInfo')
        self.assertEqual(5, len(att_group_definition.members))
        self.assertEqual('name', att_group_definition.members[0].name)
        self.assertEqual('age', att_group_definition.members[1].name)
        self.assertEqual('address', att_group_definition.members[2].name)
        self.assertEqual('phoneNumber', att_group_definition.members[3].name)
        self.assertEqual('email', att_group_definition.members[4].name)
コード例 #5
0
    async def test_entity_attribute(self):
        """Test map type on an entity attribute"""
        test_name = 'test_entity_attribute'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{0}.cdm.json/{0}'.format(entity_name))  # type: CdmEntityDefinition
        non_structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ ])

        # Original set of attributes: ["name", "age", "address"]
        # in non-structured form
        # addArtifactAttribute : { "key" , "insertAtTop": true }
        # Expand 1...3;
        # renameAttributes = { {a}_{o}_key, apply to "key" }
        # renameAttributes = { {a}_{m}_{o}_value, apply to "name", "age", "address" }
        # alterTraits = { indicates.expansionInfo.mapKey(expansionName: "{a}", ordinal: "{o}") , apply to "key" , "argumentsContainWildcards" : true }
        # alterTraits = { has.expansionInfo.mapValue(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , apply to "name", "age", "address"  , "argumentsContainWildcards" : true }
        # addArtifactAttribute : "personCount"
        # alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true }
        self.assertEqual(13, len(non_structured_resolved_entity.attributes))
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[0], 'key_1_key', 1, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[1], 'ThreePeople_name_1_value', 1, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[2], 'ThreePeople_age_1_value', 1, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[3], 'ThreePeople_address_1_value', 1, 'ThreePeople', 'address')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[4], 'key_2_key', 2, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[5], 'ThreePeople_name_2_value', 2, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[6], 'ThreePeople_age_2_value', 2, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[7], 'ThreePeople_address_2_value', 2, 'ThreePeople', 'address')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[8], 'key_3_key', 3, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[9], 'ThreePeople_name_3_value', 3, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[10], 'ThreePeople_age_3_value', 3, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[11], 'ThreePeople_address_3_value', 3, 'ThreePeople', 'address')
        self.assertEqual("personCount", (non_structured_resolved_entity.attributes[12]).name)
        self.assertEqual("indicates.expansionInfo.count", non_structured_resolved_entity.attributes[12].applied_traits[1].named_reference)
        self.assertEqual("ThreePeople", non_structured_resolved_entity.attributes[12].applied_traits[1].arguments[0].value)

        # Original set of attributes: ["name", "age", "address"]
        # in structured form
        # addAttributeGroup: favorite people
        # alterTraits = { is.dataFormat.mapValue }
        # addArtifactAttribute : { "favorite People Key" (with trait "is.dataFormat.mapKey") , "insertAtTop": true }
        # addAttributeGroup: favorite People Group
        # alterTraits = { is.dataFormat.map }
        structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ 'structured' ])
        self.assertEqual(1, len(structured_resolved_entity.attributes))
        att_group_definition = ProjectionTestUtils.validate_attribute_group(self, structured_resolved_entity.attributes, 'favorite People Group')  # type: CdmAttributeGroupDefinition
        self.assertIsNotNone(att_group_definition.exhibits_traits.item('is.dataFormat.map'))
        self.assertEqual("favorite People Key", att_group_definition.members[0].name)
        self.assertIsNotNone(att_group_definition.members[0].applied_traits.item('is.dataFormat.mapKey'))
        self.assertEqual(CdmObjectType.ATTRIBUTE_GROUP_REF, att_group_definition.members[1].object_type)
        inner_att_group_ref = att_group_definition.members[1]  # type: CdmAttributeGroupReference
        self.assertIsNotNone(inner_att_group_ref.explicit_reference)
        inner_att_group_definition = inner_att_group_ref.explicit_reference  # type: CdmAttributeGroupDefinition
        self.assertEqual('favorite people', inner_att_group_definition.attribute_group_name)
        self.assertIsNotNone(inner_att_group_definition.exhibits_traits.item('is.dataFormat.mapValue'))
コード例 #6
0
    async def test_multiple_op_proj(self):
        """Multiple AddAttributeGroup operations on the same projection """
        test_name = 'test_multiple_op_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # This will result in two attribute groups with the same set of attributes being generated
        att_group1 = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonAttributeGroup',
            2)  # type: CdmAttributeGroupDefinition
        self.assertEqual(5, len(att_group1.members))
        self.assertEqual('name', att_group1.members[0].name)
        self.assertEqual('age', att_group1.members[1].name)
        self.assertEqual('address', att_group1.members[2].name)
        self.assertEqual('phoneNumber', att_group1.members[3].name)
        self.assertEqual('email', att_group1.members[4].name)

        att_group2 = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'SecondAttributeGroup', 2,
            1)  # type: CdmAttributeGroupDefinition
        self.assertEqual(5, len(att_group2.members))
        self.assertEqual('name', att_group2.members[0].name)
        self.assertEqual('age', att_group2.members[1].name)
        self.assertEqual('address', att_group2.members[2].name)
        self.assertEqual('phoneNumber', att_group2.members[3].name)
        self.assertEqual('email', att_group2.members[4].name)
コード例 #7
0
    async def test_entity_attribute_proj_using_object_model(self):
        """Test for creating a projection with an AddAttributeGroup operation on an entity attribute using the object model"""
        test_name = 'test_entity_attribute_proj_using_object_model'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(
            corpus, local_root)  # type: CdmEntityDefinition

        # Create a projection
        projection = ProjectionTestUtils.create_projection(
            corpus, local_root)  # type: CdmProjection

        # Create an AddAttributeGroup operation
        add_att_group_op = corpus.make_object(
            CdmObjectType.OPERATION_ADD_ATTRIBUTE_GROUP_DEF
        )  # type: CdmOperationAddAttributeGroup
        add_att_group_op.attribute_group_name = 'PersonAttributeGroup'
        projection.operations.append(add_att_group_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(
            CdmObjectType.ENTITY_REF, None)  # type: CdmEntityReference
        projection_entity_ref.explicit_reference = projection

        # Create an entity attribute that contains this projection and add this to the entity
        entity_attribute = corpus.make_object(
            CdmObjectType.ENTITY_ATTRIBUTE_DEF,
            'TestEntityAttribute')  # type: CdmEntityAttributeDefinition
        entity_attribute.entity = projection_entity_ref
        entity.attributes.append(entity_attribute)

        # Resolve the entity.
        resolved_entity = await entity.create_resolved_entity_async(
            'Resolved_{}.cdm.json'.format(entity.entity_name), None,
            local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonAttributeGroup')
        self.assertEqual(4, len(att_group_definition.members))
        self.assertEqual('id', att_group_definition.members[0].name)
        self.assertEqual('name', att_group_definition.members[1].name)
        self.assertEqual('value', att_group_definition.members[2].name)
        self.assertEqual('date', att_group_definition.members[3].name)
コード例 #8
0
    async def test_type_attribute(self):
        """Test map type on a type attribute"""
        test_name = 'test_type_attribute'
        entity_name = 'Person'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{0}.cdm.json/{0}'.format(entity_name))  # type: CdmEntityDefinition
        non_structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ ])

        # Original set of attributes: ["Favorite Terms"]
        # in non-structured form
        # addArtifactAttribute : { "Term key" , "insertAtTop": true }
        # Expand 1...2;
        # renameAttributes = { {m}_{o}_key, apply to "Term key" }
        # renameAttributes = { {m}_{o}_value, apply to "FavoriteTerms" }
        # alterTraits = { indicates.expansionInfo.mapKey(expansionName: "{a}", ordinal: "{o}") , apply to "Term key" , "argumentsContainWildcards" : true }
        # alterTraits = { has.expansionInfo.mapValue(expansionName: "{a}", ordinal: "{o}") , apply to "FavoriteTerms"  , "argumentsContainWildcards" : true }
        # addArtifactAttribute : number of favorite terms"
        # alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "number of favorite terms" , "argumentsContainWildcards" : true }
        self.assertEqual(5, len(non_structured_resolved_entity.attributes))
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[0], 'Term key_1_key', 1, 'FavoriteTerms', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[1], 'FavoriteTerms_1_value', 1, 'FavoriteTerms')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[2], 'Term key_2_key', 2, 'FavoriteTerms', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[3], 'FavoriteTerms_2_value', 2, 'FavoriteTerms')
        self.assertEqual("number of favorite terms", (non_structured_resolved_entity.attributes[4]).name)
        self.assertEqual("indicates.expansionInfo.count", non_structured_resolved_entity.attributes[4].applied_traits[1].named_reference)
        self.assertEqual("FavoriteTerms", non_structured_resolved_entity.attributes[4].applied_traits[1].arguments[0].value)

        # Original set of attributes: ["Favorite Terms"]
        # in structured form
        # alterTraits = { is.dataFormat.list }
        structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ 'structured' ])
        self.assertEqual(1, len(structured_resolved_entity.attributes))
        att_group_definition = ProjectionTestUtils.validate_attribute_group(self, structured_resolved_entity.attributes, 'favorite Term Group')  # type: CdmAttributeGroupDefinition
        self.assertIsNotNone(att_group_definition.exhibits_traits.item('is.dataFormat.map'))
        self.assertEqual("Favorite Terms Key", att_group_definition.members[0].name)
        self.assertIsNotNone(att_group_definition.members[0].applied_traits.item('is.dataFormat.mapKey'))
        self.assertEqual("FavoriteTerms", att_group_definition.members[1].name)
        self.assertIsNotNone(att_group_definition.members[1].applied_traits.item('is.dataFormat.mapValue'))
コード例 #9
0
    async def test_conditional_proj(self):
        """Test AddAttributeGroup operation with a 'structured' condition"""
        test_name = 'test_conditional_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['referenceOnly'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Condition not met, keep attributes in flat list
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('address', resolved_entity.attributes[2].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)

        resolved_entity2 = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['structured'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Condition met, put all attributes in an attribute group
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity2.attributes, 'PersonAttributeGroup')
        self.assertEqual(5, len(att_group_definition.members))
        self.assertEqual('name', att_group_definition.members[0].name)
        self.assertEqual('age', att_group_definition.members[1].name)
        self.assertEqual('address', att_group_definition.members[2].name)
        self.assertEqual('phoneNumber', att_group_definition.members[3].name)
        self.assertEqual('email', att_group_definition.members[4].name)
コード例 #10
0
ファイル: test_projection_array.py プロジェクト: minettes/CDM
    async def test_entity_attribute(self):
        """Test Array type on an entity attribute"""
        test_name = 'test_entity_attribute'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        non_structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["name", "age", "address"]
        # in non-structured form
        # Expand 1...3;
        # renameFormat = {m}{o};
        # alterTraits = { has.expansionInfo.list(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , "argumentsContainWildcards" : true }
        # addArtifactAttribute : "personCount"
        # alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true }
        self.assertEqual(10, len(non_structured_resolved_entity.attributes))
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[0], 'name1', 1,
            'ThreePeople', 'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[1], 'age1', 1,
            'ThreePeople', 'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[2], 'address1', 1,
            'ThreePeople', 'address')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[3], 'name2', 2,
            'ThreePeople', 'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[4], 'age2', 2,
            'ThreePeople', 'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[5], 'address2', 2,
            'ThreePeople', 'address')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[6], 'name3', 3,
            'ThreePeople', 'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[7], 'age3', 3,
            'ThreePeople', 'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, non_structured_resolved_entity.attributes[8], 'address3', 3,
            'ThreePeople', 'address')
        self.assertEqual('personCount',
                         (non_structured_resolved_entity.attributes[9]).name)
        self.assertIsNotNone(
            non_structured_resolved_entity.attributes[9].applied_traits.item(
                'indicates.expansionInfo.count'))
        self.assertEqual(
            'ThreePeople',
            non_structured_resolved_entity.attributes[9].applied_traits.item(
                'indicates.expansionInfo.count').arguments[0].value)

        # Original set of attributes: ["name", "age", "address"]
        # in structured form
        # alterTraits = { is.dataFormat.list }
        # addAttributeGroup: favoriteMusketeers
        structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['structured'])
        self.assertEqual(1, len(structured_resolved_entity.attributes))
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, structured_resolved_entity.attributes, 'favoriteMusketeers')
        self.assertIsNotNone(
            att_group_definition.exhibits_traits.item('is.dataFormat.list'))
コード例 #11
0
    async def test_conditional_proj_using_object_model(self):
        """Test for creating a projection with an AddAttributeGroup operation and a condition using the object model"""
        test_name = 'test_conditional_proj_using_object_model'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity.
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection with a condition that states the operation should only execute when the resolution directive is 'structured'.
        projection = ProjectionTestUtils.create_projection(corpus, local_root)
        projection.condition = 'structured==true'

        # Create an AddAttributeGroup operation
        add_att_group_op = corpus.make_object(
            CdmObjectType.OPERATION_ADD_ATTRIBUTE_GROUP_DEF)
        add_att_group_op.attribute_group_name = 'PersonAttributeGroup'
        projection.operations.append(add_att_group_op)

        # Create an entity reference to hold this projection.
        projection_entity_ref = corpus.make_object(
            CdmObjectType.ENTITY_REF, None)  # type: CdmEntityReference
        projection_entity_ref.explicit_reference = projection

        # Create an entity attribute that contains this projection and add this to the entity.
        entity_attribute = corpus.make_object(
            CdmObjectType.ENTITY_ATTRIBUTE_DEF,
            'TestEntityAttribute')  # type: CdmEntityAttributeDefinition
        entity_attribute.entity = projection_entity_ref
        entity.attributes.append(entity_attribute)

        # Create resolution options with the 'referenceOnly' directive.
        res_opt = ResolveOptions(entity.in_document)
        res_opt.directives = AttributeResolutionDirectiveSet({'referenceOnly'})

        # Resolve the entity with 'referenceOnly'
        resolved_entity_with_reference_only = await entity.create_resolved_entity_async(
            'Resolved_{}.cdm.json'.format(entity.entity_name), res_opt,
            local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        # Condition not met, keep attributes in flat list
        self.assertEqual(4,
                         len(resolved_entity_with_reference_only.attributes))
        self.assertEqual(
            'id', resolved_entity_with_reference_only.attributes[0].name)
        self.assertEqual(
            'name', resolved_entity_with_reference_only.attributes[1].name)
        self.assertEqual(
            'value', resolved_entity_with_reference_only.attributes[2].name)
        self.assertEqual(
            'date', resolved_entity_with_reference_only.attributes[3].name)

        # Now resolve the entity with the 'structured' directive
        res_opt.directives = AttributeResolutionDirectiveSet({'structured'})
        resolved_entity_with_structured = await entity.create_resolved_entity_async(
            'Resolved_{}.cdm.json'.format(entity.entity_name), res_opt,
            local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        # Condition met, put all attributes in an attribute group
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity_with_structured.attributes,
            'PersonAttributeGroup')
        self.assertEqual(4, len(att_group_definition.members))
        self.assertEqual('id', att_group_definition.members[0].name)
        self.assertEqual('name', att_group_definition.members[1].name)
        self.assertEqual('value', att_group_definition.members[2].name)
        self.assertEqual('date', att_group_definition.members[3].name)