def test_polling_interval(self, formrecognizer_test_endpoint, formrecognizer_test_api_key): client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), polling_interval=7) self.assertEqual(client._client._config.polling_interval, 7) poller = client.begin_recognize_invoices_from_url(self.invoice_url_pdf, polling_interval=6) poller.wait() self.assertEqual(poller._polling_method._timeout, 6) poller2 = client.begin_recognize_invoices_from_url(self.invoice_url_pdf) poller2.wait() self.assertEqual(poller2._polling_method._timeout, 7) # goes back to client default
def test_authentication_bad_key(self, formrecognizer_test_endpoint, formrecognizer_test_api_key): client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential("xxxx")) with self.assertRaises(ClientAuthenticationError): poller = client.begin_recognize_invoices_from_url( self.invoice_url_tiff)
def test_polling_interval(self, formrecognizer_test_endpoint, formrecognizer_test_api_key, **kwargs): set_bodiless_matcher() client = FormRecognizerClient( formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), polling_interval=7) assert client._client._config.polling_interval == 7 poller = client.begin_recognize_invoices_from_url(self.invoice_url_pdf, polling_interval=6) poller.wait() assert poller._polling_method._timeout == 6 poller2 = client.begin_recognize_invoices_from_url( self.invoice_url_pdf) poller2.wait() assert poller2._polling_method._timeout == 7 # goes back to client default
def test_invoice_url_bad_endpoint(self, formrecognizer_test_endpoint, formrecognizer_test_api_key): with self.assertRaises(ServiceRequestError): client = FormRecognizerClient( "http://notreal.azure.com", AzureKeyCredential(formrecognizer_test_api_key)) poller = client.begin_recognize_invoices_from_url( self.invoice_url_pdf)
def test_authentication_bad_key(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential("xxxx")) with self.assertRaises(ClientAuthenticationError): poller = client.begin_recognize_invoices_from_url( self.invoice_url_tiff)
def test_polling_interval(self, formrecognizer_test_endpoint, formrecognizer_test_api_key, **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" ) client = FormRecognizerClient( formrecognizer_test_endpoint, AzureKeyCredential(formrecognizer_test_api_key), polling_interval=7) assert client._client._config.polling_interval == 7 poller = client.begin_recognize_invoices_from_url(self.invoice_url_pdf, polling_interval=6) poller.wait() assert poller._polling_method._timeout == 6 poller2 = client.begin_recognize_invoices_from_url( self.invoice_url_pdf) poller2.wait() assert poller2._polling_method._timeout == 7 # goes back to client default
def test_logging_info_fr_client(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_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) result = poller.result() for message in mock_handler.messages: if message.levelname == "INFO": # not able to use json.loads here. At INFO level only API key should be REDACTED if message.message.find("Ocp-Apim-Subscription-Key") != -1: assert message.message.find("REDACTED") != -1 else: assert message.message.find("REDACTED") == -1
work_phones = business_card.fields.get("WorkPhones") if work_phones: for work_phone in work_phones.value: print("Work phone number: {} has confidence: {}".format( work_phone.value, work_phone.confidence)) other_phones = business_card.fields.get("OtherPhones") if other_phones: for other_phone in other_phones.value: print("Other phone number: {} has confidence: {}".format( other_phone.value, other_phone.confidence)) # </snippet_bc> # <snippet_invoice> invoiceUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/simple-invoice.png" poller = form_recognizer_client.begin_recognize_invoices_from_url(invoiceUrl) invoices = poller.result() for idx, invoice in enumerate(invoices): print("--------Recognizing invoice #{}--------".format(idx + 1)) vendor_name = invoice.fields.get("VendorName") if vendor_name: print("Vendor Name: {} has confidence: {}".format( vendor_name.value, vendor_name.confidence)) vendor_address = invoice.fields.get("VendorAddress") if vendor_address: print("Vendor Address: {} has confidence: {}".format( vendor_address.value, vendor_address.confidence)) customer_name = invoice.fields.get("CustomerName") if customer_name: print("Customer Name: {} has confidence: {}".format(