Exemplo n.º 1
0
    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'))
Exemplo n.º 2
0
    async def test_wildcard_args(self):
        """Test argumentsContainWildcards field in AlterTraits with ArrayExpansion and RenameAttributes operations"""
        test_name = 'test_wildcard_args'
        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
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Add attribute: ["newName" (InsertAtTop:false), "newName_1" (InsertAtTop:true)]
        self.assertEqual(9, len(resolved_entity.attributes))
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[0], 'name1', 1, 'ThreePeople',
            'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[1], 'age1', 1, 'ThreePeople',
            'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[2], 'address1', 1, 'ThreePeople',
            'address')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[3], 'name2', 2, 'ThreePeople',
            'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[4], 'age2', 2, 'ThreePeople',
            'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[5], 'address2', 2, 'ThreePeople',
            'address')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[6], 'name3', 3, 'ThreePeople',
            'name')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[7], 'age3', 3, 'ThreePeople',
            'age')
        ProjectionTestUtils.validate_expansion_info_trait(
            self, resolved_entity.attributes[8], 'address3', 3, 'ThreePeople',
            'address')