Skip to content

Commit ff26bc6

Browse files
committed
feedback + add test for copy authorization
1 parent 4736418 commit ff26bc6

File tree

7 files changed

+100
-5
lines changed

7 files changed

+100
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ def get_custom_model(self, model_id, **kwargs):
251251
@distributed_trace
252252
def get_copy_authorization(self, resource_id, resource_region, **kwargs):
253253
# type: (str, str, Any) -> Dict[str, Union[str, int]]
254-
"""Generate authorization for copying a model into the target Form Recognizer resource.
254+
"""Generate authorization for copying a custom model into the target Form Recognizer resource.
255255
This should be called by the target resource (where the model will be copied to)
256256
and the output can be passed as the `target` parameter into :func:`~begin_copy_model()`.
257257
258258
:param str resource_id: Azure Resource Id of the target Form Recognizer resource
259259
where the model will be copied to.
260-
:param str resource_region: Location of the target Azure resource. A valid Azure
260+
:param str resource_region: Location of the target Form Recognizer resource. A valid Azure
261261
region name supported by Cognitive Services.
262262
:return: A dictionary with values for the copy authorization -
263263
"modelId", "accessToken", "resourceId", "resourceRegion", and "expirationDateTimeTicks".

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ async def get_copy_authorization(
263263
resource_region: str,
264264
**kwargs: Any
265265
) -> Dict[str, Union[str, int]]:
266-
"""Generate authorization for copying a model into the target Form Recognizer resource.
266+
"""Generate authorization for copying a custom model into the target Form Recognizer resource.
267267
This should be called by the target resource (where the model will be copied to)
268268
and the output can be passed as the `target` parameter into :func:`~copy_model()`.
269269
270270
:param str resource_id: Azure Resource Id of the target Form Recognizer resource
271271
where the model will be copied to.
272-
:param str resource_region: Location of the target Azure resource. A valid Azure
272+
:param str resource_region: Location of the target Form Recognizer resource. A valid Azure
273273
region name supported by Cognitive Services.
274274
:return: A dictionary with values for the copy authorization -
275275
"modelId", "accessToken", "resourceId", "resourceRegion", and "expirationDateTimeTicks".

sdk/formrecognizer/azure-ai-formrecognizer/samples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ All of these samples need the endpoint to your Form Recognizer resource ([instru
2727
|[sample_train_model_without_labels.py][sample_train_model_without_labels] and [sample_train_model_without_labels_async.py][sample_train_model_without_labels_async]|Train a custom model with unlabeled data|
2828
|[sample_train_model_with_labels.py][sample_train_model_with_labels] and [sample_train_model_with_labels_async.py][sample_train_model_with_labels_async]|Train a custom model with labeled data|
2929
|[sample_manage_custom_models.py][sample_manage_custom_models] and [sample_manage_custom_models_async.py][sample_manage_custom_models_async]|Manage the custom models in your account|
30-
|[sample_copy_model.py][sample_copy_model] and [sample_copy_model_async.py][sample_copy_model_async]|Copy a model from one Form Recognizer resource to another|
30+
|[sample_copy_model.py][sample_copy_model] and [sample_copy_model_async.py][sample_copy_model_async]|Copy a custom model from one Form Recognizer resource to another|
3131

3232

3333
## Prerequisites
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
Content-Length:
12+
- '0'
13+
User-Agent:
14+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
15+
Python/3.7.3 (Windows-10-10.0.18362-SP0)
16+
method: POST
17+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models/copyAuthorization
18+
response:
19+
body:
20+
string: '{"modelId": "3a1af284-1187-402d-9869-39ad09181bf5", "accessToken":
21+
"redacted", "expirationDateTimeTicks": 637255865516657423}'
22+
headers:
23+
apim-request-id:
24+
- be03b750-1177-47fa-9473-028489a9ce67
25+
content-type:
26+
- application/json; charset=utf-8
27+
date:
28+
- Tue, 19 May 2020 15:49:11 GMT
29+
location:
30+
- https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models/3a1af284-1187-402d-9869-39ad09181bf5
31+
strict-transport-security:
32+
- max-age=31536000; includeSubDomains; preload
33+
transfer-encoding:
34+
- chunked
35+
x-content-type-options:
36+
- nosniff
37+
x-envoy-upstream-service-time:
38+
- '231'
39+
status:
40+
code: 201
41+
message: Created
42+
version: 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
User-Agent:
8+
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
9+
Python/3.7.3 (Windows-10-10.0.18362-SP0)
10+
method: POST
11+
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models/copyAuthorization
12+
response:
13+
body:
14+
string: '{"modelId": "adcd2786-9aa5-4098-9a55-7d68eaeaaf2f", "accessToken":
15+
"redacted", "expirationDateTimeTicks": 637255866617034918}'
16+
headers:
17+
apim-request-id: 99a50a5e-a423-47ae-8e9e-9369a4ac8d90
18+
content-type: application/json; charset=utf-8
19+
date: Tue, 19 May 2020 15:51:01 GMT
20+
location: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models/adcd2786-9aa5-4098-9a55-7d68eaeaaf2f
21+
strict-transport-security: max-age=31536000; includeSubDomains; preload
22+
transfer-encoding: chunked
23+
x-content-type-options: nosniff
24+
x-envoy-upstream-service-time: '226'
25+
status:
26+
code: 201
27+
message: Created
28+
url: https://westus.api.cognitive.microsoft.com//formrecognizer/v2.0-preview/custom/models/copyAuthorization
29+
version: 1

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_copy_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ def callback(response, _, headers):
7878
self.assertEqual(copy.status, actual.status)
7979
self.assertEqual(copy.last_modified, actual.last_updated_date_time)
8080
self.assertEqual(copy.model_id, target["modelId"])
81+
82+
@GlobalFormRecognizerAccountPreparer()
83+
@GlobalTrainingAccountPreparer(copy=True)
84+
def test_copy_authorization(self, client, container_sas_url, location, resource_id):
85+
86+
target = client.get_copy_authorization(resource_region="eastus", resource_id=resource_id)
87+
88+
self.assertIsNotNone(target["modelId"])
89+
self.assertIsNotNone(target["accessToken"])
90+
self.assertIsNotNone(target["expirationDateTimeTicks"])
91+
self.assertEqual(target["resourceRegion"], "eastus")
92+
self.assertEqual(target["resourceId"], resource_id)

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_copy_model_async.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ def callback(response, _, headers):
7373
self.assertEqual(copy.status, actual.status)
7474
self.assertEqual(copy.last_modified, actual.last_updated_date_time)
7575
self.assertEqual(copy.model_id, target["modelId"])
76+
77+
@GlobalFormRecognizerAccountPreparer()
78+
@GlobalTrainingAccountPreparer(copy=True)
79+
async def test_copy_authorization(self, client, container_sas_url, location, resource_id):
80+
81+
target = await client.get_copy_authorization(resource_region="eastus", resource_id=resource_id)
82+
83+
self.assertIsNotNone(target["modelId"])
84+
self.assertIsNotNone(target["accessToken"])
85+
self.assertIsNotNone(target["expirationDateTimeTicks"])
86+
self.assertEqual(target["resourceRegion"], "eastus")
87+
self.assertEqual(target["resourceId"], resource_id)

0 commit comments

Comments
 (0)