-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[translation] add ARM template and set up test preparers (#17146)
* adding arm template for doc translation * runs and creates container + sas url * add preparer, wip arm template * creating sas token with storage * remove client polling interval * fix tests.yml to deploy arm template * fixes to testcase and arm template * make sure storage account name unique * remove max parallel == 1 * accidentally reverted rg name * try using storage to create containers * just build the storage endpoint * fix recorded tests * support creating more than one blob in container * add blob prefix option * sean's feedback * fix ci.yml
- Loading branch information
1 parent
3b7c11e
commit 6a7cedd
Showing
10 changed files
with
567 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sdk/documenttranslation/azure-ai-documenttranslation/tests/preparer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
# coding: utf-8 | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
import os | ||
import functools | ||
from devtools_testutils import PowerShellPreparer, AzureMgmtPreparer | ||
from azure.core.credentials import AzureKeyCredential | ||
|
||
|
||
DocumentTranslationPreparer = functools.partial( | ||
PowerShellPreparer, | ||
'documenttranslation', | ||
documenttranslation_test_endpoint="https://redacted.cognitiveservices.azure.com/", | ||
documenttranslation_test_api_key="fakeZmFrZV9hY29jdW50X2tleQ==", | ||
documenttranslation_name="redacted", | ||
documenttranslation_storage_name="redacted", | ||
documenttranslation_storage_key="fakeZmFrZV9hY29jdW50X2tleQ==" | ||
) | ||
|
||
|
||
class DocumentTranslationClientPreparer(AzureMgmtPreparer): | ||
def __init__(self, client_cls, client_kwargs={}, **kwargs): | ||
super(DocumentTranslationClientPreparer, self).__init__( | ||
name_prefix='', | ||
random_name_length=42 | ||
) | ||
self.client_kwargs = client_kwargs | ||
self.client_cls = client_cls | ||
|
||
def create_resource(self, name, **kwargs): | ||
doctranslation_test_endpoint = kwargs.get("documenttranslation_test_endpoint") | ||
doctranslation_test_api_key = kwargs.get("documenttranslation_test_api_key") | ||
|
||
|
||
client = self.client_cls( | ||
doctranslation_test_endpoint, | ||
AzureKeyCredential(doctranslation_test_api_key), | ||
**self.client_kwargs | ||
) | ||
kwargs.update({"client": client}) | ||
return kwargs |
218 changes: 218 additions & 0 deletions
218
...ranslation/azure-ai-documenttranslation/tests/recordings/test_service.test_translate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- application/xml | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '0' | ||
User-Agent: | ||
- azsdk-python-storage-blob/12.8.0 Python/3.9.0 (Windows-10-10.0.19041-SP0) | ||
x-ms-date: | ||
- Tue, 16 Mar 2021 18:51:11 GMT | ||
x-ms-version: | ||
- '2020-06-12' | ||
method: PUT | ||
uri: https://redacted.blob.core.windows.net/src62ef0d59-2d8a-4e0e-ad67-8ca442eb5cb9?restype=container | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
content-length: | ||
- '0' | ||
date: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
etag: | ||
- '"0x8D8E8AC7DBBD706"' | ||
last-modified: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
server: | ||
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 | ||
x-ms-version: | ||
- '2020-06-12' | ||
status: | ||
code: 201 | ||
message: Created | ||
- request: | ||
body: This is written in english. | ||
headers: | ||
Accept: | ||
- application/xml | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '27' | ||
Content-Type: | ||
- application/octet-stream | ||
If-None-Match: | ||
- '*' | ||
User-Agent: | ||
- azsdk-python-storage-blob/12.8.0 Python/3.9.0 (Windows-10-10.0.19041-SP0) | ||
x-ms-blob-type: | ||
- BlockBlob | ||
x-ms-date: | ||
- Tue, 16 Mar 2021 18:51:12 GMT | ||
x-ms-encryption-algorithm: | ||
- AES256 | ||
x-ms-version: | ||
- '2020-06-12' | ||
method: PUT | ||
uri: https://redacted.blob.core.windows.net/src62ef0d59-2d8a-4e0e-ad67-8ca442eb5cb9/ccda6168-42dd-4239-80f2-0aecf398e94f.txt | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
content-length: | ||
- '0' | ||
content-md5: | ||
- mYgA0QpY6baiB+xZp8Hk+A== | ||
date: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
etag: | ||
- '"0x8D8E8AC7DC61C66"' | ||
last-modified: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
server: | ||
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 | ||
x-ms-content-crc64: | ||
- NB4xBtawP6g= | ||
x-ms-request-server-encrypted: | ||
- 'true' | ||
x-ms-version: | ||
- '2020-06-12' | ||
status: | ||
code: 201 | ||
message: Created | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- application/xml | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '0' | ||
User-Agent: | ||
- azsdk-python-storage-blob/12.8.0 Python/3.9.0 (Windows-10-10.0.19041-SP0) | ||
x-ms-date: | ||
- Tue, 16 Mar 2021 18:51:12 GMT | ||
x-ms-version: | ||
- '2020-06-12' | ||
method: PUT | ||
uri: https://redacted.blob.core.windows.net/target368c8609-a7ea-4b5b-9dde-934f66132328?restype=container | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
content-length: | ||
- '0' | ||
date: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
etag: | ||
- '"0x8D8E8AC7DE884EA"' | ||
last-modified: | ||
- Tue, 16 Mar 2021 18:51:21 GMT | ||
server: | ||
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 | ||
x-ms-version: | ||
- '2020-06-12' | ||
status: | ||
code: 201 | ||
message: Created | ||
- request: | ||
body: '{"inputs": [{"source": {"sourceUrl": "https://redacted.blob.core.windows.net/src62ef0d59-2d8a-4e0e-ad67-8ca442eb5cb9?se=end&sp=rl&sv=2020-06-12&sr=c&sig=fake_token_value"}, | ||
"targets": [{"targetUrl": "https://redacted.blob.core.windows.net/target368c8609-a7ea-4b5b-9dde-934f66132328?se=end&sp=racwdl&sv=2020-06-12&sr=c&sig=fake_token_value", | ||
"language": "es"}]}]}' | ||
headers: | ||
Accept: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '474' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- azsdk-python-ai-translatortext/1.0.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0) | ||
method: POST | ||
uri: https://redacted.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1/batches | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
apim-request-id: | ||
- 680aea25-5542-4a93-b1a8-8ef4bb8734de | ||
content-length: | ||
- '0' | ||
date: | ||
- Tue, 16 Mar 2021 18:51:22 GMT | ||
operation-location: | ||
- https://redacted.cognitiveservices.azure.com/translatortext/batch/v1.0-preview.1/batches/ff5fc438-83d3-4e50-bf13-26b4505a93cc | ||
set-cookie: | ||
- ARRAffinity=5dd610bbbfcdcce1e8b7e036dad4b7c92b91df5adc2f4b536e67d2a5eff0940e;Path=/;HttpOnly;Secure;Domain=doctrans.westus.microsofttranslator.com | ||
- ARRAffinitySameSite=5dd610bbbfcdcce1e8b7e036dad4b7c92b91df5adc2f4b536e67d2a5eff0940e;Path=/;HttpOnly;SameSite=None;Secure;Domain=doctrans.westus.microsofttranslator.com | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains; preload | ||
x-content-type-options: | ||
- nosniff | ||
x-powered-by: | ||
- ASP.NET | ||
x-requestid: | ||
- 80004b6a-0003-ec00-b63f-84710c7967bb | ||
status: | ||
code: 202 | ||
message: Accepted | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- azsdk-python-ai-translatortext/1.0.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0) | ||
method: GET | ||
uri: https://redacted.cognitiveservices.azure.com/translator/text/batch/v1.0-preview.1/batches/ff5fc438-83d3-4e50-bf13-26b4505a93cc | ||
response: | ||
body: | ||
string: '{"id":"ff5fc438-83d3-4e50-bf13-26b4505a93cc","createdDateTimeUtc":"2021-03-16T18:51:22.2869529Z","lastActionDateTimeUtc":"2021-03-16T18:51:22.2869593Z","status":"NotStarted","summary":{"total":1,"failed":0,"success":0,"inProgress":0,"notYetStarted":1,"cancelled":0,"totalCharacterCharged":0}}' | ||
headers: | ||
apim-request-id: | ||
- 757bca98-ee54-47e5-b6ce-8e773a2ff780 | ||
content-length: | ||
- '292' | ||
content-type: | ||
- application/json; charset=utf-8 | ||
date: | ||
- Tue, 16 Mar 2021 18:51:52 GMT | ||
set-cookie: | ||
- ARRAffinity=19727efd86700e5294e01d3d9816fda18b4016b330aceb2a79043575a77e402c;Path=/;HttpOnly;Secure;Domain=doctrans.westus.microsofttranslator.com | ||
- ARRAffinitySameSite=19727efd86700e5294e01d3d9816fda18b4016b330aceb2a79043575a77e402c;Path=/;HttpOnly;SameSite=None;Secure;Domain=doctrans.westus.microsofttranslator.com | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains; preload | ||
transfer-encoding: | ||
- chunked | ||
vary: | ||
- Accept-Encoding | ||
x-content-type-options: | ||
- nosniff | ||
x-powered-by: | ||
- ASP.NET | ||
x-requestid: | ||
- 8000439b-0003-f400-b63f-84710c7967bb | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
42 changes: 42 additions & 0 deletions
42
sdk/documenttranslation/azure-ai-documenttranslation/tests/test_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# coding=utf-8 | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
import functools | ||
from testcase import DocumentTranslationTest | ||
from preparer import DocumentTranslationPreparer, DocumentTranslationClientPreparer as _DocumentTranslationClientPreparer | ||
from azure.ai.documenttranslation import DocumentTranslationClient, BatchDocumentInput, StorageTarget | ||
DocumentTranslationClientPreparer = functools.partial(_DocumentTranslationClientPreparer, DocumentTranslationClient) | ||
|
||
|
||
class TestTranslation(DocumentTranslationTest): | ||
|
||
@DocumentTranslationPreparer() | ||
@DocumentTranslationClientPreparer() | ||
def test_translate(self, client): | ||
# this uses generated code and should be deleted. Using it to test live tests pending our code in master | ||
from azure.ai.documenttranslation._generated.models import BatchRequest, SourceInput, TargetInput | ||
self._setup() # set up test resources | ||
|
||
response_headers = client._client.document_translation._submit_batch_request_initial( | ||
inputs=[ | ||
BatchRequest( | ||
source=SourceInput( | ||
source_url=self.source_container_sas_url | ||
), | ||
targets=[TargetInput( | ||
target_url=self.target_container_sas_url, | ||
language="es" | ||
)] | ||
) | ||
], | ||
cls=lambda pipeline_response, _, response_headers: response_headers | ||
) | ||
|
||
batch_id = response_headers['Operation-Location'].split('/')[-1] | ||
assert batch_id | ||
self.wait() | ||
result = client._client.document_translation.get_operation_status(batch_id) | ||
assert result |
15 changes: 0 additions & 15 deletions
15
sdk/documenttranslation/azure-ai-documenttranslation/tests/test_supported_methods.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.