def test_training_auth_bad_key(self, resource_group, location,
                                form_recognizer_account,
                                form_recognizer_account_key):
     client = FormTrainingClient(form_recognizer_account,
                                 AzureKeyCredential("xxxx"))
     with self.assertRaises(ClientAuthenticationError):
         poller = client.begin_train_model("xx")
    def train_model_with_labels(self):
        from azure.ai.formrecognizer import FormTrainingClient
        from azure.core.credentials import AzureKeyCredential

        form_training_client = FormTrainingClient(self.endpoint,
                                                  AzureKeyCredential(self.key))

        poller = form_training_client.begin_train_model(
            self.container_sas_url, use_training_labels=True)
        model = poller.result()

        # Custom model information
        print("Model ID: {}".format(model.model_id))
        print("Status: {}".format(model.status))
        print("Requested on: {}".format(model.requested_on))
        print("Completed on: {}".format(model.completed_on))

        print("Recognized fields:")
        # looping through the submodels, which contains the fields they were trained on
        # The labels are based on the ones you gave the training document.
        for submodel in model.submodels:
            print("...The submodel with form type {} has accuracy '{}'".format(
                submodel.form_type, submodel.accuracy))
            for name, field in submodel.fields.items():
                print(
                    "...The model found field '{}' to have name '{}' with an accuracy of {}"
                    .format(name, field.name, field.accuracy))

        # Training result information
        for doc in model.training_documents:
            print("Document name: {}".format(doc.document_name))
            print("Document status: {}".format(doc.status))
            print("Document page count: {}".format(doc.page_count))
            print("Document errors: {}".format(doc.errors))
    def train_model_without_labels(self):
        # [START training]
        from azure.ai.formrecognizer import FormTrainingClient
        from azure.core.credentials import AzureKeyCredential

        form_training_client = FormTrainingClient(self.endpoint,
                                                  AzureKeyCredential(self.key))

        # Default for begin_train_model is `use_training_labels=False`
        poller = form_training_client.begin_train_model(
            self.container_sas_url, use_training_labels=False)
        model = poller.result()

        # Custom model information
        print("Model ID: {}".format(model.model_id))
        print("Status: {}".format(model.status))
        print("Requested on: {}".format(model.requested_on))
        print("Completed on: {}".format(model.completed_on))

        print("Recognized fields:")
        # Looping through the submodels, which contains the fields they were trained on
        for submodel in model.submodels:
            print("...The submodel has form type '{}'".format(
                submodel.form_type))
            for name, field in submodel.fields.items():
                print(
                    "...The model found field '{}' to have label '{}'".format(
                        name, field.label))
        # [END training]
        # Training result information
        for doc in model.training_documents:
            print("Document name: {}".format(doc.document_name))
            print("Document status: {}".format(doc.status))
            print("Document page count: {}".format(doc.page_count))
            print("Document errors: {}".format(doc.errors))