8
8
import functools
9
9
from devtools_testutils .aio import recorded_by_proxy_async
10
10
from devtools_testutils import set_bodiless_matcher
11
- from azure .core .credentials import AzureKeyCredential
12
11
from azure .ai .formrecognizer ._generated .v2023_07_31 .models import AnalyzeResultOperation
13
12
from azure .ai .formrecognizer .aio import DocumentAnalysisClient , DocumentModelAdministrationClient
14
13
from azure .ai .formrecognizer import AnalyzeResult
15
- from preparers import FormRecognizerPreparer
14
+ from preparers import FormRecognizerPreparer , get_async_client
16
15
from asynctestcase import AsyncFormRecognizerTest
17
- from preparers import GlobalClientPreparer as _GlobalClientPreparer
18
16
from conftest import skip_flaky_test
19
17
20
-
21
- DocumentModelAdministrationClientPreparer = functools .partial (_GlobalClientPreparer , DocumentModelAdministrationClient )
18
+ get_dma_client = functools . partial ( get_async_client , DocumentModelAdministrationClient )
19
+ get_da_client = functools .partial (get_async_client , DocumentAnalysisClient )
22
20
23
21
class TestDACAnalyzeCustomModelAsync (AsyncFormRecognizerTest ):
24
22
25
23
@FormRecognizerPreparer ()
26
24
async def test_analyze_document_none_model_id (self , ** kwargs ):
27
- formrecognizer_test_endpoint = kwargs .pop ("formrecognizer_test_endpoint" )
28
- formrecognizer_test_api_key = kwargs .pop ("formrecognizer_test_api_key" )
29
- client = DocumentAnalysisClient (formrecognizer_test_endpoint , AzureKeyCredential (formrecognizer_test_api_key ))
25
+ client = get_da_client ()
30
26
with pytest .raises (ValueError ) as e :
31
27
async with client :
32
28
await client .begin_analyze_document (model_id = None , document = b"xx" )
33
29
assert "model_id cannot be None or empty." in str (e .value )
34
30
35
31
@FormRecognizerPreparer ()
36
32
async def test_analyze_document_empty_model_id (self , ** kwargs ):
37
- formrecognizer_test_endpoint = kwargs .pop ("formrecognizer_test_endpoint" )
38
- formrecognizer_test_api_key = kwargs .pop ("formrecognizer_test_api_key" )
39
- client = DocumentAnalysisClient (formrecognizer_test_endpoint , AzureKeyCredential (formrecognizer_test_api_key ))
33
+ client = get_da_client ()
40
34
with pytest .raises (ValueError ) as e :
41
35
async with client :
42
36
await client .begin_analyze_document (model_id = "" , document = b"xx" )
43
37
assert "model_id cannot be None or empty." in str (e .value )
44
38
45
39
@skip_flaky_test
46
40
@FormRecognizerPreparer ()
47
- @DocumentModelAdministrationClientPreparer ()
48
41
@recorded_by_proxy_async
49
- async def test_custom_document_transform (self , client , formrecognizer_storage_container_sas_url , ** kwargs ):
42
+ async def test_custom_document_transform (self , formrecognizer_storage_container_sas_url , ** kwargs ):
43
+ client = get_dma_client ()
50
44
set_bodiless_matcher ()
51
45
da_client = client .get_document_analysis_client ()
52
46
@@ -92,9 +86,9 @@ def callback(raw_response, _, headers):
92
86
93
87
@skip_flaky_test
94
88
@FormRecognizerPreparer ()
95
- @DocumentModelAdministrationClientPreparer ()
96
89
@recorded_by_proxy_async
97
- async def test_custom_document_multipage_transform (self , client , formrecognizer_multipage_storage_container_sas_url , ** kwargs ):
90
+ async def test_custom_document_multipage_transform (self , formrecognizer_multipage_storage_container_sas_url , ** kwargs ):
91
+ client = get_dma_client ()
98
92
set_bodiless_matcher ()
99
93
da_client = client .get_document_analysis_client ()
100
94
@@ -140,9 +134,9 @@ def callback(raw_response, _, headers):
140
134
141
135
@skip_flaky_test
142
136
@FormRecognizerPreparer ()
143
- @DocumentModelAdministrationClientPreparer ()
144
137
@recorded_by_proxy_async
145
- async def test_custom_document_selection_mark (self , client , formrecognizer_selection_mark_storage_container_sas_url , ** kwargs ):
138
+ async def test_custom_document_selection_mark (self , formrecognizer_selection_mark_storage_container_sas_url , ** kwargs ):
139
+ client = get_dma_client ()
146
140
set_bodiless_matcher ()
147
141
da_client = client .get_document_analysis_client ()
148
142
with open (self .selection_form_pdf , "rb" ) as fd :
@@ -186,9 +180,9 @@ def callback(raw_response, _, headers):
186
180
187
181
@skip_flaky_test
188
182
@FormRecognizerPreparer ()
189
- @DocumentModelAdministrationClientPreparer ()
190
183
@recorded_by_proxy_async
191
- async def test_pages_kwarg_specified (self , client , formrecognizer_storage_container_sas_url , ** kwargs ):
184
+ async def test_pages_kwarg_specified (self , formrecognizer_storage_container_sas_url , ** kwargs ):
185
+ client = get_dma_client ()
192
186
set_bodiless_matcher ()
193
187
da_client = client .get_document_analysis_client ()
194
188
@@ -207,9 +201,9 @@ async def test_pages_kwarg_specified(self, client, formrecognizer_storage_contai
207
201
208
202
@skip_flaky_test
209
203
@FormRecognizerPreparer ()
210
- @DocumentModelAdministrationClientPreparer ()
211
204
@recorded_by_proxy_async
212
- async def test_custom_document_signature_field (self , client , formrecognizer_storage_container_sas_url , ** kwargs ):
205
+ async def test_custom_document_signature_field (self , formrecognizer_storage_container_sas_url , ** kwargs ):
206
+ client = get_dma_client ()
213
207
set_bodiless_matcher ()
214
208
da_client = client .get_document_analysis_client ()
215
209
@@ -234,9 +228,9 @@ async def test_custom_document_signature_field(self, client, formrecognizer_stor
234
228
235
229
@skip_flaky_test
236
230
@FormRecognizerPreparer ()
237
- @DocumentModelAdministrationClientPreparer ()
238
231
@recorded_by_proxy_async
239
- async def test_custom_document_blank_pdf (self , client , formrecognizer_storage_container_sas_url , ** kwargs ):
232
+ async def test_custom_document_blank_pdf (self , formrecognizer_storage_container_sas_url , ** kwargs ):
233
+ client = get_dma_client ()
240
234
set_bodiless_matcher ()
241
235
da_client = client .get_document_analysis_client ()
242
236
0 commit comments