88import functools
99from devtools_testutils .aio import recorded_by_proxy_async
1010from devtools_testutils import set_bodiless_matcher
11- from azure .core .credentials import AzureKeyCredential
1211from azure .ai .formrecognizer ._generated .v2023_07_31 .models import AnalyzeResultOperation
1312from azure .ai .formrecognizer .aio import DocumentAnalysisClient , DocumentModelAdministrationClient
1413from azure .ai .formrecognizer import AnalyzeResult
15- from preparers import FormRecognizerPreparer
14+ from preparers import FormRecognizerPreparer , get_async_client
1615from asynctestcase import AsyncFormRecognizerTest
17- from preparers import GlobalClientPreparer as _GlobalClientPreparer
1816from conftest import skip_flaky_test
1917
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 )
2220
2321class TestDACAnalyzeCustomModelAsync (AsyncFormRecognizerTest ):
2422
2523 @FormRecognizerPreparer ()
2624 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 ()
3026 with pytest .raises (ValueError ) as e :
3127 async with client :
3228 await client .begin_analyze_document (model_id = None , document = b"xx" )
3329 assert "model_id cannot be None or empty." in str (e .value )
3430
3531 @FormRecognizerPreparer ()
3632 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 ()
4034 with pytest .raises (ValueError ) as e :
4135 async with client :
4236 await client .begin_analyze_document (model_id = "" , document = b"xx" )
4337 assert "model_id cannot be None or empty." in str (e .value )
4438
4539 @skip_flaky_test
4640 @FormRecognizerPreparer ()
47- @DocumentModelAdministrationClientPreparer ()
4841 @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 ()
5044 set_bodiless_matcher ()
5145 da_client = client .get_document_analysis_client ()
5246
@@ -92,9 +86,9 @@ def callback(raw_response, _, headers):
9286
9387 @skip_flaky_test
9488 @FormRecognizerPreparer ()
95- @DocumentModelAdministrationClientPreparer ()
9689 @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 ()
9892 set_bodiless_matcher ()
9993 da_client = client .get_document_analysis_client ()
10094
@@ -140,9 +134,9 @@ def callback(raw_response, _, headers):
140134
141135 @skip_flaky_test
142136 @FormRecognizerPreparer ()
143- @DocumentModelAdministrationClientPreparer ()
144137 @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 ()
146140 set_bodiless_matcher ()
147141 da_client = client .get_document_analysis_client ()
148142 with open (self .selection_form_pdf , "rb" ) as fd :
@@ -186,9 +180,9 @@ def callback(raw_response, _, headers):
186180
187181 @skip_flaky_test
188182 @FormRecognizerPreparer ()
189- @DocumentModelAdministrationClientPreparer ()
190183 @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 ()
192186 set_bodiless_matcher ()
193187 da_client = client .get_document_analysis_client ()
194188
@@ -207,9 +201,9 @@ async def test_pages_kwarg_specified(self, client, formrecognizer_storage_contai
207201
208202 @skip_flaky_test
209203 @FormRecognizerPreparer ()
210- @DocumentModelAdministrationClientPreparer ()
211204 @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 ()
213207 set_bodiless_matcher ()
214208 da_client = client .get_document_analysis_client ()
215209
@@ -234,9 +228,9 @@ async def test_custom_document_signature_field(self, client, formrecognizer_stor
234228
235229 @skip_flaky_test
236230 @FormRecognizerPreparer ()
237- @DocumentModelAdministrationClientPreparer ()
238231 @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 ()
240234 set_bodiless_matcher ()
241235 da_client = client .get_document_analysis_client ()
242236
0 commit comments