Skip to content

Commit 6b6a612

Browse files
[translation] enable samples to run in CI (Azure#19190)
* adding dynamic env vars to let samples run in CI * fix resource group reference * fixes * remove temp skip of tests
1 parent aa29c1c commit 6b6a612

File tree

5 files changed

+180
-8
lines changed

5 files changed

+180
-8
lines changed

scripts/devops_tasks/test_run_samples.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
"release_phone_number_sample_async.py",
114114
"release_phone_number_sample.py"
115115
],
116+
"azure-ai-translation-document": [
117+
"sample_list_document_statuses_with_filters_async.py",
118+
"sample_list_translations_with_filters_async.py",
119+
"sample_list_document_statuses_with_filters.py",
120+
"sample_list_translations_with_filters.py",
121+
]
116122
}
117123

118124

sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def sample_document_status_checks_async():
4646
poller = await client.begin_translation(source_container_url, target_container_url, "es")
4747

4848
completed_docs = []
49-
while not poller.done():
49+
while poller.status() in ["Running", "NotStarted"]:
5050
await asyncio.sleep(30)
5151

5252
doc_statuses = client.list_all_document_statuses(poller.id)

sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ async def sample_translation_with_azure_blob(self):
6868

6969
source_container = await self.create_container(
7070
blob_service_client,
71-
container_name=self.storage_source_container_name or "translation-source-container",
71+
container_name=self.storage_source_container_name or "translation-source-container-async",
7272
)
7373
target_container = await self.create_container(
7474
blob_service_client,
75-
container_name=self.storage_target_container_name or "translation-target-container"
75+
container_name=self.storage_target_container_name or "translation-target-container-async"
7676
)
7777

7878
if self.document_name:

sdk/translation/test-resources.json

Lines changed: 169 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,90 @@
4646
"defaultValue": ".cognitiveservices.azure.com/",
4747
"type": "string"
4848
},
49-
"storageEndpointSuffix": {
50-
"defaultValue": ".blob.core.windows.net/",
51-
"type": "string"
52-
},
5349
"blobStorageAccount": {
5450
"type": "string",
5551
"defaultValue": "[concat(parameters('baseName'), 'prim')]"
52+
},
53+
"sourceStorageAccount": {
54+
"type": "string",
55+
"defaultValue": "krpraticstorageacc"
56+
},
57+
"sourceResourceId": {
58+
"type": "string",
59+
"defaultValue": "[resourceId('faa080af-c1d8-40ad-9cce-e1a450ca5b57', 'krpratic-rg', 'Microsoft.Storage/storageAccounts', parameters('sourceStorageAccount'))]"
60+
},
61+
"sourceContainerName": {
62+
"type": "string",
63+
"defaultValue": "testingtranslation"
64+
},
65+
"glossaryFileName": {
66+
"type": "string",
67+
"defaultValue": "glosario.tsv"
68+
},
69+
"sourceContainerSasProperties": {
70+
"type": "object",
71+
"defaultValue": {
72+
"canonicalizedResource": "[concat('/blob/', parameters('sourceStorageAccount'), '/', parameters('sourceContainerName'))]",
73+
"signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]",
74+
"signedPermission": "rl",
75+
"signedResource": "c"
76+
}
77+
},
78+
"targetResourceId": {
79+
"type": "string",
80+
"defaultValue": "[resourceId('Microsoft.Storage/storageAccounts', parameters('blobStorageAccount'))]"
81+
},
82+
"targetContainerName_1": {
83+
"type": "string",
84+
"defaultValue": "testingcontainer1"
85+
},
86+
"targetContainerSasProperties_1": {
87+
"type": "object",
88+
"defaultValue": {
89+
"canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_1'))]",
90+
"signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]",
91+
"signedPermission": "wl",
92+
"signedResource": "c"
93+
}
94+
},
95+
"targetContainerName_2": {
96+
"type": "string",
97+
"defaultValue": "testingcontainer2"
98+
},
99+
"targetContainerSasProperties_2": {
100+
"type": "object",
101+
"defaultValue": {
102+
"canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_2'))]",
103+
"signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]",
104+
"signedPermission": "wl",
105+
"signedResource": "c"
106+
}
107+
},
108+
"targetContainerName_3": {
109+
"type": "string",
110+
"defaultValue": "testingcontainer3"
111+
},
112+
"targetContainerSasProperties_3": {
113+
"type": "object",
114+
"defaultValue": {
115+
"canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_3'))]",
116+
"signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]",
117+
"signedPermission": "wl",
118+
"signedResource": "c"
119+
}
120+
},
121+
"targetContainerName_4": {
122+
"type": "string",
123+
"defaultValue": "testingcontainer4"
124+
},
125+
"targetContainerSasProperties_4": {
126+
"type": "object",
127+
"defaultValue": {
128+
"canonicalizedResource": "[concat('/blob/', parameters('blobStorageAccount'), '/', parameters('targetContainerName_4'))]",
129+
"signedExpiry": "[dateTimeAdd(utcNow('u'), 'PT3H')]",
130+
"signedPermission": "wl",
131+
"signedResource": "c"
132+
}
56133
}
57134
},
58135
"variables": {
@@ -63,6 +140,7 @@
63140
"storageAccountName": "[concat(parameters('baseName'), 'prim')]",
64141
"location": "[resourceGroup().location]",
65142
"azureDocTranslationUrl": "[concat('https://', variables('docTranslationBaseName'), parameters('docTranslationEndpointSuffix'))]",
143+
"azureStorageEndpoint": "[concat('https://', parameters('blobStorageAccount'), '.blob.core.windows.net/')]",
66144
"cognitiveServiceUserRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/a97b65f3-24c7-4388-baec-2e87135dc908')]",
67145
"encryption": {
68146
"services": {
@@ -120,7 +198,41 @@
120198
"supportsHttpsTrafficOnly": true,
121199
"encryption": "[variables('encryption')]",
122200
"accessTier": "Cool"
123-
}
201+
},
202+
"resources": [
203+
{
204+
"type": "blobServices/containers",
205+
"apiVersion": "[variables('storageMgmtApiVersion')]",
206+
"name": "[concat('default/', parameters('targetContainerName_1'))]",
207+
"dependsOn": [
208+
"[parameters('blobStorageAccount')]"
209+
]
210+
},
211+
{
212+
"type": "blobServices/containers",
213+
"apiVersion": "[variables('storageMgmtApiVersion')]",
214+
"name": "[concat('default/', parameters('targetContainerName_2'))]",
215+
"dependsOn": [
216+
"[parameters('blobStorageAccount')]"
217+
]
218+
},
219+
{
220+
"type": "blobServices/containers",
221+
"apiVersion": "[variables('storageMgmtApiVersion')]",
222+
"name": "[concat('default/', parameters('targetContainerName_3'))]",
223+
"dependsOn": [
224+
"[parameters('blobStorageAccount')]"
225+
]
226+
},
227+
{
228+
"type": "blobServices/containers",
229+
"apiVersion": "[variables('storageMgmtApiVersion')]",
230+
"name": "[concat('default/', parameters('targetContainerName_4'))]",
231+
"dependsOn": [
232+
"[parameters('blobStorageAccount')]"
233+
]
234+
}
235+
]
124236
}
125237
],
126238
"outputs": {
@@ -155,6 +267,58 @@
155267
"TRANSLATION_DOCUMENT_STORAGE_KEY": {
156268
"type": "string",
157269
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]"
270+
},
271+
"AZURE_DOCUMENT_TRANSLATION_KEY": {
272+
"type": "string",
273+
"value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('docTranslationBaseName')), variables('docTranslationApiVersion')).key1]"
274+
},
275+
"AZURE_DOCUMENT_TRANSLATION_ENDPOINT": {
276+
"type": "string",
277+
"value": "[variables('azureDocTranslationUrl')]"
278+
},
279+
"AZURE_STORAGE_ACCOUNT_NAME": {
280+
"type": "string",
281+
"value": "[parameters('blobStorageAccount')]"
282+
},
283+
"AZURE_STORAGE_SOURCE_KEY": {
284+
"type": "string",
285+
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]"
286+
},
287+
"AZURE_STORAGE_SOURCE_ENDPOINT": {
288+
"type": "string",
289+
"value": "[variables('azureStorageEndpoint')]"
290+
},
291+
"AZURE_SOURCE_CONTAINER_URL": {
292+
"type": "string",
293+
"value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
294+
},
295+
"AZURE_SOURCE_CONTAINER_URL_1": {
296+
"type": "string",
297+
"value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
298+
},
299+
"AZURE_SOURCE_CONTAINER_URL_2": {
300+
"type": "string",
301+
"value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
302+
},
303+
"AZURE_TRANSLATION_GLOSSARY_URL": {
304+
"type": "string",
305+
"value": "[concat(reference(parameters('sourceResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '/', parameters('glossaryFileName'), '?', listServiceSas(parameters('sourceResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
306+
},
307+
"AZURE_TARGET_CONTAINER_URL": {
308+
"type": "string",
309+
"value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_1'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_1')).serviceSasToken)]"
310+
},
311+
"AZURE_TARGET_CONTAINER_URL_FR": {
312+
"type": "string",
313+
"value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_2'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_2')).serviceSasToken)]"
314+
},
315+
"AZURE_TARGET_CONTAINER_URL_AR": {
316+
"type": "string",
317+
"value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_3'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_3')).serviceSasToken)]"
318+
},
319+
"AZURE_TARGET_CONTAINER_URL_ES": {
320+
"type": "string",
321+
"value": "[concat(reference(parameters('targetResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_4'), '?', listServiceSas(parameters('targetResourceId'), '2019-06-01', parameters('targetContainerSasProperties_4')).serviceSasToken)]"
158322
}
159323
}
160324
}

sdk/translation/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ stages:
66
DeployArmTemplate: true
77
BuildTargetingString: azure-ai-translation-document
88
ServiceDirectory: translation
9+
MatrixReplace:
10+
- TestSamples=.*/true
911
EnvVars:
1012
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
1113
AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret)

0 commit comments

Comments
 (0)