Skip to content

Commit ff97aa8

Browse files
authored
[Test Proxy] Add custom matcher setter and ignore unnecessary headers (Azure#23148)
1 parent c472b93 commit ff97aa8

File tree

57 files changed

+1458
-427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1458
-427
lines changed

sdk/eventgrid/azure-eventgrid/tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import sys
2828
import pytest
2929
from devtools_testutils import test_proxy
30-
from devtools_testutils.sanitizers import add_remove_header_sanitizer, add_general_regex_sanitizer, set_bodiless_matcher
30+
from devtools_testutils.sanitizers import add_remove_header_sanitizer, add_general_regex_sanitizer, set_custom_default_matcher
3131

3232
# Ignore async tests for Python < 3.5
3333
collect_ignore_glob = []
@@ -37,7 +37,10 @@
3737

3838
@pytest.fixture(scope="session", autouse=True)
3939
def add_aeg_sanitizer(test_proxy):
40-
set_bodiless_matcher()
40+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
41+
set_custom_default_matcher(
42+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
43+
)
4144
add_remove_header_sanitizer(headers="aeg-sas-key, aeg-sas-token")
4245
add_general_regex_sanitizer(
4346
value="fakeresource",

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88
import functools
9-
from devtools_testutils import recorded_by_proxy, set_bodiless_matcher
9+
from devtools_testutils import recorded_by_proxy, set_custom_default_matcher
1010
from azure.core.credentials import AzureKeyCredential
1111
from azure.ai.formrecognizer import DocumentAnalysisClient, DocumentModelAdministrationClient, AnalyzeResult
1212
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
@@ -41,7 +41,10 @@ def test_analyze_document_empty_model_id(self, **kwargs):
4141
@DocumentModelAdministrationClientPreparer()
4242
@recorded_by_proxy
4343
def test_custom_document_transform(self, client, formrecognizer_storage_container_sas_url, **kwargs):
44-
set_bodiless_matcher()
44+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
45+
set_custom_default_matcher(
46+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
47+
)
4548
da_client = client.get_document_analysis_client()
4649

4750
poller = client.begin_build_model(formrecognizer_storage_container_sas_url, "template")
@@ -87,7 +90,10 @@ def callback(raw_response, _, headers):
8790
@DocumentModelAdministrationClientPreparer()
8891
@recorded_by_proxy
8992
def test_custom_document_multipage_transform(self, client, formrecognizer_multipage_storage_container_sas_url, **kwargs):
90-
set_bodiless_matcher()
93+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
94+
set_custom_default_matcher(
95+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
96+
)
9197
da_client = client.get_document_analysis_client()
9298

9399
poller = client.begin_build_model(formrecognizer_multipage_storage_container_sas_url, "template")
@@ -133,7 +139,10 @@ def callback(raw_response, _, headers):
133139
@DocumentModelAdministrationClientPreparer()
134140
@recorded_by_proxy
135141
def test_custom_document_selection_mark(self, client, formrecognizer_selection_mark_storage_container_sas_url, **kwargs):
136-
set_bodiless_matcher()
142+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
143+
set_custom_default_matcher(
144+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
145+
)
137146
da_client = client.get_document_analysis_client()
138147

139148
poller = client.begin_build_model(formrecognizer_selection_mark_storage_container_sas_url, "template")
@@ -179,7 +188,10 @@ def callback(raw_response, _, headers):
179188
@DocumentModelAdministrationClientPreparer()
180189
@recorded_by_proxy
181190
def test_pages_kwarg_specified(self, client, formrecognizer_storage_container_sas_url, **kwargs):
182-
set_bodiless_matcher()
191+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
192+
set_custom_default_matcher(
193+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
194+
)
183195
da_client = client.get_document_analysis_client()
184196

185197
with open(self.form_jpg, "rb") as fd:
@@ -197,7 +209,10 @@ def test_pages_kwarg_specified(self, client, formrecognizer_storage_container_sa
197209
@DocumentModelAdministrationClientPreparer()
198210
@recorded_by_proxy
199211
def test_custom_document_signature_field(self, client, formrecognizer_storage_container_sas_url, **kwargs):
200-
set_bodiless_matcher()
212+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
213+
set_custom_default_matcher(
214+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
215+
)
201216
da_client = client.get_document_analysis_client()
202217

203218
with open(self.form_jpg, "rb") as fd:

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
import functools
99
from devtools_testutils.aio import recorded_by_proxy_async
10-
from devtools_testutils import set_bodiless_matcher
10+
from devtools_testutils import set_custom_default_matcher
1111
from azure.core.credentials import AzureKeyCredential
1212
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
1313
from azure.ai.formrecognizer.aio import DocumentAnalysisClient, DocumentModelAdministrationClient
@@ -47,7 +47,10 @@ async def test_analyze_document_empty_model_id(self, **kwargs):
4747
@DocumentModelAdministrationClientPreparer()
4848
@recorded_by_proxy_async
4949
async def test_custom_document_transform(self, client, formrecognizer_storage_container_sas_url, **kwargs):
50-
set_bodiless_matcher()
50+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
51+
set_custom_default_matcher(
52+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
53+
)
5154
da_client = client.get_document_analysis_client()
5255

5356
responses = []
@@ -95,7 +98,10 @@ def callback(raw_response, _, headers):
9598
@DocumentModelAdministrationClientPreparer()
9699
@recorded_by_proxy_async
97100
async def test_custom_document_multipage_transform(self, client, formrecognizer_multipage_storage_container_sas_url, **kwargs):
98-
set_bodiless_matcher()
101+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
102+
set_custom_default_matcher(
103+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
104+
)
99105
da_client = client.get_document_analysis_client()
100106

101107
responses = []
@@ -143,7 +149,10 @@ def callback(raw_response, _, headers):
143149
@DocumentModelAdministrationClientPreparer()
144150
@recorded_by_proxy_async
145151
async def test_custom_document_selection_mark(self, client, formrecognizer_selection_mark_storage_container_sas_url, **kwargs):
146-
set_bodiless_matcher()
152+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
153+
set_custom_default_matcher(
154+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
155+
)
147156
da_client = client.get_document_analysis_client()
148157
with open(self.selection_form_pdf, "rb") as fd:
149158
my_file = fd.read()
@@ -189,7 +198,10 @@ def callback(raw_response, _, headers):
189198
@DocumentModelAdministrationClientPreparer()
190199
@recorded_by_proxy_async
191200
async def test_pages_kwarg_specified(self, client, formrecognizer_storage_container_sas_url, **kwargs):
192-
set_bodiless_matcher()
201+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
202+
set_custom_default_matcher(
203+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
204+
)
193205
da_client = client.get_document_analysis_client()
194206

195207
with open(self.form_jpg, "rb") as fd:
@@ -209,7 +221,10 @@ async def test_pages_kwarg_specified(self, client, formrecognizer_storage_contai
209221
@DocumentModelAdministrationClientPreparer()
210222
@recorded_by_proxy_async
211223
async def test_custom_document_signature_field(self, client, formrecognizer_storage_container_sas_url, **kwargs):
212-
set_bodiless_matcher()
224+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
225+
set_custom_default_matcher(
226+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
227+
)
213228
da_client = client.get_document_analysis_client()
214229

215230
with open(self.form_jpg, "rb") as fd:

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88
import functools
9-
from devtools_testutils import recorded_by_proxy, set_bodiless_matcher
9+
from devtools_testutils import recorded_by_proxy, set_custom_default_matcher
1010
from azure.core.credentials import AzureKeyCredential
1111
from azure.ai.formrecognizer import DocumentAnalysisClient, DocumentModelAdministrationClient, AnalyzeResult
1212
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
@@ -41,7 +41,10 @@ def test_document_analysis_empty_model_id(self, **kwargs):
4141
@DocumentModelAdministrationClientPreparer()
4242
@recorded_by_proxy
4343
def test_custom_document_selection_mark(self, client, formrecognizer_selection_mark_storage_container_sas_url, **kwargs):
44-
set_bodiless_matcher()
44+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
45+
set_custom_default_matcher(
46+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
47+
)
4548
da_client = client.get_document_analysis_client()
4649

4750
poller = client.begin_build_model(formrecognizer_selection_mark_storage_container_sas_url, "template")
@@ -84,7 +87,10 @@ def callback(raw_response, _, headers):
8487
@DocumentModelAdministrationClientPreparer()
8588
@recorded_by_proxy
8689
def test_label_tables_variable_rows(self, client, formrecognizer_table_variable_rows_container_sas_url, **kwargs):
87-
set_bodiless_matcher()
90+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
91+
set_custom_default_matcher(
92+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
93+
)
8894
da_client = client.get_document_analysis_client()
8995

9096
build_poller = client.begin_build_model(formrecognizer_table_variable_rows_container_sas_url, "template")
@@ -126,7 +132,10 @@ def callback(raw_response, _, headers):
126132
@DocumentModelAdministrationClientPreparer()
127133
@recorded_by_proxy
128134
def test_label_tables_fixed_rows(self, client, formrecognizer_table_fixed_rows_container_sas_url, **kwargs):
129-
set_bodiless_matcher()
135+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
136+
set_custom_default_matcher(
137+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
138+
)
130139
da_client = client.get_document_analysis_client()
131140

132141
build_poller = client.begin_build_model(formrecognizer_table_fixed_rows_container_sas_url, "template")

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
import functools
99
from devtools_testutils.aio import recorded_by_proxy_async
10-
from devtools_testutils import set_bodiless_matcher
10+
from devtools_testutils import set_custom_default_matcher
1111
from azure.core.credentials import AzureKeyCredential
1212
from azure.ai.formrecognizer.aio import DocumentAnalysisClient, DocumentModelAdministrationClient
1313
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
@@ -45,7 +45,10 @@ async def test_document_analysis_empty_model_id(self, **kwargs):
4545
@DocumentModelAdministrationClientPreparer()
4646
@recorded_by_proxy_async
4747
async def test_custom_document_selection_mark(self, client, formrecognizer_selection_mark_storage_container_sas_url, **kwargs):
48-
set_bodiless_matcher()
48+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
49+
set_custom_default_matcher(
50+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
51+
)
4952
da_client = client.get_document_analysis_client()
5053

5154
responses = []
@@ -90,7 +93,10 @@ def callback(raw_response, _, headers):
9093
@DocumentModelAdministrationClientPreparer()
9194
@recorded_by_proxy_async
9295
async def test_label_tables_variable_rows(self, client, formrecognizer_table_variable_rows_container_sas_url, **kwargs):
93-
set_bodiless_matcher()
96+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
97+
set_custom_default_matcher(
98+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
99+
)
94100
da_client = client.get_document_analysis_client()
95101

96102
responses = []
@@ -135,7 +141,10 @@ def callback(raw_response, _, headers):
135141
@DocumentModelAdministrationClientPreparer()
136142
@recorded_by_proxy_async
137143
async def test_label_tables_fixed_rows(self, client, formrecognizer_table_fixed_rows_container_sas_url, **kwargs):
138-
set_bodiless_matcher()
144+
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
145+
set_custom_default_matcher(
146+
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
147+
)
139148
da_client = client.get_document_analysis_client()
140149

141150
responses = []

0 commit comments

Comments
 (0)