Skip to content

Commit

Permalink
[formrecognizer] Fix failing pipeline tests (Azure#23781)
Browse files Browse the repository at this point in the history
* fix failing pipeline tests

* set bodiless matcher

* fix text proxy setting matcher live condition
  • Loading branch information
catalinaperalta authored Apr 1, 2022
1 parent ade4549 commit 462edaa
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 458 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "152",
"Content-Length": "153",
"Content-Type": "application/json",
"User-Agent": "azsdk-python-ai-formrecognizer/3.2.0b3 Python/3.9.1 (Windows-10-10.0.19041-SP0)",
"x-ms-client-request-id": "a1edbe35-7f2b-11ec-849b-c8348e073d30"
"User-Agent": "azsdk-python-ai-formrecognizer/3.2.0b4 Python/3.9.1 (Windows-10-10.0.19041-SP0)"
},
"RequestBody": {
"modelId": "3498b340-3526-4834-b00a-9eaa1ef70f19",
"modelId": "a765bec0-8629-4c1d-8012-e1837cd8494a",
"buildMode": "template",
"azureBlobSource": {
"containerUrl": "https://blob_sas_url",
"prefix": "subfolder"
"prefix": "testfolder"
}
},
"StatusCode": 400,
"ResponseHeaders": {
"apim-request-id": "41721141-ff50-491d-84bf-3fe310ebac0a",
"apim-request-id": "df890e1d-20f8-40f5-977d-4ffc40181f7c",
"Content-Type": "application/json",
"Date": "Thu, 27 Jan 2022 04:43:11 GMT",
"Date": "Thu, 31 Mar 2022 23:41:51 GMT",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "613"
"x-envoy-upstream-service-time": "215"
},
"ResponseBody": {
"error": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "152",
"Content-Length": "153",
"Content-Type": "application/json",
"User-Agent": "azsdk-python-ai-formrecognizer/3.2.0b3 Python/3.9.1 (Windows-10-10.0.19041-SP0)",
"x-ms-client-request-id": "61720381-7f2b-11ec-9e3f-c8348e073d30"
"User-Agent": "azsdk-python-ai-formrecognizer/3.2.0b4 Python/3.9.1 (Windows-10-10.0.19041-SP0)"
},
"RequestBody": {
"modelId": "158c284d-5a3a-485b-b494-d41bfd5e8315",
"modelId": "42720dcc-9c79-491b-afb0-3ee2ac20f454",
"buildMode": "template",
"azureBlobSource": {
"containerUrl": "https://blob_sas_url",
"prefix": "subfolder"
"prefix": "testfolder"
}
},
"StatusCode": 400,
"ResponseHeaders": {
"apim-request-id": "d5806070-92e1-48b6-bb6a-ed229b2c3aed",
"apim-request-id": "289d2fb5-7e29-4e53-b5db-3fc2a61aed7f",
"Content-Type": "application/json",
"Date": "Thu, 27 Jan 2022 04:41:23 GMT",
"Date": "Thu, 31 Mar 2022 23:41:32 GMT",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "612"
"x-envoy-upstream-service-time": "387"
},
"ResponseBody": {
"error": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest
import functools
from devtools_testutils import recorded_by_proxy, set_custom_default_matcher
from devtools_testutils import recorded_by_proxy, set_bodiless_matcher, set_custom_default_matcher
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient, DocumentModelAdministrationClient, AnalyzeResult
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
Expand Down Expand Up @@ -209,10 +209,7 @@ def test_pages_kwarg_specified(self, client, formrecognizer_storage_container_sa
@DocumentModelAdministrationClientPreparer()
@recorded_by_proxy
def test_custom_document_signature_field(self, client, formrecognizer_storage_container_sas_url, **kwargs):
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
set_custom_default_matcher(
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
)
set_bodiless_matcher()
da_client = client.get_document_analysis_client()

with open(self.form_jpg, "rb") as fd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import functools
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils import set_custom_default_matcher
from devtools_testutils import set_bodiless_matcher, set_custom_default_matcher
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import AnalyzeResultOperation
from azure.ai.formrecognizer.aio import DocumentAnalysisClient, DocumentModelAdministrationClient
Expand Down Expand Up @@ -221,10 +221,7 @@ async def test_pages_kwarg_specified(self, client, formrecognizer_storage_contai
@DocumentModelAdministrationClientPreparer()
@recorded_by_proxy_async
async def test_custom_document_signature_field(self, client, formrecognizer_storage_container_sas_url, **kwargs):
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
set_custom_default_matcher(
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
)
set_bodiless_matcher()
da_client = client.get_document_analysis_client()

with open(self.form_jpg, "rb") as fd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid
import pytest
import functools
from devtools_testutils import recorded_by_proxy, set_custom_default_matcher
from devtools_testutils import recorded_by_proxy, set_bodiless_matcher, set_custom_default_matcher
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import GetOperationResponse, ModelInfo
Expand Down Expand Up @@ -241,12 +241,9 @@ def callback(response, _, headers):
@DocumentModelAdministrationClientPreparer()
@recorded_by_proxy
def test_build_model_azure_blob_path_filter(self, client, formrecognizer_storage_container_sas_url, **kwargs):
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
set_custom_default_matcher(
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
)
set_bodiless_matcher()
with pytest.raises(HttpResponseError) as e:
poller = client.begin_build_model(formrecognizer_storage_container_sas_url, "template", prefix="subfolder")
poller = client.begin_build_model(formrecognizer_storage_container_sas_url, "template", prefix="testfolder")
model = poller.result()

@pytest.mark.live_test_only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import functools
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils import set_custom_default_matcher
from devtools_testutils import set_bodiless_matcher, set_custom_default_matcher
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from azure.ai.formrecognizer._generated.v2022_01_30_preview.models import GetOperationResponse, ModelInfo
Expand Down Expand Up @@ -252,13 +252,10 @@ def callback(response, _, headers):
@DocumentModelAdministrationClientPreparer()
@recorded_by_proxy_async
async def test_build_model_azure_blob_path_filter(self, client, formrecognizer_storage_container_sas_url, **kwargs):
# this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers
set_custom_default_matcher(
compare_bodies=False, excluded_headers="Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id"
)
set_bodiless_matcher()
with pytest.raises(HttpResponseError) as e:
async with client:
poller = await client.begin_build_model(formrecognizer_storage_container_sas_url, "template", prefix="subfolder")
poller = await client.begin_build_model(formrecognizer_storage_container_sas_url, "template", prefix="testfolder")
model = await poller.result()

@pytest.mark.live_test_only
Expand Down
4 changes: 2 additions & 2 deletions tools/azure-sdk-tools/devtools_testutils/sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING

from .config import PROXY_URL
from .helpers import get_recording_id, is_live_and_not_recording
from .helpers import get_recording_id, is_live, is_live_and_not_recording

if TYPE_CHECKING:
from typing import Any, Dict, Optional
Expand Down Expand Up @@ -235,7 +235,7 @@ def _send_matcher_request(matcher, headers, parameters=None):
:param dict headers: Any matcher headers, as a dictionary.
"""

if is_live_and_not_recording():
if is_live():
return

headers_to_send = {"x-abstraction-identifier": matcher}
Expand Down

0 comments on commit 462edaa

Please sign in to comment.