From b06c979952daea6748cff0db42fa33a91a8b12ad Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 13 May 2020 15:16:05 -0400 Subject: [PATCH 1/3] updated tests --- .../formrecognizer/_form_recognizer_client.py | 20 +- .../formrecognizer/_form_training_client.py | 20 +- .../aio/_form_recognizer_client_async.py | 19 +- .../aio/_form_training_client_async.py | 19 +- ..._mgmt.test_get_form_recognizer_client.yaml | 184 ++++++++++++++++++ ...async.test_get_form_recognizer_client.yaml | 105 ++++++++++ .../tests/test_custom_forms.py | 66 +++---- .../tests/test_custom_forms_async.py | 66 +++---- .../tests/test_custom_forms_from_url.py | 66 +++---- .../tests/test_custom_forms_from_url_async.py | 66 +++---- .../tests/test_mgmt.py | 16 +- .../tests/test_mgmt_async.py | 14 +- 12 files changed, 474 insertions(+), 187 deletions(-) create mode 100644 sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt.test_get_form_recognizer_client.yaml create mode 100644 sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt_async.test_get_form_recognizer_client.yaml diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py index 891ea4320e7e..c218a02d18ca 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py @@ -26,7 +26,6 @@ from ._helpers import get_content_type, error_map, POLLING_INTERVAL, COGNITIVE_KEY_HEADER from ._user_agent import USER_AGENT from ._polling import AnalyzePolling -from ._form_training_client import FormTrainingClient if TYPE_CHECKING: from azure.core.credentials import AzureKeyCredential @@ -55,11 +54,9 @@ class FormRecognizerClient(object): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, Any) -> None - self._endpoint = endpoint - self._credential = credential self._client = FormRecognizer( - endpoint=self._endpoint, - credential=self._credential, + endpoint=endpoint, + credential=credential, sdk_moniker=USER_AGENT, authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER), **kwargs @@ -334,19 +331,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume **kwargs ) - def get_form_training_client(self, **kwargs): - # type: (Any) -> FormTrainingClient - """Get an instance of a FormTrainingClient from FormRecognizerClient. - - :rtype: ~azure.ai.formrecognizer.FormTrainingClient - :return: A FormTrainingClient - """ - return FormTrainingClient( - endpoint=self._endpoint, - credential=self._credential, - **kwargs - ) - def close(self): # type: () -> None """Close the :class:`~azure.ai.formrecognizer.FormRecognizerClient` session. diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py index e699dbac99ab..a13d8634c539 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py @@ -27,6 +27,7 @@ ) from ._polling import TrainingPolling from ._user_agent import USER_AGENT +from ._form_recognizer_client import FormRecognizerClient if TYPE_CHECKING: from azure.core.credentials import AzureKeyCredential from azure.core.pipeline.transport import HttpResponse @@ -57,9 +58,11 @@ class FormTrainingClient(object): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, Any) -> None + self._endpoint = endpoint + self._credential = credential self._client = FormRecognizer( - endpoint=endpoint, - credential=credential, + endpoint=self._endpoint, + credential=self._credential, sdk_moniker=USER_AGENT, authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER), **kwargs @@ -224,6 +227,19 @@ def get_custom_model(self, model_id, **kwargs): response = self._client.get_custom_model(model_id=model_id, include_keys=True, error_map=error_map, **kwargs) return CustomFormModel._from_generated(response) + def get_form_recognizer_client(self, **kwargs): + # type: (Any) -> FormRecognizerClient + """Get an instance of a FormRecognizerClient from FormTrainingClient. + + :rtype: ~azure.ai.formrecognizer.FormRecognizerClient + :return: A FormRecognizerClient + """ + return FormRecognizerClient( + endpoint=self._endpoint, + credential=self._credential, + **kwargs + ) + def close(self): # type: () -> None """Close the :class:`~azure.ai.formrecognizer.FormTrainingClient` session. diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py index f4c3d40485f4..d389d4d4e5c4 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py @@ -16,7 +16,6 @@ from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.polling.async_base_polling import AsyncLROBasePolling from azure.core.pipeline.policies import AzureKeyCredentialPolicy -from ._form_training_client_async import FormTrainingClient from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer from .._response_handlers import ( prepare_us_receipt, @@ -64,11 +63,9 @@ def __init__( credential: "AzureKeyCredential", **kwargs: Any ) -> None: - self._endpoint = endpoint - self._credential = credential self._client = FormRecognizer( - endpoint=self._endpoint, - credential=self._credential, + endpoint=endpoint, + credential=credential, sdk_moniker=USER_AGENT, authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER), **kwargs @@ -349,18 +346,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume **kwargs ) - def get_form_training_client(self, **kwargs: Any) -> FormTrainingClient: - """Get an instance of a FormTrainingClient from FormRecognizerClient. - - :rtype: ~azure.ai.formrecognizer.aio.FormTrainingClient - :return: A FormTrainingClient - """ - return FormTrainingClient( - endpoint=self._endpoint, - credential=self._credential, - **kwargs - ) - async def __aenter__(self) -> "FormRecognizerClient": await self._client.__aenter__() return self diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py index 51798412b6bb..0e48262462d8 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py @@ -17,6 +17,7 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.pipeline.policies import AzureKeyCredentialPolicy +from ._form_recognizer_client_async import FormRecognizerClient from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer from .._generated.models import TrainRequest, TrainSourceFilter from .._generated.models import Model @@ -60,9 +61,11 @@ def __init__( credential: "AzureKeyCredential", **kwargs: Any ) -> None: + self._endpoint = endpoint + self._credential = credential self._client = FormRecognizer( - endpoint=endpoint, - credential=credential, + endpoint=self._endpoint, + credential=self._credential, sdk_moniker=USER_AGENT, authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER), **kwargs @@ -230,6 +233,18 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode ) return CustomFormModel._from_generated(response) + def get_form_recognizer_client(self, **kwargs: Any) -> FormRecognizerClient: + """Get an instance of a FormRecognizerClient from FormTrainingClient. + + :rtype: ~azure.ai.formrecognizer.aio.FormRecognizerClient + :return: A FormRecognizerClient + """ + return FormRecognizerClient( + endpoint=self._endpoint, + credential=self._credential, + **kwargs + ) + async def __aenter__(self) -> "FormTrainingClient": await self._client.__aenter__() return self diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt.test_get_form_recognizer_client.yaml b/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt.test_get_form_recognizer_client.yaml new file mode 100644 index 000000000000..429af9c7b6b0 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt.test_get_form_recognizer_client.yaml @@ -0,0 +1,184 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary + response: + body: + string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:33Z"}}' + headers: + apim-request-id: + - 49d7757e-2cea-4126-8660-1b64832e48d7 + content-type: + - application/json; charset=utf-8 + date: + - Wed, 13 May 2020 16:13:32 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '5109' + status: + code: 200 + message: OK +- request: + body: '{"source": "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-allinone.jpg"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '172' + Content-Type: + - application/json + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: POST + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyze?includeTextDetails=false + response: + body: + string: '' + headers: + apim-request-id: + - 7f8f4fe8-1330-4bb1-8030-9e96ca52adc2 + content-length: + - '0' + date: + - Wed, 13 May 2020 16:13:34 GMT + operation-location: + - https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '1478' + status: + code: 202 + message: Accepted +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2 + response: + body: + string: '{"status":"running","createdDateTime":"2020-05-13T16:13:34Z","lastUpdatedDateTime":"2020-05-13T16:13:35Z"}' + headers: + apim-request-id: + - 2f458f0e-eccf-4da2-ab90-05c85f13f58b + content-type: + - application/json; charset=utf-8 + date: + - Wed, 13 May 2020 16:13:40 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '138' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2 + response: + body: + string: '{"status":"succeeded","createdDateTime":"2020-05-13T16:13:34Z","lastUpdatedDateTime":"2020-05-13T16:13:43Z","analyzeResult":{"version":"2.0.0","readResults":[{"page":1,"angle":0.6893,"width":1688,"height":3000,"unit":"pixel","language":"en"}],"documentResults":[{"docType":"prebuilt:receipt","pageRange":[1,1],"fields":{"ReceiptType":{"type":"string","valueString":"Itemized","confidence":0.692},"MerchantName":{"type":"string","valueString":"Contoso + Contoso","text":"Contoso Contoso","boundingBox":[378.2,292.4,1117.7,468.3,1035.7,812.7,296.3,636.8],"page":1,"confidence":0.613},"MerchantAddress":{"type":"string","valueString":"123 + Main Street Redmond, WA 98052","text":"123 Main Street Redmond, WA 98052","boundingBox":[302,675.8,848.1,793.7,809.9,970.4,263.9,852.5],"page":1,"confidence":0.99},"MerchantPhoneNumber":{"type":"phoneNumber","valuePhoneNumber":"+19876543210","text":"987-654-3210","boundingBox":[278,1004,656.3,1054.7,646.8,1125.3,268.5,1074.7],"page":1,"confidence":0.99},"TransactionDate":{"type":"date","valueDate":"2019-06-10","text":"6/10/2019","boundingBox":[265.1,1228.4,525,1247,518.9,1332.1,259,1313.5],"page":1,"confidence":0.99},"TransactionTime":{"type":"time","valueTime":"13:59:00","text":"13:59","boundingBox":[541,1248,677.3,1261.5,668.9,1346.5,532.6,1333],"page":1,"confidence":0.977},"Items":{"type":"array","valueArray":[{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[245.1,1581.5,300.9,1585.1,295,1676,239.2,1672.4],"page":1,"confidence":0.92},"Name":{"type":"string","valueString":"Cappuccino","text":"Cappuccino","boundingBox":[322,1586,654.2,1601.1,650,1693,317.8,1678],"page":1,"confidence":0.923},"TotalPrice":{"type":"number","valueNumber":2.2,"text":"$2.20","boundingBox":[1107.7,1584,1263,1574,1268.3,1656,1113,1666],"page":1,"confidence":0.918}}},{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[232,1834,286.6,1835,285,1921,230.4,1920],"page":1,"confidence":0.858},"Name":{"type":"string","valueString":"BACON + & EGGS","text":"BACON & EGGS","boundingBox":[308,1836,746,1841.4,745,1925.4,307,1920],"page":1,"confidence":0.916},"TotalPrice":{"type":"number","text":"$9.5","boundingBox":[1133.9,1955,1257,1952,1259.1,2036,1136,2039],"page":1,"confidence":0.916}}}]},"Subtotal":{"type":"number","valueNumber":11.7,"text":"11.70","boundingBox":[1146,2221,1297.3,2223,1296,2319,1144.7,2317],"page":1,"confidence":0.955},"Tax":{"type":"number","valueNumber":1.17,"text":"1.17","boundingBox":[1190,2359,1304,2359,1304,2456,1190,2456],"page":1,"confidence":0.979},"Tip":{"type":"number","valueNumber":1.63,"text":"1.63","boundingBox":[1094,2479,1267.7,2485,1264,2591,1090.3,2585],"page":1,"confidence":0.941},"Total":{"type":"number","valueNumber":14.5,"text":"$14.50","boundingBox":[1034.2,2617,1387.5,2638.2,1380,2763,1026.7,2741.8],"page":1,"confidence":0.985}}}]}}' + headers: + apim-request-id: + - 195addaa-7fcc-4053-bceb-5087740c57ed + content-type: + - application/json; charset=utf-8 + date: + - Wed, 13 May 2020 16:13:45 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '378' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary + response: + body: + string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:47Z"}}' + headers: + apim-request-id: + - fa489acc-6458-4098-8379-b1f9389b3e1e + content-type: + - application/json; charset=utf-8 + date: + - Wed, 13 May 2020 16:13:46 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '168' + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt_async.test_get_form_recognizer_client.yaml b/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt_async.test_get_form_recognizer_client.yaml new file mode 100644 index 000000000000..ccf9cb209957 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/recordings/test_mgmt_async.test_get_form_recognizer_client.yaml @@ -0,0 +1,105 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary + response: + body: + string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:48Z"}}' + headers: + apim-request-id: 7bd4ca53-2060-4abd-b1ab-67a10a603095 + content-type: application/json; charset=utf-8 + date: Wed, 13 May 2020 16:13:48 GMT + strict-transport-security: max-age=31536000; includeSubDomains; preload + transfer-encoding: chunked + x-content-type-options: nosniff + x-envoy-upstream-service-time: '9' + status: + code: 200 + message: OK + url: https://westus.api.cognitive.microsoft.com//formrecognizer/v2.0-preview/custom/models?op=summary +- request: + body: '{"source": "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-allinone.jpg"}' + headers: + Content-Length: + - '172' + Content-Type: + - application/json + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: POST + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyze?includeTextDetails=false + response: + body: + string: '' + headers: + apim-request-id: 4164c2e3-437a-46f3-a880-316414895e40 + content-length: '0' + date: Wed, 13 May 2020 16:13:49 GMT + operation-location: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/4164c2e3-437a-46f3-a880-316414895e40 + strict-transport-security: max-age=31536000; includeSubDomains; preload + x-content-type-options: nosniff + x-envoy-upstream-service-time: '701' + status: + code: 202 + message: Accepted + url: https://westus.api.cognitive.microsoft.com//formrecognizer/v2.0-preview/prebuilt/receipt/analyze?includeTextDetails=false +- request: + body: null + headers: + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/4164c2e3-437a-46f3-a880-316414895e40 + response: + body: + string: '{"status":"succeeded","createdDateTime":"2020-05-13T16:13:49Z","lastUpdatedDateTime":"2020-05-13T16:13:52Z","analyzeResult":{"version":"2.0.0","readResults":[{"page":1,"angle":0.6893,"width":1688,"height":3000,"unit":"pixel","language":"en"}],"documentResults":[{"docType":"prebuilt:receipt","pageRange":[1,1],"fields":{"ReceiptType":{"type":"string","valueString":"Itemized","confidence":0.692},"MerchantName":{"type":"string","valueString":"Contoso + Contoso","text":"Contoso Contoso","boundingBox":[378.2,292.4,1117.7,468.3,1035.7,812.7,296.3,636.8],"page":1,"confidence":0.613},"MerchantAddress":{"type":"string","valueString":"123 + Main Street Redmond, WA 98052","text":"123 Main Street Redmond, WA 98052","boundingBox":[302,675.8,848.1,793.7,809.9,970.4,263.9,852.5],"page":1,"confidence":0.99},"MerchantPhoneNumber":{"type":"phoneNumber","valuePhoneNumber":"+19876543210","text":"987-654-3210","boundingBox":[278,1004,656.3,1054.7,646.8,1125.3,268.5,1074.7],"page":1,"confidence":0.99},"TransactionDate":{"type":"date","valueDate":"2019-06-10","text":"6/10/2019","boundingBox":[265.1,1228.4,525,1247,518.9,1332.1,259,1313.5],"page":1,"confidence":0.99},"TransactionTime":{"type":"time","valueTime":"13:59:00","text":"13:59","boundingBox":[541,1248,677.3,1261.5,668.9,1346.5,532.6,1333],"page":1,"confidence":0.977},"Items":{"type":"array","valueArray":[{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[245.1,1581.5,300.9,1585.1,295,1676,239.2,1672.4],"page":1,"confidence":0.92},"Name":{"type":"string","valueString":"Cappuccino","text":"Cappuccino","boundingBox":[322,1586,654.2,1601.1,650,1693,317.8,1678],"page":1,"confidence":0.923},"TotalPrice":{"type":"number","valueNumber":2.2,"text":"$2.20","boundingBox":[1107.7,1584,1263,1574,1268.3,1656,1113,1666],"page":1,"confidence":0.918}}},{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[232,1834,286.6,1835,285,1921,230.4,1920],"page":1,"confidence":0.858},"Name":{"type":"string","valueString":"BACON + & EGGS","text":"BACON & EGGS","boundingBox":[308,1836,746,1841.4,745,1925.4,307,1920],"page":1,"confidence":0.916},"TotalPrice":{"type":"number","text":"$9.5","boundingBox":[1133.9,1955,1257,1952,1259.1,2036,1136,2039],"page":1,"confidence":0.916}}}]},"Subtotal":{"type":"number","valueNumber":11.7,"text":"11.70","boundingBox":[1146,2221,1297.3,2223,1296,2319,1144.7,2317],"page":1,"confidence":0.955},"Tax":{"type":"number","valueNumber":1.17,"text":"1.17","boundingBox":[1190,2359,1304,2359,1304,2456,1190,2456],"page":1,"confidence":0.979},"Tip":{"type":"number","valueNumber":1.63,"text":"1.63","boundingBox":[1094,2479,1267.7,2485,1264,2591,1090.3,2585],"page":1,"confidence":0.941},"Total":{"type":"number","valueNumber":14.5,"text":"$14.50","boundingBox":[1034.2,2617,1387.5,2638.2,1380,2763,1026.7,2741.8],"page":1,"confidence":0.985}}}]}}' + headers: + apim-request-id: 7be2b8dc-1d16-4fc6-8f20-a66a121787cd + content-type: application/json; charset=utf-8 + date: Wed, 13 May 2020 16:13:54 GMT + strict-transport-security: max-age=31536000; includeSubDomains; preload + transfer-encoding: chunked + x-content-type-options: nosniff + x-envoy-upstream-service-time: '16' + status: + code: 200 + message: OK + url: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/4164c2e3-437a-46f3-a880-316414895e40 +- request: + body: null + headers: + Accept: + - application/json + User-Agent: + - azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit) + method: GET + uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary + response: + body: + string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:55Z"}}' + headers: + apim-request-id: 15cd571c-a214-4c66-8563-2279b34755a5 + content-type: application/json; charset=utf-8 + date: Wed, 13 May 2020 16:13:54 GMT + strict-transport-security: max-age=31536000; includeSubDomains; preload + transfer-encoding: chunked + x-content-type-options: nosniff + x-envoy-upstream-service-time: '10' + status: + code: 200 + message: OK + url: https://westus.api.cognitive.microsoft.com//formrecognizer/v2.0-preview/custom/models?op=summary +version: 1 diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms.py index 6261efaee871..761498e3b1e0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms.py @@ -7,14 +7,14 @@ import functools from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import ServiceRequestError, ClientAuthenticationError, HttpResponseError -from azure.ai.formrecognizer import FormRecognizerClient, FormContentType +from azure.ai.formrecognizer import FormRecognizerClient, FormContentType, FormTrainingClient from azure.ai.formrecognizer._generated.models import AnalyzeOperationResult from azure.ai.formrecognizer._response_handlers import prepare_form_result from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer from testcase import GlobalTrainingAccountPreparer as _GlobalTrainingAccountPreparer -GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormRecognizerClient) +GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormTrainingClient) class TestCustomForms(FormRecognizerTest): @@ -56,13 +56,13 @@ def test_auto_detect_unsupported_stream_content(self, resource_group, location, @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_damaged_file(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() with self.assertRaises(HttpResponseError): - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, b"\x25\x50\x44\x46\x55\x55\x55", ) @@ -71,13 +71,13 @@ def test_custom_form_damaged_file(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() with open(self.form_jpg, "rb") as stream: - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, stream, content_type=FormContentType.image_jpeg @@ -97,13 +97,13 @@ def test_custom_form_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) def test_custom_form_multipage_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() with open(self.multipage_invoice_pdf, "rb") as stream: - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, stream, content_type=FormContentType.application_pdf @@ -124,9 +124,9 @@ def test_custom_form_multipage_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model( + poller = client.begin_train_model( container_sas_url, use_labels=True ) @@ -135,7 +135,7 @@ def test_custom_form_labeled(self, client, container_sas_url): with open(self.form_jpg, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) + poller = fr_client.begin_recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) form = poller.result() self.assertEqual(form[0].form_type, "form-"+model.model_id) @@ -150,9 +150,9 @@ def test_custom_form_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) def test_custom_form_multipage_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model( + poller = client.begin_train_model( container_sas_url, use_labels=True ) @@ -161,7 +161,7 @@ def test_custom_form_multipage_labeled(self, client, container_sas_url): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, myfile, content_type=FormContentType.application_pdf @@ -181,15 +181,15 @@ def test_custom_form_multipage_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -197,7 +197,7 @@ def callback(raw_response, _, headers): with open(self.form_jpg, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -218,15 +218,15 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) def test_custom_form_multipage_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -234,7 +234,7 @@ def callback(raw_response, _, headers): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -256,15 +256,15 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -272,7 +272,7 @@ def callback(raw_response, _, headers): with open(self.form_jpg, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -293,15 +293,15 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) def test_custom_form_multipage_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -309,7 +309,7 @@ def callback(raw_response, _, headers): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - poller = client.begin_recognize_custom_forms( + poller = fr_client.begin_recognize_custom_forms( model.model_id, myfile, include_text_content=True, diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_async.py index 7e83718a9e7d..7ac09ac5a2fb 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_async.py @@ -8,7 +8,7 @@ from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import ServiceRequestError, ClientAuthenticationError, HttpResponseError from azure.ai.formrecognizer import FormContentType -from azure.ai.formrecognizer.aio import FormRecognizerClient +from azure.ai.formrecognizer.aio import FormRecognizerClient, FormTrainingClient from azure.ai.formrecognizer._generated.models import AnalyzeOperationResult from azure.ai.formrecognizer._response_handlers import prepare_form_result from testcase import GlobalFormRecognizerAccountPreparer @@ -16,7 +16,7 @@ from asynctestcase import AsyncFormRecognizerTest -GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormRecognizerClient) +GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormTrainingClient) class TestCustomFormsAsync(AsyncFormRecognizerTest): @@ -58,12 +58,12 @@ async def test_auto_detect_unsupported_stream_content(self, resource_group, loca @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_custom_form_damaged_file(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) with self.assertRaises(HttpResponseError): - form = await client.recognize_custom_forms( + form = await fr_client.recognize_custom_forms( model.model_id, b"\x25\x50\x44\x46\x55\x55\x55", ) @@ -71,14 +71,14 @@ async def test_custom_form_damaged_file(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_custom_form_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) with open(self.form_jpg, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) + form = await fr_client.recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) self.assertEqual(form[0].form_type, "form-0") self.assertFormPagesHasValues(form[0].pages) @@ -93,13 +93,13 @@ async def test_custom_form_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) async def test_custom_form_multipage_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - forms = await client.recognize_custom_forms( + forms = await fr_client.recognize_custom_forms( model.model_id, myfile, content_type=FormContentType.application_pdf @@ -119,14 +119,14 @@ async def test_custom_form_multipage_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_custom_form_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) with open(self.form_jpg, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) + form = await fr_client.recognize_custom_forms(model.model_id, myfile, content_type=FormContentType.image_jpeg) self.assertEqual(form[0].form_type, "form-"+model.model_id) self.assertFormPagesHasValues(form[0].pages) @@ -140,9 +140,9 @@ async def test_custom_form_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) async def test_custom_form_multipage_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model( + model = await client.train_model( container_sas_url, use_labels=True ) @@ -150,7 +150,7 @@ async def test_custom_form_multipage_labeled(self, client, container_sas_url): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - forms = await client.recognize_custom_forms( + forms = await fr_client.recognize_custom_forms( model.model_id, myfile, content_type=FormContentType.application_pdf @@ -170,14 +170,14 @@ async def test_custom_form_multipage_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -185,7 +185,7 @@ def callback(raw_response, _, headers): with open(self.form_jpg, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms( + form = await fr_client.recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -206,14 +206,14 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) async def test_custom_forms_multipage_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -221,7 +221,7 @@ def callback(raw_response, _, headers): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms( + form = await fr_client.recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -244,14 +244,14 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -259,7 +259,7 @@ def callback(raw_response, _, headers): with open(self.form_jpg, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms( + form = await fr_client.recognize_custom_forms( model.model_id, myfile, include_text_content=True, @@ -280,14 +280,14 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True) async def test_custom_forms_multipage_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) @@ -295,7 +295,7 @@ def callback(raw_response, _, headers): with open(self.multipage_invoice_pdf, "rb") as fd: myfile = fd.read() - form = await client.recognize_custom_forms( + form = await fr_client.recognize_custom_forms( model.model_id, myfile, include_text_content=True, diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url.py index b43e1384a82e..d995161e12c0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url.py @@ -7,14 +7,14 @@ import functools from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import HttpResponseError, ServiceRequestError, ClientAuthenticationError -from azure.ai.formrecognizer import FormRecognizerClient +from azure.ai.formrecognizer import FormRecognizerClient, FormTrainingClient from azure.ai.formrecognizer._generated.models import AnalyzeOperationResult from azure.ai.formrecognizer._response_handlers import prepare_form_result from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer from testcase import GlobalTrainingAccountPreparer as _GlobalTrainingAccountPreparer -GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormRecognizerClient) +GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormTrainingClient) class TestCustomFormsFromUrl(FormRecognizerTest): @@ -52,13 +52,13 @@ def test_pass_stream_into_url(self, resource_group, location, form_recognizer_ac @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_bad_url(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() with self.assertRaises(HttpResponseError): - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, url="https://badurl.jpg" ) @@ -67,12 +67,12 @@ def test_custom_form_bad_url(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() - poller = client.begin_recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) + poller = fr_client.begin_recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) form = poller.result() self.assertEqual(form[0].form_type, "form-0") @@ -88,12 +88,12 @@ def test_custom_form_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) def test_form_multipage_unlabeled(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, blob_sas_url ) @@ -113,12 +113,12 @@ def test_form_multipage_unlabeled(self, client, container_sas_url, blob_sas_url) @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() - poller = client.begin_recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) + poller = fr_client.begin_recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) form = poller.result() self.assertEqual(form[0].form_type, "form-"+model.model_id) @@ -133,15 +133,15 @@ def test_custom_form_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model( + poller = client.begin_train_model( container_sas_url, use_labels=True ) model = poller.result() - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, blob_sas_url ) @@ -161,20 +161,20 @@ def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_custom_form_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, self.form_url_jpg, include_text_content=True, @@ -195,20 +195,20 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) def test_custom_form_multipage_unlabeled_transform(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url) + poller = client.begin_train_model(container_sas_url) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, blob_sas_url, include_text_content=True, @@ -231,20 +231,20 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() def test_form_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, self.form_url_jpg, include_text_content=True, @@ -265,20 +265,20 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) def test_custom_form_multipage_labeled_transform(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - poller = training_client.begin_train_model(container_sas_url, use_labels=True) + poller = client.begin_train_model(container_sas_url, use_labels=True) model = poller.result() responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - poller = client.begin_recognize_custom_forms_from_url( + poller = fr_client.begin_recognize_custom_forms_from_url( model.model_id, blob_sas_url, include_text_content=True, diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url_async.py index a759a731d6de..e30d3f1677d8 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url_async.py @@ -7,14 +7,14 @@ import functools from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import HttpResponseError, ServiceRequestError, ClientAuthenticationError -from azure.ai.formrecognizer.aio import FormRecognizerClient +from azure.ai.formrecognizer.aio import FormRecognizerClient, FormTrainingClient from azure.ai.formrecognizer._generated.models import AnalyzeOperationResult from azure.ai.formrecognizer._response_handlers import prepare_form_result from testcase import GlobalFormRecognizerAccountPreparer from testcase import GlobalTrainingAccountPreparer as _GlobalTrainingAccountPreparer from asynctestcase import AsyncFormRecognizerTest -GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormRecognizerClient) +GlobalTrainingAccountPreparer = functools.partial(_GlobalTrainingAccountPreparer, FormTrainingClient) class TestCustomFormsFromUrlAsync(AsyncFormRecognizerTest): @@ -52,12 +52,12 @@ async def test_pass_stream_into_url(self, resource_group, location, form_recogni @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_bad_url(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) with self.assertRaises(HttpResponseError): - form = await client.recognize_custom_forms_from_url( + form = await fr_client.recognize_custom_forms_from_url( model.model_id, url="https://badurl.jpg" ) @@ -65,11 +65,11 @@ async def test_form_bad_url(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_unlabeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) - form = await client.recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) + form = await fr_client.recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) self.assertEqual(form[0].form_type, "form-0") self.assertFormPagesHasValues(form[0].pages) @@ -84,11 +84,11 @@ async def test_form_unlabeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) async def test_custom_form_multipage_unlabeled(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) - forms = await client.recognize_custom_forms_from_url( + forms = await fr_client.recognize_custom_forms_from_url( model.model_id, blob_sas_url, ) @@ -107,11 +107,11 @@ async def test_custom_form_multipage_unlabeled(self, client, container_sas_url, @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_labeled(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) - form = await client.recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) + form = await fr_client.recognize_custom_forms_from_url(model.model_id, self.form_url_jpg) self.assertEqual(form[0].form_type, "form-"+model.model_id) self.assertFormPagesHasValues(form[0].pages) @@ -125,14 +125,14 @@ async def test_form_labeled(self, client, container_sas_url): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) async def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model( + model = await client.train_model( container_sas_url, use_labels=True ) - forms = await client.recognize_custom_forms_from_url( + forms = await fr_client.recognize_custom_forms_from_url( model.model_id, blob_sas_url ) @@ -150,19 +150,19 @@ async def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_ @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_unlabeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - form = await client.recognize_custom_forms_from_url( + form = await fr_client.recognize_custom_forms_from_url( model.model_id, self.form_url_jpg, include_text_content=True, @@ -183,19 +183,19 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) async def test_multipage_unlabeled_transform(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url) + model = await client.train_model(container_sas_url) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - form = await client.recognize_custom_forms_from_url( + form = await fr_client.recognize_custom_forms_from_url( model.model_id, blob_sas_url, include_text_content=True, @@ -216,19 +216,19 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer() async def test_form_labeled_transform(self, client, container_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - form = await client.recognize_custom_forms_from_url( + form = await fr_client.recognize_custom_forms_from_url( model.model_id, self.form_url_jpg, include_text_content=True, @@ -249,19 +249,19 @@ def callback(raw_response, _, headers): @GlobalFormRecognizerAccountPreparer() @GlobalTrainingAccountPreparer(multipage=True, blob_sas_url=True) async def test_multipage_labeled_transform(self, client, container_sas_url, blob_sas_url): - training_client = client.get_form_training_client() + fr_client = client.get_form_recognizer_client() - model = await training_client.train_model(container_sas_url, use_labels=True) + model = await client.train_model(container_sas_url, use_labels=True) responses = [] def callback(raw_response, _, headers): - analyze_result = client._client._deserialize(AnalyzeOperationResult, raw_response) + analyze_result = fr_client._client._deserialize(AnalyzeOperationResult, raw_response) form = prepare_form_result(analyze_result, model.model_id) responses.append(analyze_result) responses.append(form) - form = await client.recognize_custom_forms_from_url( + form = await fr_client.recognize_custom_forms_from_url( model.model_id, blob_sas_url, include_text_content=True, diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt.py index 7abb5ef60d82..a56d82c50971 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt.py @@ -124,17 +124,15 @@ def test_mgmt_model_unlabeled(self, client, container_sas_url): client.get_custom_model(unlabeled_model_from_train.model_id) @GlobalFormRecognizerAccountPreparer() - def test_get_form_training_client(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): + def test_get_form_recognizer_client(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): transport = RequestsTransport() - frc = FormRecognizerClient(endpoint=form_recognizer_account, credential=AzureKeyCredential(form_recognizer_account_key), transport=transport) + ftc = FormTrainingClient(endpoint=form_recognizer_account, credential=AzureKeyCredential(form_recognizer_account_key), transport=transport) - with frc: - poller = frc.begin_recognize_receipts_from_url(self.receipt_url_jpg) - result = poller.result() + with ftc: + ftc.get_account_properties() assert transport.session is not None - with frc.get_form_training_client() as ftc: + with ftc.get_form_recognizer_client() as frc: assert transport.session is not None - properties = ftc.get_account_properties() - poller = frc.begin_recognize_receipts_from_url(self.receipt_url_jpg) - result = poller.result() + frc.begin_recognize_receipts_from_url(self.receipt_url_jpg).wait() + ftc.get_account_properties() assert transport.session is not None diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt_async.py index edfd133ff0b5..fcfb5e0720fd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt_async.py @@ -122,15 +122,15 @@ async def test_mgmt_model_unlabeled(self, client, container_sas_url): await client.get_custom_model(unlabeled_model_from_train.model_id) @GlobalFormRecognizerAccountPreparer() - async def test_get_form_training_client(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): + async def test_get_form_recognizer_client(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): transport = AioHttpTransport() - frc = FormRecognizerClient(endpoint=form_recognizer_account, credential=AzureKeyCredential(form_recognizer_account_key), transport=transport) + ftc = FormTrainingClient(endpoint=form_recognizer_account, credential=AzureKeyCredential(form_recognizer_account_key), transport=transport) - async with frc: - result = await frc.recognize_receipts_from_url(self.receipt_url_jpg) + async with ftc: + await ftc.get_account_properties() assert transport.session is not None - async with frc.get_form_training_client() as ftc: + async with ftc.get_form_recognizer_client() as frc: assert transport.session is not None - properties = await ftc.get_account_properties() - result = await frc.recognize_receipts_from_url(self.receipt_url_jpg) + await frc.recognize_receipts_from_url(self.receipt_url_jpg) + await ftc.get_account_properties() assert transport.session is not None From 89b28b92a93cd811e9106cc6486f4ea69743a38d Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 13 May 2020 15:56:31 -0400 Subject: [PATCH 2/3] updated changelog --- sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index 592d75f28dba..b0cbb94555ab 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -7,6 +7,8 @@ - `training_files` parameter of `begin_train_model` is renamed to `training_files_url` - `use_labels` parameter of `begin_train_model` is renamed to `use_training_labels` - `list_model_infos` method has been renamed to `list_custom_models` +- Removed `get_form_training_client` from `FormRecognizerClient` +- Added `get_form_recognizer_client` to `FormTrainingClient` **New features** From de6aa00b24c5cdec6e594efdea81a1ba63d51f7e Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 13 May 2020 16:29:07 -0400 Subject: [PATCH 3/3] fixed mypy --- .../azure/ai/formrecognizer/_form_recognizer_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py index d6ed42dd32a6..61dfa284cd07 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py @@ -61,7 +61,7 @@ class FormRecognizerClient(object): """ def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, Any) -> None + # type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None authentication_policy = get_authentication_policy(credential) self._client = FormRecognizer(