Skip to content

Commit b06c979

Browse files
committed
updated tests
1 parent b53e56a commit b06c979

12 files changed

+474
-187
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from ._helpers import get_content_type, error_map, POLLING_INTERVAL, COGNITIVE_KEY_HEADER
2727
from ._user_agent import USER_AGENT
2828
from ._polling import AnalyzePolling
29-
from ._form_training_client import FormTrainingClient
3029
if TYPE_CHECKING:
3130
from azure.core.credentials import AzureKeyCredential
3231

@@ -55,11 +54,9 @@ class FormRecognizerClient(object):
5554

5655
def __init__(self, endpoint, credential, **kwargs):
5756
# type: (str, AzureKeyCredential, Any) -> None
58-
self._endpoint = endpoint
59-
self._credential = credential
6057
self._client = FormRecognizer(
61-
endpoint=self._endpoint,
62-
credential=self._credential,
58+
endpoint=endpoint,
59+
credential=credential,
6360
sdk_moniker=USER_AGENT,
6461
authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER),
6562
**kwargs
@@ -334,19 +331,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume
334331
**kwargs
335332
)
336333

337-
def get_form_training_client(self, **kwargs):
338-
# type: (Any) -> FormTrainingClient
339-
"""Get an instance of a FormTrainingClient from FormRecognizerClient.
340-
341-
:rtype: ~azure.ai.formrecognizer.FormTrainingClient
342-
:return: A FormTrainingClient
343-
"""
344-
return FormTrainingClient(
345-
endpoint=self._endpoint,
346-
credential=self._credential,
347-
**kwargs
348-
)
349-
350334
def close(self):
351335
# type: () -> None
352336
"""Close the :class:`~azure.ai.formrecognizer.FormRecognizerClient` session.

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from ._polling import TrainingPolling
2929
from ._user_agent import USER_AGENT
30+
from ._form_recognizer_client import FormRecognizerClient
3031
if TYPE_CHECKING:
3132
from azure.core.credentials import AzureKeyCredential
3233
from azure.core.pipeline.transport import HttpResponse
@@ -57,9 +58,11 @@ class FormTrainingClient(object):
5758

5859
def __init__(self, endpoint, credential, **kwargs):
5960
# type: (str, AzureKeyCredential, Any) -> None
61+
self._endpoint = endpoint
62+
self._credential = credential
6063
self._client = FormRecognizer(
61-
endpoint=endpoint,
62-
credential=credential,
64+
endpoint=self._endpoint,
65+
credential=self._credential,
6366
sdk_moniker=USER_AGENT,
6467
authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER),
6568
**kwargs
@@ -224,6 +227,19 @@ def get_custom_model(self, model_id, **kwargs):
224227
response = self._client.get_custom_model(model_id=model_id, include_keys=True, error_map=error_map, **kwargs)
225228
return CustomFormModel._from_generated(response)
226229

230+
def get_form_recognizer_client(self, **kwargs):
231+
# type: (Any) -> FormRecognizerClient
232+
"""Get an instance of a FormRecognizerClient from FormTrainingClient.
233+
234+
:rtype: ~azure.ai.formrecognizer.FormRecognizerClient
235+
:return: A FormRecognizerClient
236+
"""
237+
return FormRecognizerClient(
238+
endpoint=self._endpoint,
239+
credential=self._credential,
240+
**kwargs
241+
)
242+
227243
def close(self):
228244
# type: () -> None
229245
"""Close the :class:`~azure.ai.formrecognizer.FormTrainingClient` session.

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from azure.core.tracing.decorator_async import distributed_trace_async
1717
from azure.core.polling.async_base_polling import AsyncLROBasePolling
1818
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
19-
from ._form_training_client_async import FormTrainingClient
2019
from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer
2120
from .._response_handlers import (
2221
prepare_us_receipt,
@@ -64,11 +63,9 @@ def __init__(
6463
credential: "AzureKeyCredential",
6564
**kwargs: Any
6665
) -> None:
67-
self._endpoint = endpoint
68-
self._credential = credential
6966
self._client = FormRecognizer(
70-
endpoint=self._endpoint,
71-
credential=self._credential,
67+
endpoint=endpoint,
68+
credential=credential,
7269
sdk_moniker=USER_AGENT,
7370
authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER),
7471
**kwargs
@@ -349,18 +346,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume
349346
**kwargs
350347
)
351348

352-
def get_form_training_client(self, **kwargs: Any) -> FormTrainingClient:
353-
"""Get an instance of a FormTrainingClient from FormRecognizerClient.
354-
355-
:rtype: ~azure.ai.formrecognizer.aio.FormTrainingClient
356-
:return: A FormTrainingClient
357-
"""
358-
return FormTrainingClient(
359-
endpoint=self._endpoint,
360-
credential=self._credential,
361-
**kwargs
362-
)
363-
364349
async def __aenter__(self) -> "FormRecognizerClient":
365350
await self._client.__aenter__()
366351
return self

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from azure.core.tracing.decorator import distributed_trace
1818
from azure.core.tracing.decorator_async import distributed_trace_async
1919
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
20+
from ._form_recognizer_client_async import FormRecognizerClient
2021
from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer
2122
from .._generated.models import TrainRequest, TrainSourceFilter
2223
from .._generated.models import Model
@@ -60,9 +61,11 @@ def __init__(
6061
credential: "AzureKeyCredential",
6162
**kwargs: Any
6263
) -> None:
64+
self._endpoint = endpoint
65+
self._credential = credential
6366
self._client = FormRecognizer(
64-
endpoint=endpoint,
65-
credential=credential,
67+
endpoint=self._endpoint,
68+
credential=self._credential,
6669
sdk_moniker=USER_AGENT,
6770
authentication_policy=AzureKeyCredentialPolicy(credential, COGNITIVE_KEY_HEADER),
6871
**kwargs
@@ -230,6 +233,18 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode
230233
)
231234
return CustomFormModel._from_generated(response)
232235

236+
def get_form_recognizer_client(self, **kwargs: Any) -> FormRecognizerClient:
237+
"""Get an instance of a FormRecognizerClient from FormTrainingClient.
238+
239+
:rtype: ~azure.ai.formrecognizer.aio.FormRecognizerClient
240+
:return: A FormRecognizerClient
241+
"""
242+
return FormRecognizerClient(
243+
endpoint=self._endpoint,
244+
credential=self._credential,
245+
**kwargs
246+
)
247+
233248
async def __aenter__(self) -> "FormTrainingClient":
234249
await self._client.__aenter__()
235250
return self
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
13+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
14+
method: GET
15+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary
16+
response:
17+
body:
18+
string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:33Z"}}'
19+
headers:
20+
apim-request-id:
21+
- 49d7757e-2cea-4126-8660-1b64832e48d7
22+
content-type:
23+
- application/json; charset=utf-8
24+
date:
25+
- Wed, 13 May 2020 16:13:32 GMT
26+
strict-transport-security:
27+
- max-age=31536000; includeSubDomains; preload
28+
transfer-encoding:
29+
- chunked
30+
x-content-type-options:
31+
- nosniff
32+
x-envoy-upstream-service-time:
33+
- '5109'
34+
status:
35+
code: 200
36+
message: OK
37+
- request:
38+
body: '{"source": "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-allinone.jpg"}'
39+
headers:
40+
Accept:
41+
- '*/*'
42+
Accept-Encoding:
43+
- gzip, deflate
44+
Connection:
45+
- keep-alive
46+
Content-Length:
47+
- '172'
48+
Content-Type:
49+
- application/json
50+
User-Agent:
51+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
52+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
53+
method: POST
54+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyze?includeTextDetails=false
55+
response:
56+
body:
57+
string: ''
58+
headers:
59+
apim-request-id:
60+
- 7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
61+
content-length:
62+
- '0'
63+
date:
64+
- Wed, 13 May 2020 16:13:34 GMT
65+
operation-location:
66+
- https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
67+
strict-transport-security:
68+
- max-age=31536000; includeSubDomains; preload
69+
x-content-type-options:
70+
- nosniff
71+
x-envoy-upstream-service-time:
72+
- '1478'
73+
status:
74+
code: 202
75+
message: Accepted
76+
- request:
77+
body: null
78+
headers:
79+
Accept:
80+
- '*/*'
81+
Accept-Encoding:
82+
- gzip, deflate
83+
Connection:
84+
- keep-alive
85+
User-Agent:
86+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
87+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
88+
method: GET
89+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
90+
response:
91+
body:
92+
string: '{"status":"running","createdDateTime":"2020-05-13T16:13:34Z","lastUpdatedDateTime":"2020-05-13T16:13:35Z"}'
93+
headers:
94+
apim-request-id:
95+
- 2f458f0e-eccf-4da2-ab90-05c85f13f58b
96+
content-type:
97+
- application/json; charset=utf-8
98+
date:
99+
- Wed, 13 May 2020 16:13:40 GMT
100+
strict-transport-security:
101+
- max-age=31536000; includeSubDomains; preload
102+
transfer-encoding:
103+
- chunked
104+
x-content-type-options:
105+
- nosniff
106+
x-envoy-upstream-service-time:
107+
- '138'
108+
status:
109+
code: 200
110+
message: OK
111+
- request:
112+
body: null
113+
headers:
114+
Accept:
115+
- '*/*'
116+
Accept-Encoding:
117+
- gzip, deflate
118+
Connection:
119+
- keep-alive
120+
User-Agent:
121+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
122+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
123+
method: GET
124+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
125+
response:
126+
body:
127+
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
128+
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
129+
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
130+
& 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}}}]}}'
131+
headers:
132+
apim-request-id:
133+
- 195addaa-7fcc-4053-bceb-5087740c57ed
134+
content-type:
135+
- application/json; charset=utf-8
136+
date:
137+
- Wed, 13 May 2020 16:13:45 GMT
138+
strict-transport-security:
139+
- max-age=31536000; includeSubDomains; preload
140+
transfer-encoding:
141+
- chunked
142+
x-content-type-options:
143+
- nosniff
144+
x-envoy-upstream-service-time:
145+
- '378'
146+
status:
147+
code: 200
148+
message: OK
149+
- request:
150+
body: null
151+
headers:
152+
Accept:
153+
- application/json
154+
Accept-Encoding:
155+
- gzip, deflate
156+
Connection:
157+
- keep-alive
158+
User-Agent:
159+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
160+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
161+
method: GET
162+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary
163+
response:
164+
body:
165+
string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:47Z"}}'
166+
headers:
167+
apim-request-id:
168+
- fa489acc-6458-4098-8379-b1f9389b3e1e
169+
content-type:
170+
- application/json; charset=utf-8
171+
date:
172+
- Wed, 13 May 2020 16:13:46 GMT
173+
strict-transport-security:
174+
- max-age=31536000; includeSubDomains; preload
175+
transfer-encoding:
176+
- chunked
177+
x-content-type-options:
178+
- nosniff
179+
x-envoy-upstream-service-time:
180+
- '168'
181+
status:
182+
code: 200
183+
message: OK
184+
version: 1

0 commit comments

Comments
 (0)