diff --git a/scripts/devops_tasks/test_run_samples.py b/scripts/devops_tasks/test_run_samples.py index 4501a0bcc1c3..ad993339e526 100644 --- a/scripts/devops_tasks/test_run_samples.py +++ b/scripts/devops_tasks/test_run_samples.py @@ -113,6 +113,12 @@ "release_phone_number_sample_async.py", "release_phone_number_sample.py" ], + "azure-ai-translation-document": [ + "sample_list_document_statuses_with_filters_async.py", + "sample_list_translations_with_filters_async.py", + "sample_list_document_statuses_with_filters.py", + "sample_list_translations_with_filters.py", + ] } diff --git a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py index 0f92be1c64af..c8e709a30f8a 100644 --- a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py +++ b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py @@ -46,7 +46,7 @@ async def sample_document_status_checks_async(): poller = await client.begin_translation(source_container_url, target_container_url, "es") completed_docs = [] - while not poller.done(): + while poller.status() in ["Running", "NotStarted"]: await asyncio.sleep(30) doc_statuses = client.list_all_document_statuses(poller.id) diff --git a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py index a1b8ca78458c..8399cbfc1e08 100644 --- a/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py +++ b/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py @@ -68,11 +68,11 @@ async def sample_translation_with_azure_blob(self): source_container = await self.create_container( blob_service_client, - container_name=self.storage_source_container_name or "translation-source-container", + container_name=self.storage_source_container_name or "translation-source-container-async", ) target_container = await self.create_container( blob_service_client, - container_name=self.storage_target_container_name or "translation-target-container" + container_name=self.storage_target_container_name or "translation-target-container-async" ) if self.document_name: diff --git a/sdk/translation/test-resources.json b/sdk/translation/test-resources.json index 4d59f0ae34f6..0b124a23d692 100644 --- a/sdk/translation/test-resources.json +++ b/sdk/translation/test-resources.json @@ -46,13 +46,90 @@ "defaultValue": ".cognitiveservices.azure.com/", "type": "string" }, - "storageEndpointSuffix": { - "defaultValue": ".blob.core.windows.net/", - "type": "string" - }, "blobStorageAccount": { "type": "string", "defaultValue": "[concat(parameters('baseName'), 'prim')]" + }, + "sourceStorageAccount": { + "type": "string", + "defaultValue": "krpraticstorageacc" + }, + "sourceResourceId": { + "type": "string", + "defaultValue": "[resourceId('faa080af-c1d8-40ad-9cce-e1a450ca5b57', 'krpratic-rg', 'Microsoft.Storage/storageAccounts', parameters('sourceStorageAccount'))]" + }, + "sourceContainerName": { + "type": "string", + "defaultValue": "testingtranslation" + }, + "glossaryFileName": { + "type": "string", + "defaultValue": "glosario.tsv" + }, + "sourceContainerSasProperties": { + "type": "object", + "defaultValue": { + "canonicalizedResource": "[concat('/blob/', parameters('sourceStorageAccount'), '/', parameters('sourceContainerName'))]", + "signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]", + "signedPermission": "rl", + "signedResource": "c" + } + }, + "targetResourceId": { + "type": "string", + "defaultValue": "[resourceId('Microsoft.Storage/storageAccounts', parameters('blobStorageAccount'))]" + }, + "targetContainerName_1": { + "type": "string", + "defaultValue": "testingcontainer1" + }, + "targetContainerSasProperties_1": { + "type": "object", + "defaultValue": { + "canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_1'))]", + "signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]", + "signedPermission": "wl", + "signedResource": "c" + } + }, + "targetContainerName_2": { + "type": "string", + "defaultValue": "testingcontainer2" + }, + "targetContainerSasProperties_2": { + "type": "object", + "defaultValue": { + "canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_2'))]", + "signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]", + "signedPermission": "wl", + "signedResource": "c" + } + }, + "targetContainerName_3": { + "type": "string", + "defaultValue": "testingcontainer3" + }, + "targetContainerSasProperties_3": { + "type": "object", + "defaultValue": { + "canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_3'))]", + "signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]", + "signedPermission": "wl", + "signedResource": "c" + } + }, + "targetContainerName_4": { + "type": "string", + "defaultValue": "testingcontainer4" + }, + "targetContainerSasProperties_4": { + "type": "object", + "defaultValue": { + "canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_4'))]", + "signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]", + "signedPermission": "wl", + "signedResource": "c" + } } }, "variables": { @@ -63,6 +140,7 @@ "storageAccountName": "[concat(parameters('baseName'), 'prim')]", "location": "[resourceGroup().location]", "azureDocTranslationUrl": "[concat('https://', variables('docTranslationBaseName'), parameters('docTranslationEndpointSuffix'))]", + "azureStorageEndpoint": "[concat('https://', parameters('blobStorageAccount'), '.blob.core.windows.net/')]", "cognitiveServiceUserRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/a97b65f3-24c7-4388-baec-2e87135dc908')]", "encryption": { "services": { @@ -120,7 +198,41 @@ "supportsHttpsTrafficOnly": true, "encryption": "[variables('encryption')]", "accessTier": "Cool" - } + }, + "resources": [ + { + "type": "blobServices/containers", + "apiVersion": "[variables('storageMgmtApiVersion')]", + "name": "[concat('default/', parameters('targetContainerName_1'))]", + "dependsOn": [ + "[parameters('blobStorageAccount')]" + ] + }, + { + "type": "blobServices/containers", + "apiVersion": "[variables('storageMgmtApiVersion')]", + "name": "[concat('default/', parameters('targetContainerName_2'))]", + "dependsOn": [ + "[parameters('blobStorageAccount')]" + ] + }, + { + "type": "blobServices/containers", + "apiVersion": "[variables('storageMgmtApiVersion')]", + "name": "[concat('default/', parameters('targetContainerName_3'))]", + "dependsOn": [ + "[parameters('blobStorageAccount')]" + ] + }, + { + "type": "blobServices/containers", + "apiVersion": "[variables('storageMgmtApiVersion')]", + "name": "[concat('default/', parameters('targetContainerName_4'))]", + "dependsOn": [ + "[parameters('blobStorageAccount')]" + ] + } + ] } ], "outputs": { @@ -155,6 +267,58 @@ "TRANSLATION_DOCUMENT_STORAGE_KEY": { "type": "string", "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]" + }, + "AZURE_DOCUMENT_TRANSLATION_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('docTranslationBaseName')), variables('docTranslationApiVersion')).key1]" + }, + "AZURE_DOCUMENT_TRANSLATION_ENDPOINT": { + "type": "string", + "value": "[variables('azureDocTranslationUrl')]" + }, + "AZURE_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[parameters('blobStorageAccount')]" + }, + "AZURE_STORAGE_SOURCE_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]" + }, + "AZURE_STORAGE_SOURCE_ENDPOINT": { + "type": "string", + "value": "[variables('azureStorageEndpoint')]" + }, + "AZURE_SOURCE_CONTAINER_URL": { + "type": "string", + "value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]" + }, + "AZURE_SOURCE_CONTAINER_URL_1": { + "type": "string", + "value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]" + }, + "AZURE_SOURCE_CONTAINER_URL_2": { + "type": "string", + "value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]" + }, + "AZURE_TRANSLATION_GLOSSARY_URL": { + "type": "string", + "value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '/', parameters('glossaryFileName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]" + }, + "AZURE_TARGET_CONTAINER_URL": { + "type": "string", + "value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_1'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_1')).serviceSasToken)]" + }, + "AZURE_TARGET_CONTAINER_URL_FR": { + "type": "string", + "value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_2'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_2')).serviceSasToken)]" + }, + "AZURE_TARGET_CONTAINER_URL_AR": { + "type": "string", + "value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_3'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_3')).serviceSasToken)]" + }, + "AZURE_TARGET_CONTAINER_URL_ES": { + "type": "string", + "value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_4'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_4')).serviceSasToken)]" } } } \ No newline at end of file diff --git a/sdk/translation/tests.yml b/sdk/translation/tests.yml index b8f85cab3828..2dad0c62e8bd 100644 --- a/sdk/translation/tests.yml +++ b/sdk/translation/tests.yml @@ -6,6 +6,8 @@ stages: DeployArmTemplate: true BuildTargetingString: azure-ai-translation-document ServiceDirectory: translation + MatrixReplace: + - TestSamples=.*/true EnvVars: AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id) AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret)