Skip to content

Commit

Permalink
reenable tests (Azure#20978)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico committed Sep 30, 2021
1 parent 5069292 commit 561d522
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __init__(self, endpoint, credential, **kwargs):
"op",
"pages",
"readingOrder",
"stringIndexType",
"api-version"
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def __init__(
"op",
"pages",
"readingOrder",
"stringIndexType",
"api-version"
}
)
self._client = FormRecognizer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ interactions:
Content-Length:
- '154512'
Content-Type:
- image/jpeg
- application/octet-stream
User-Agent:
- azsdk-python-ai-formrecognizer/3.2.0b1 Python/3.9.1 (Windows-10-10.0.19041-SP0)
- azsdk-python-ai-formrecognizer/3.2.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
uri: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
response:
body:
string: '{"error": {"code": "UnsupportedLocale", "innerError": {"requestId":
"c6836b61-db64-4355-8b25-e1948f564d44"}, "message": "Locale unsupported. Supported
locales include en-AU, en-CA, en-GB, en-IN and en-US."}}'
string: '{"error": {"code": "InvalidArgument", "message": "Invalid argument.",
"innererror": {"code": "InvalidParameter", "message": "The parameter Locale
is invalid: The language code is invalid or not supported."}}}'
headers:
apim-request-id:
- c6836b61-db64-4355-8b25-e1948f564d44
content-length:
- '200'
- edf133b9-e46e-458e-a38e-3a148a6ed1f2
content-type:
- application/json; charset=utf-8
date:
- Mon, 30 Aug 2021 23:48:59 GMT
- Thu, 30 Sep 2021 17:06:02 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '113'
- '135'
status:
code: 400
message: Bad Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ interactions:
Accept:
- application/json
Content-Type:
- image/jpeg
- application/octet-stream
User-Agent:
- azsdk-python-ai-formrecognizer/3.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-ai-formrecognizer/3.2.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
uri: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
response:
body:
string: '{"error": {"code": "UnsupportedLocale", "innerError": {"requestId":
"4c27b38d-d0e4-4b41-b76a-0422a7b924b9"}, "message": "Locale unsupported. Supported
locales include en-AU, en-CA, en-GB, en-IN and en-US."}}'
string: '{"error": {"code": "InvalidArgument", "message": "Invalid argument.",
"innererror": {"code": "InvalidParameter", "message": "The parameter Locale
is invalid: The language code is invalid or not supported."}}}'
headers:
apim-request-id: 4c27b38d-d0e4-4b41-b76a-0422a7b924b9
content-length: '200'
apim-request-id: 8f6bc0ec-dfbe-4d03-895f-b0cf4bec6192
content-type: application/json; charset=utf-8
date: Tue, 11 May 2021 03:08:08 GMT
date: Thu, 30 Sep 2021 17:06:19 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '134'
x-envoy-upstream-service-time: '69'
status:
code: 400
message: Bad Request
url: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
url: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
version: 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interactions:
- request:
body: 'b''{"source": "blob_sas_url"}'''
body: 'b''{"urlSource": "blob_sas_url"}'''
headers:
Accept:
- application/json
Expand All @@ -9,33 +9,33 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '221'
- '224'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-formrecognizer/3.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-ai-formrecognizer/3.2.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
uri: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
response:
body:
string: '{"error": {"code": "UnsupportedLocale", "innerError": {"requestId":
"04a5530c-7246-4327-9661-6579f4ac252b"}, "message": "Locale unsupported. Supported
locales include en-AU, en-CA, en-GB, en-IN and en-US."}}'
string: '{"error": {"code": "InvalidArgument", "message": "Invalid argument.",
"innererror": {"code": "InvalidParameter", "message": "The parameter Locale
is invalid: The language code is invalid or not supported."}}}'
headers:
apim-request-id:
- 04a5530c-7246-4327-9661-6579f4ac252b
content-length:
- '200'
- 37eba60a-f330-4c8f-94cf-8747ba3c2fc5
content-type:
- application/json; charset=utf-8
date:
- Tue, 11 May 2021 03:09:31 GMT
- Thu, 30 Sep 2021 17:05:04 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '289'
- '564'
status:
code: 400
message: Bad Request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
interactions:
- request:
body: 'b''{"source": "blob_sas_url"}'''
body: 'b''{"urlSource": "blob_sas_url"}'''
headers:
Accept:
- application/json
Content-Length:
- '221'
- '224'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-formrecognizer/3.1.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-ai-formrecognizer/3.2.0b1 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
uri: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
response:
body:
string: '{"error": {"code": "UnsupportedLocale", "innerError": {"requestId":
"c72b100e-f260-4bd3-874f-3354e1b08e83"}, "message": "Locale unsupported. Supported
locales include en-AU, en-CA, en-GB, en-IN and en-US."}}'
string: '{"error": {"code": "InvalidArgument", "message": "Invalid argument.",
"innererror": {"code": "InvalidParameter", "message": "The parameter Locale
is invalid: The language code is invalid or not supported."}}}'
headers:
apim-request-id: c72b100e-f260-4bd3-874f-3354e1b08e83
content-length: '200'
apim-request-id: e6c4d122-9c19-4bfb-9d69-f5914cfc29b4
content-type: application/json; charset=utf-8
date: Tue, 11 May 2021 03:12:51 GMT
date: Thu, 30 Sep 2021 17:06:34 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '897'
x-envoy-upstream-service-time: '581'
status:
code: 400
message: Bad Request
url: https://region.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/receipt/analyze?includeTextDetails=false&locale=not%20a%20locale
url: https://region.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-receipt:analyze?locale=not%20a%20locale&stringIndexType=unicodeCodePoint&api-version=2021-09-30-preview
version: 1
24 changes: 12 additions & 12 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
except ImportError: # python < 3.3
import mock # type: ignore

from azure.ai.formrecognizer import FormRecognizerClient, FormTrainingClient
from azure.ai.formrecognizer import DocumentAnalysisClient, DocumentModelAdministrationClient
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import HttpResponseError
from testcase import FormRecognizerTest
Expand All @@ -27,20 +27,20 @@ def __init__(self):
def emit(self, record):
self.messages.append(record)

@pytest.mark.skip

class TestLogging(FormRecognizerTest):

@FormRecognizerPreparer()
@pytest.mark.live_test_only
def test_logging_info_fr_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
def test_logging_info_dac_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
mock_handler = MockHandler()

logger = logging.getLogger("azure")
logger.addHandler(mock_handler)
logger.setLevel(logging.INFO)

poller = client.begin_recognize_invoices_from_url(self.receipt_url_jpg)
poller = client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
result = poller.result()

for message in mock_handler.messages:
Expand All @@ -53,15 +53,15 @@ def test_logging_info_fr_client(self, formrecognizer_test_endpoint, formrecogniz

@FormRecognizerPreparer()
@pytest.mark.live_test_only
def test_logging_info_ft_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormTrainingClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
def test_logging_info_dmac_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = DocumentModelAdministrationClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
mock_handler = MockHandler()

logger = logging.getLogger("azure")
logger.addHandler(mock_handler)
logger.setLevel(logging.INFO)

result = client.get_account_properties()
result = client.get_account_info()

for message in mock_handler.messages:
if message.levelname == "INFO":
Expand All @@ -86,10 +86,10 @@ def test_mock_quota_exceeded_403(self, formrecognizer_test_endpoint, formrecogni
response.content_type = "application/json"
transport = mock.Mock(send=lambda request, **kwargs: response)

client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)

with pytest.raises(HttpResponseError) as e:
poller = client.begin_recognize_receipts_from_url(self.receipt_url_jpg)
poller = client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
assert e.value.status_code == 403
assert e.value.error.message == 'Out of call volume quota for FormRecognizer F0 pricing tier. Please retry after 1 day. To increase your call volume switch to a paid tier.'

Expand All @@ -108,9 +108,9 @@ def test_mock_quota_exceeded_429(self, formrecognizer_test_endpoint, formrecogni
response.content_type = "application/json"
transport = mock.Mock(send=lambda request, **kwargs: response)

client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)

with pytest.raises(HttpResponseError) as e:
poller = client.begin_recognize_receipts_from_url(self.receipt_url_jpg)
poller = client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
assert e.value.status_code == 429
assert e.value.error.message == 'Out of call volume quota for FormRecognizer F0 pricing tier. Please retry after 1 day. To increase your call volume switch to a paid tier.'
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from unittest import mock
except ImportError: # python < 3.3
import mock # type: ignore
from azure.ai.formrecognizer.aio import FormRecognizerClient, FormTrainingClient
from azure.ai.formrecognizer.aio import DocumentAnalysisClient, DocumentModelAdministrationClient
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import HttpResponseError
from preparers import FormRecognizerPreparer
Expand Down Expand Up @@ -62,20 +62,20 @@ def __init__(self, *args, **kwargs):
self.__aenter__ = mock.Mock(return_value=get_completed_future())
self.__aexit__ = mock.Mock(return_value=get_completed_future())

@pytest.mark.skip

class TestLogging(AsyncFormRecognizerTest):

@FormRecognizerPreparer()
@pytest.mark.live_test_only
async def test_logging_info_fr_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
async def test_logging_info_dac_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
mock_handler = MockHandler()

logger = logging.getLogger("azure")
logger.addHandler(mock_handler)
logger.setLevel(logging.INFO)
async with client:
poller = await client.begin_recognize_invoices_from_url(self.receipt_url_jpg)
poller = await client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
result = await poller.result()

for message in mock_handler.messages:
Expand All @@ -88,15 +88,15 @@ async def test_logging_info_fr_client(self, formrecognizer_test_endpoint, formre

@FormRecognizerPreparer()
@pytest.mark.live_test_only
async def test_logging_info_ft_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormTrainingClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
async def test_logging_info_dmac_client(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = DocumentModelAdministrationClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
mock_handler = MockHandler()

logger = logging.getLogger("azure")
logger.addHandler(mock_handler)
logger.setLevel(logging.INFO)
async with client:
result = await client.get_account_properties()
result = await client.get_account_info()

for message in mock_handler.messages:
if message.levelname == "INFO":
Expand All @@ -121,10 +121,10 @@ async def test_mock_quota_exceeded_403(self, formrecognizer_test_endpoint, formr
response.content_type = "application/json"
transport = AsyncMockTransport(send=wrap_in_future(lambda request, **kwargs: response))

client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)

with pytest.raises(HttpResponseError) as e:
poller = await client.begin_recognize_receipts_from_url(self.receipt_url_jpg)
poller = await client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
assert e.value.status_code == 403
assert e.value.error.message == 'Out of call volume quota for FormRecognizer F0 pricing tier. Please retry after 1 day. To increase your call volume switch to a paid tier.'

Expand All @@ -142,8 +142,8 @@ async def test_mock_quota_exceeded_429(self, formrecognizer_test_endpoint, formr
response.content_type = "application/json"
transport = AsyncMockTransport(send=wrap_in_future(lambda request, **kwargs: response))

client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)
client = DocumentAnalysisClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), transport=transport)
with pytest.raises(HttpResponseError) as e:
poller = await client.begin_recognize_receipts_from_url(self.receipt_url_jpg)
poller = await client.begin_analyze_document_from_url("prebuilt-receipt", self.receipt_url_jpg)
assert e.value.status_code == 429
assert e.value.error.message == 'Out of call volume quota for FormRecognizer F0 pricing tier. Please retry after 1 day. To increase your call volume switch to a paid tier.'
assert e.value.error.message == 'Out of call volume quota for FormRecognizer F0 pricing tier. Please retry after 1 day. To increase your call volume switch to a paid tier.'
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

class TestManagement(FormRecognizerTest):

@pytest.mark.skip("aad not working in canary")
@FormRecognizerPreparer()
@pytest.mark.live_test_only
def test_active_directory_auth(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

class TestManagementAsync(AsyncFormRecognizerTest):

@pytest.mark.skip("no aad yet in private preview")
@FormRecognizerPreparer()
@pytest.mark.live_test_only
async def test_active_directory_auth_async(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,12 @@ def test_receipt_locale_specified(self, client):

@FormRecognizerPreparer()
@GlobalClientPreparer()
@pytest.mark.skip("the service is returning a different error code")
def test_receipt_locale_error(self, client):
with open(self.receipt_jpg, "rb") as fd:
receipt = fd.read()
with pytest.raises(HttpResponseError) as e:
client.begin_analyze_document("prebuilt-receipt", receipt, locale="not a locale")
assert "UnsupportedLocale" == e.value.error.code
assert "InvalidArgument" == e.value.error.code

@FormRecognizerPreparer()
@GlobalClientPreparerV2(client_kwargs={"api_version": FormRecognizerApiVersion.V2_0})
Expand Down
Loading

0 comments on commit 561d522

Please sign in to comment.