Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[formrecognizer] Clean up tests #16715

Merged
merged 8 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ def test_business_card_bad_endpoint(self, formrecognizer_test_endpoint, formreco
client = FormRecognizerClient("http://notreal.azure.com", AzureKeyCredential(formrecognizer_test_api_key))
poller = client.begin_recognize_business_cards(myfile)

@FormRecognizerPreparer()
def test_authentication_successful_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key))
with open(self.business_card_jpg, "rb") as fd:
myfile = fd.read()
poller = client.begin_recognize_business_cards(myfile)
result = poller.result()

@FormRecognizerPreparer()
def test_authentication_bad_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential("xxxx"))
Expand Down Expand Up @@ -249,52 +241,6 @@ def callback(raw_response, _, headers):
# Check page metadata
self.assertFormPagesTransformCorrect(returned_model, read_results)

@FormRecognizerPreparer()
@GlobalClientPreparer()
def test_business_card_jpg(self, client):

with open(self.business_card_jpg, "rb") as fd:
business_card = fd.read()

poller = client.begin_recognize_business_cards(business_card)

result = poller.result()
self.assertEqual(len(result), 1)
business_card = result[0]
# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")

@FormRecognizerPreparer()
@GlobalClientPreparer()
def test_business_card_png(self, client):
Expand Down Expand Up @@ -418,6 +364,40 @@ def test_business_card_jpg_include_field_elements(self, client):
for name, field in business_card.fields.items():
for f in field.value:
self.assertFieldElementsHasValues(f.value_data.field_elements, business_card.page_range.first_page_number)

kristapratico marked this conversation as resolved.
Show resolved Hide resolved
# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")

@FormRecognizerPreparer()
@GlobalClientPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ async def test_business_card_bad_endpoint(self, formrecognizer_test_endpoint, fo
async with client:
poller = await client.begin_recognize_business_cards(myfile)

@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_authentication_successful_key(self, client):
with open(self.business_card_jpg, "rb") as fd:
myfile = fd.read()
async with client:
poller = await client.begin_recognize_business_cards(myfile)
result = await poller.result()

@FormRecognizerPreparer()
async def test_authentication_bad_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential("xxxx"))
Expand Down Expand Up @@ -105,7 +96,6 @@ async def test_damaged_file_bytes_io_fails_autodetect(self, client):
@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_blank_page(self, client):

with open(self.blank_pdf, "rb") as fd:
blank = fd.read()
async with client:
Expand Down Expand Up @@ -137,7 +127,6 @@ async def test_passing_unsupported_url_content_type(self, client):
@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_auto_detect_unsupported_stream_content(self, client):

with open(self.unsupported_content_py, "rb") as fd:
myfile = fd.read()

Expand Down Expand Up @@ -264,54 +253,6 @@ def callback(raw_response, _, headers):
# Check page metadata
self.assertFormPagesTransformCorrect(returned_model, read_results)

@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_business_card_jpg(self, client):

with open(self.business_card_jpg, "rb") as fd:
business_card = fd.read()

async with client:
poller = await client.begin_recognize_business_cards(business_card)
result = await poller.result()

self.assertEqual(len(result), 1)
business_card = result[0]
# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")


@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_business_card_png(self, client):
Expand Down Expand Up @@ -361,7 +302,6 @@ async def test_business_card_png(self, client):
@FormRecognizerPreparer()
@GlobalClientPreparer()
async def test_business_card_multipage_pdf(self, client):

with open(self.business_card_multipage_pdf, "rb") as fd:
receipt = fd.read()

Expand Down Expand Up @@ -440,6 +380,40 @@ async def test_business_card_jpg_include_field_elements(self, client):
for f in field.value:
self.assertFieldElementsHasValues(f.value_data.field_elements, business_card.page_range.first_page_number)

# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")

@FormRecognizerPreparer()
@GlobalClientPreparer()
@pytest.mark.live_test_only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def test_business_card_url_bad_endpoint(self, formrecognizer_test_endpoint, form
client = FormRecognizerClient("http://notreal.azure.com", AzureKeyCredential(formrecognizer_test_api_key))
poller = client.begin_recognize_business_cards_from_url(self.business_card_url_jpg)

@FormRecognizerPreparer()
@GlobalClientPreparer()
def test_authentication_successful_key(self, client):
poller = client.begin_recognize_business_cards_from_url(self.business_card_url_jpg)
result = poller.result()

@FormRecognizerPreparer()
def test_authentication_bad_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key):
client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential("xxxx"))
Expand Down Expand Up @@ -180,48 +174,6 @@ def callback(raw_response, _, headers):
# Check page metadata
self.assertFormPagesTransformCorrect(returned_model, read_results)

@FormRecognizerPreparer()
@GlobalClientPreparer()
def test_business_card_jpg(self, client):
poller = client.begin_recognize_business_cards_from_url(self.business_card_url_jpg)

result = poller.result()
self.assertEqual(len(result), 1)
business_card = result[0]
# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")

@FormRecognizerPreparer()
@GlobalClientPreparer()
def test_business_card_png(self, client):
Expand Down Expand Up @@ -339,6 +291,40 @@ def test_business_card_jpg_include_field_elements(self, client):
for name, field in business_card.fields.items():
for f in field.value:
self.assertFieldElementsHasValues(f.value_data.field_elements, business_card.page_range.first_page_number)

# check dict values
self.assertEqual(len(business_card.fields.get("ContactNames").value), 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value_data.page_number, 1)
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['FirstName'].value, 'Avery')
self.assertEqual(business_card.fields.get("ContactNames").value[0].value['LastName'].value, 'Smith')

self.assertEqual(len(business_card.fields.get("JobTitles").value), 1)
self.assertEqual(business_card.fields.get("JobTitles").value[0].value, "Senior Researcher")

self.assertEqual(len(business_card.fields.get("Departments").value), 1)
self.assertEqual(business_card.fields.get("Departments").value[0].value, "Cloud & Al Department")

self.assertEqual(len(business_card.fields.get("Emails").value), 1)
self.assertEqual(business_card.fields.get("Emails").value[0].value, "avery.smith@contoso.com")

self.assertEqual(len(business_card.fields.get("Websites").value), 1)
self.assertEqual(business_card.fields.get("Websites").value[0].value, "https://www.contoso.com/")

# FIXME: uncomment https://github.com/Azure/azure-sdk-for-python/issues/14300
# self.assertEqual(len(business_card.fields.get("MobilePhones").value), 1)
# self.assertEqual(business_card.fields.get("MobilePhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("OtherPhones").value), 1)
# self.assertEqual(business_card.fields.get("OtherPhones").value[0].value, "https://www.contoso.com/")

# self.assertEqual(len(business_card.fields.get("Faxes").value), 1)
# self.assertEqual(business_card.fields.get("Faxes").value[0].value, "https://www.contoso.com/")

self.assertEqual(len(business_card.fields.get("Addresses").value), 1)
self.assertEqual(business_card.fields.get("Addresses").value[0].value, "2 Kingdom Street Paddington, London, W2 6BD")

self.assertEqual(len(business_card.fields.get("CompanyNames").value), 1)
self.assertEqual(business_card.fields.get("CompanyNames").value[0].value, "Contoso")

@FormRecognizerPreparer()
@GlobalClientPreparer()
Expand Down
Loading