Exemplo n.º 1
0
    async def _load_entity_for_resolution_option_and_save(self, test_name: str, entity_name: str, res_opts: List[str]) -> None:
        """Loads an entity, resolves it, and then validates the generated attribute contexts"""
        expected_output_path = TestHelper.get_expected_output_folder_path(self.tests_sub_path, test_name)  # type: str
        file_name_suffix = ProjectionTestUtils.get_resolution_option_name_suffix(res_opts)  # type: str

        corpus = TestHelper.get_local_corpus(self.tests_sub_path, test_name)  # type: CdmCorpusDefinition
        corpus.storage.mount('expected', LocalAdapter(expected_output_path))

        # entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        # resolved_entity = await TestUtils._get_resolved_entity(corpus, entity, res_opts, True)
        entity = await corpus.fetch_object_async('local:/{0}.cdm.json/{0}'.format(entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, res_opts, True)

        await self._validate_resolved_attributes(corpus, resolved_entity, entity_name, file_name_suffix)

        AttributeContextUtil.validate_attribute_context(self, corpus, expected_output_path, '{}{}'.format(entity_name, file_name_suffix), resolved_entity)
Exemplo n.º 2
0
    async def _load_entity_for_resolution_option_and_save(
            self, test_name: str, entity_name: str, res_opts: List[str]):
        corpus = TestHelper.get_local_corpus(self.tests_subpath, test_name)
        manifest = await corpus.fetch_object_async(
            'local:/default.manifest.cdm.json')

        expected_output_path = TestHelper.get_expected_output_folder_path(
            self.tests_subpath, test_name)
        file_name_suffix = ProjectionTestUtils.get_resolution_option_name_suffix(
            res_opts)

        ent_sales_foreign_key_projection = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name), manifest)
        self.assertIsNotNone(ent_sales_foreign_key_projection)
        resolved_sales_foreign_key_projection = await self._save_resolved(
            corpus, manifest, test_name, ent_sales_foreign_key_projection,
            res_opts)
        self.assertIsNotNone(resolved_sales_foreign_key_projection)
        await AttributeContextUtil.validate_attribute_context(
            self, corpus, expected_output_path,
            '{}{}'.format(entity_name, file_name_suffix),
            resolved_sales_foreign_key_projection)
Exemplo n.º 3
0
    async def _save_resolved(
            self, corpus: 'CdmCorpusDefinition',
            manifest: 'CdmManifestDefinition', test_name: str,
            input_entity: 'CdmEntityDefinition',
            resolution_options: List[str]) -> 'CdmEntityDefinition':
        ro_hash_set = set()
        for i in range(len(resolution_options)):
            ro_hash_set.add(resolution_options[i])

        file_name_suffix = ProjectionTestUtils.get_resolution_option_name_suffix(
            resolution_options)

        resolved_entity_name = 'Resolved_{}{}.cdm.json'.format(
            input_entity.entity_name, file_name_suffix)

        ro = ResolveOptions(
            input_entity.in_document,
            directives=AttributeResolutionDirectiveSet(ro_hash_set))

        resolved_folder = corpus.storage.fetch_root_folder('output')
        resolved_entity = await input_entity.create_resolved_entity_async(
            resolved_entity_name, ro, resolved_folder)

        return resolved_entity