Beispiel #1
0
    async def _create_translation_job_with_dummy_docs_async(self, async_client, docs_count, **kwargs):
        # get input parms
        wait_for_job = kwargs.pop('wait', False)
        language_code = kwargs.pop('language_code', "es")

        # prepare containers and test data
        blob_data = Document.create_dummy_docs(docs_count=docs_count)
        source_container_sas_url = self.create_source_container(data=blob_data)
        target_container_sas_url = self.create_target_container()

        # prepare translation inputs
        translation_inputs = [
            DocumentTranslationInput(
                source_url=source_container_sas_url,
                targets=[
                    TranslationTarget(
                        target_url=target_container_sas_url,
                        language_code=language_code
                    )
                ]
            )
        ]

        # submit job
        job_details = await async_client.create_translation_job(translation_inputs)
        self.assertIsNotNone(job_details.id)
        # wait for result
        if wait_for_job:
                await async_client.wait_until_done(job_details.id)
        # validate
        self._validate_translation_job(job_details=job_details)

        return job_details.id
    async def _begin_and_validate_translation_with_multiple_docs_async(
            self, async_client, docs_count, **kwargs):
        # get input parms
        wait_for_operation = kwargs.pop('wait', False)
        language_code = kwargs.pop('language_code', "es")

        # prepare containers and test data
        blob_data = Document.create_dummy_docs(docs_count=docs_count)
        source_container_sas_url = self.create_source_container(data=blob_data)
        target_container_sas_url = self.create_target_container()

        # prepare translation inputs
        translation_inputs = [
            DocumentTranslationInput(
                source_url=source_container_sas_url,
                targets=[
                    TranslationTarget(target_url=target_container_sas_url,
                                      language_code=language_code)
                ])
        ]

        # submit operation
        poller = await async_client.begin_translation(translation_inputs)
        self.assertIsNotNone(poller.id)
        # wait for result
        if wait_for_operation:
            result = await poller.result()
            async for doc in result:
                self._validate_doc_status(doc, "es")

        # validate
        self._validate_translation_metadata(poller=poller)
        return poller
Beispiel #3
0
    async def _begin_multiple_translations_async(self, async_client,
                                                 operations_count, **kwargs):
        container_suffix = kwargs.pop('container_suffix', "")
        variables = kwargs.pop('variables', {})
        wait_for_operation = kwargs.pop('wait', True)
        language_code = kwargs.pop('language_code', "es")
        docs_per_operation = kwargs.pop('docs_per_operation', 2)
        result_ids = []
        for i in range(operations_count):
            # prepare containers and test data
            '''
                # note
                since we're only testing the client library
                we can use sync container calls in here
                no need for async container clients!
            '''
            blob_data = Document.create_dummy_docs(docs_per_operation)
            source_container_sas_url = self.create_source_container(
                data=blob_data,
                variables=variables,
                container_suffix=str(i) + container_suffix)
            target_container_sas_url = self.create_target_container(
                variables=variables,
                container_suffix=str(i) + container_suffix)

            # prepare translation inputs
            translation_inputs = [
                DocumentTranslationInput(
                    source_url=source_container_sas_url,
                    targets=[
                        TranslationTarget(target_url=target_container_sas_url,
                                          language_code=language_code)
                    ])
            ]

            # submit multiple operations
            poller = await async_client.begin_translation(translation_inputs)
            assert poller.id is not None
            if wait_for_operation:
                await poller.result()
            else:
                await poller.wait()
            result_ids.append(poller.id)

        return result_ids
Beispiel #4
0
    async def _create_and_submit_sample_translation_jobs_async(self, async_client, jobs_count, **kwargs):
        wait_for_job = kwargs.pop('wait', True)
        language_code = kwargs.pop('language_code', "es")
        docs_per_job = kwargs.pop('docs_per_job', 2)
        result_job_ids = []
        for i in range(jobs_count):
            # prepare containers and test data
            '''
                # note
                since we're only testing the client library
                we can use sync container calls in here
                no need for async container clients!
            '''
            blob_data = Document.create_dummy_docs(docs_per_job)
            source_container_sas_url = self.create_source_container(data=blob_data)
            target_container_sas_url = self.create_target_container()

            # prepare translation inputs
            translation_inputs = [
                DocumentTranslationInput(
                    source_url=source_container_sas_url,
                    targets=[
                        TranslationTarget(
                            target_url=target_container_sas_url,
                            language_code=language_code
                        )
                    ]
                )
            ]

            # submit multiple jobs
            job_details = await async_client.create_translation_job(translation_inputs)
            self.assertIsNotNone(job_details.id)
            if wait_for_job:
                await async_client.wait_until_done(job_details.id)
            result_job_ids.append(job_details.id)

        return result_job_ids
Beispiel #5
0
    async def _create_translation_job_with_dummy_docs_async(
            self, async_client, docs_count, **kwargs):
        '''
            appropriated this method from another PR! #18302
            please resolve conflict before merge
            keep in mind it's the exact same method
        '''
        # get input parms
        wait_for_job = kwargs.pop('wait', False)
        language_code = kwargs.pop('language_code', "es")

        # prepare containers and test data
        blob_data = Document.create_dummy_docs(docs_count=docs_count)
        source_container_sas_url = self.create_source_container(data=blob_data)
        target_container_sas_url = self.create_target_container()

        # prepare translation inputs
        translation_inputs = [
            DocumentTranslationInput(
                source_url=source_container_sas_url,
                targets=[
                    TranslationTarget(target_url=target_container_sas_url,
                                      language_code=language_code)
                ])
        ]

        # submit job
        job_details = await async_client.create_translation_job(
            translation_inputs)
        self.assertIsNotNone(job_details.id)
        # wait for result
        if wait_for_job:
            await async_client.wait_until_done(job_details.id)
        # validate
        self._validate_translation_job(job_details=job_details)

        return job_details.id