async def test_copy_model_with_labeled_model_name_v21(
            self, client, formrecognizer_storage_container_sas_url_v2,
            formrecognizer_region, formrecognizer_resource_id, **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"
        )
        async with client:
            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=True,
                model_name="mymodel")
            model = await poller.result()

            target = await client.get_copy_authorization(
                resource_region=formrecognizer_region,
                resource_id=formrecognizer_resource_id)

            poller = await client.begin_copy_model(model.model_id,
                                                   target=target)
            copy = await poller.result()

            copied_model = await client.get_custom_model(copy.model_id)

            assert copy.status == "ready"
            assert copy.training_started_on
            assert copy.training_completed_on
            assert target["modelId"] == copy.model_id
            assert target["modelId"] != model.model_id
            assert copied_model
            assert copied_model.model_name == "mymodel"
Ejemplo n.º 2
0
    async def test_build_model(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"
        )
        model_id = str(uuid.uuid4())
        async with client:
            poller = await client.begin_build_model(
                formrecognizer_storage_container_sas_url,
                "template",
                model_id=model_id,
                description="a v3 model",
                tags={"testkey": "testvalue"})
            model = await poller.result()

        if self.is_live:
            assert model.model_id == model_id

        assert model.model_id
        assert model.description == "a v3 model"
        assert model.created_on
        assert model.tags == {"testkey": "testvalue"}
        for name, doc_type in model.doc_types.items():
            assert name
            for key, field in doc_type.field_schema.items():
                assert key
                assert field["type"]
                assert doc_type.field_confidence[key] is not None
Ejemplo n.º 3
0
    async def test_build_model_multipage_transform(
            self, client, formrecognizer_multipage_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"
        )
        raw_response = []

        def callback(response, _, headers):
            op_response = client._deserialize(GetOperationResponse, response)
            model_info = client._deserialize(ModelInfo, op_response.result)
            document_model = DocumentModel._from_generated(model_info)
            raw_response.append(model_info)
            raw_response.append(document_model)

        async with client:
            poller = await client.begin_build_model(
                formrecognizer_multipage_storage_container_sas_url,
                "template",
                cls=callback)
            model = await poller.result()

        raw_model = raw_response[0]
        document_model = raw_response[1]
        self.assertModelTransformCorrect(document_model, raw_model)
Ejemplo n.º 4
0
    async def test_compose_model_v21(
            self, client, formrecognizer_storage_container_sas_url_v2,
            **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"
        )
        async with client:
            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=True)
            model_1 = await poller.result()

            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=True,
                model_name="second-labeled-model")
            model_2 = await poller.result()

            poller = await client.begin_create_composed_model(
                [model_1.model_id, model_2.model_id],
                model_name="my composed model")

            composed_model = await poller.result()

        composed_model_dict = composed_model.to_dict()
        composed_model = CustomFormModel.from_dict(composed_model_dict)
        self.assertComposedModelV2HasValues(composed_model, model_1, model_2)
Ejemplo n.º 5
0
    def test_get_form_recognizer_client_v2(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"
        )
        transport = RequestsTransport()
        ftc = FormTrainingClient(
            endpoint=formrecognizer_test_endpoint,
            credential=AzureKeyCredential(formrecognizer_test_api_key),
            transport=transport,
            api_version="2.1")

        with ftc:
            ftc.get_account_properties()
            assert transport.session is not None
            with ftc.get_form_recognizer_client() as frc:
                assert transport.session is not None
                frc.begin_recognize_receipts_from_url(
                    self.receipt_url_jpg).wait()
                assert frc._api_version == FormRecognizerApiVersion.V2_1
            ftc.get_account_properties()
            assert transport.session is not None
    async def test_batch_different_partition_operations_fail(
            self, tables_cosmos_account_name,
            tables_primary_cosmos_account_key):
        # 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"
        )

        # Arrange
        await self._set_up(tables_cosmos_account_name,
                           tables_primary_cosmos_account_key,
                           url="cosmos")
        try:
            entity = self._create_random_entity_dict('001', 'batch_negative_1')
            await self.table.create_entity(entity)

            # Act
            batch = []

            entity = self._create_updated_entity_dict('001',
                                                      'batch_negative_1')
            batch.append(('update', entity.copy()))

            entity = self._create_random_entity_dict('002', 'batch_negative_1')
            batch.append(('update', entity.copy(), {
                'mode': UpdateMode.REPLACE
            }))

            # Assert
            with pytest.raises(ValueError):
                await self.table.submit_transaction(batch)
        finally:
            await self._tear_down()
    async def test_batch_request_too_large(self, tables_cosmos_account_name,
                                           tables_primary_cosmos_account_key):
        # 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"
        )

        # Arrange
        await self._set_up(tables_cosmos_account_name,
                           tables_primary_cosmos_account_key,
                           url="cosmos")
        try:

            batch = []
            entity = {
                'PartitionKey': 'pk001',
                'Foo': os.urandom(1024 * 64),
                'Bar': os.urandom(1024 * 64),
                'Baz': os.urandom(1024 * 64)
            }
            for i in range(20):
                entity['RowKey'] = str(i)
                batch.append(('create', entity.copy()))

            with pytest.raises(RequestTooLargeError):
                await self.table.submit_transaction(batch)

        finally:
            await self._tear_down()
    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"
        )
        da_client = client.get_document_analysis_client()

        with open(self.form_jpg, "rb") as fd:
            my_file = fd.read()

        async with client:
            build_polling = await client.begin_build_model(
                formrecognizer_storage_container_sas_url, "template")
            model = await build_polling.result()

            async with da_client:
                poller = await da_client.begin_analyze_document(
                    model.model_id,
                    my_file,
                )
                result = await poller.result()

        assert result.documents[0].fields.get(
            "FullSignature").value == "signed"
        assert result.documents[0].fields.get(
            "FullSignature").value_type == "signature"
        # this will notify us of changes in the service, currently expecting to get a None content for signature type fields
        assert result.documents[0].fields.get("FullSignature").content == None
Ejemplo n.º 9
0
    async def test_training_without_labels_v2(self, client, formrecognizer_storage_container_sas_url_v2, **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"
        )
        async with client:
            poller = await client.begin_training(training_files_url=formrecognizer_storage_container_sas_url_v2, use_training_labels=True)
            model = await poller.result()

        model_dict = model.to_dict()
        model = CustomFormModel.from_dict(model_dict)

        assert model.model_id
        assert model.training_started_on
        assert model.training_completed_on
        assert model.errors == []
        assert model.status == "ready"
        for doc in model.training_documents:
            assert doc.name
            assert doc.page_count
            assert doc.status
            assert doc.errors == []
        for sub in model.submodels:
            assert sub.form_type
            assert sub.accuracy is not None
            for key, field in sub.fields.items():
                assert field.accuracy is not None
                assert field.name
Ejemplo n.º 10
0
    def test_get_account_backups(self):
        # 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"
        )
        create_backup(self.client,
                      backup_name=TEST_BACKUP_1,
                      live=self.is_live)

        account_backup = self.client.account_backups.get(
            TEST_RG, TEST_ACC_1, TEST_BACKUP_1)
        assert account_backup.name == TEST_ACC_1 + "/" + TEST_BACKUP_1

        disable_backup(self.client, TEST_BACKUP_1, live=self.is_live)
        delete_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_pool(self.client,
                    TEST_RG,
                    TEST_ACC_1,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
    async def test_pages_kwarg_specified(
            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"
        )
        da_client = client.get_document_analysis_client()

        with open(self.form_jpg, "rb") as fd:
            my_file = fd.read()

        async with client:
            build_poller = await client.begin_build_model(
                formrecognizer_storage_container_sas_url, "template")
            model = await build_poller.result()

            async with da_client:
                poller = await da_client.begin_analyze_document(model.model_id,
                                                                my_file,
                                                                pages="1")
                assert '1' == poller._polling_method._initial_response.http_response.request.query[
                    'pages']
                result = await poller.result()
                assert result
Ejemplo n.º 12
0
    def test_build_model_nested_schema_transform(self, client, formrecognizer_table_variable_rows_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"
        )
        
        raw_response = []

        def callback(response, _, headers):
            op_response = client._deserialize(GetOperationResponse, response)
            model_info = client._deserialize(ModelInfo, op_response.result)
            document_model = DocumentModel._from_generated(model_info)
            raw_response.append(model_info)
            raw_response.append(document_model)

        poller = client.begin_build_model(formrecognizer_table_variable_rows_container_sas_url, "template", cls=callback)
        model = poller.result()

        raw_model = raw_response[0]
        document_model = raw_response[1]
        self.assertModelTransformCorrect(document_model, raw_model)

        document_model_dict = document_model.to_dict()

        document_model_from_dict = _models.DocumentModel.from_dict(document_model_dict)
        assert document_model_from_dict.model_id == document_model.model_id
        self.assertModelTransformCorrect(document_model_from_dict, raw_model)
    def test_copy_model_with_composed_model_v21(self, client, formrecognizer_storage_container_sas_url_v2, formrecognizer_region, formrecognizer_resource_id, **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"
        )
        
        poller_1 = client.begin_training(formrecognizer_storage_container_sas_url_v2, use_training_labels=True, model_name="model1")
        model_1 = poller_1.result()

        poller_2 = client.begin_training(formrecognizer_storage_container_sas_url_v2, use_training_labels=True, model_name="model2")
        model_2 = poller_2.result()

        composed_poller = client.begin_create_composed_model([model_1.model_id, model_2.model_id], model_name="composedmodel")
        composed_model = composed_poller.result()

        target = client.get_copy_authorization(resource_region=formrecognizer_region, resource_id=formrecognizer_resource_id)

        poller = client.begin_copy_model(composed_model.model_id, target=target)
        copy = poller.result()

        copied_model = client.get_custom_model(copy.model_id)

        assert copy.status == "ready"
        assert copy.training_started_on
        assert copy.training_completed_on
        assert target["modelId"] == copy.model_id
        assert target["modelId"] != composed_model.model_id
        assert copied_model
        assert copied_model.model_name == "composedmodel"
        for submodel in copied_model.submodels:
            assert submodel.model_id in [model_1.model_id, model_2.model_id]
    async def test_get_document_analysis_client(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"
        )
        transport = AioHttpTransport()
        dtc = DocumentModelAdministrationClient(
            endpoint=formrecognizer_test_endpoint,
            credential=AzureKeyCredential(formrecognizer_test_api_key),
            transport=transport)

        async with dtc:
            await dtc.get_account_info()
            assert transport.session is not None
            async with dtc.get_document_analysis_client() as dac:
                assert transport.session is not None
                await (await dac.begin_analyze_document_from_url(
                    "prebuilt-receipt", self.receipt_url_jpg)).wait()
                assert dac._api_version == DocumentAnalysisApiVersion.V2022_01_30_PREVIEW
            await dtc.get_account_info()
            assert transport.session is not None
Ejemplo n.º 15
0
 def test_receipt_bad_url(self, client):
     # 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"
     )
     with pytest.raises(HttpResponseError):
         poller = client.begin_analyze_document_from_url("prebuilt-receipt", "https://badurl.jpg")
    async def test_pages_kwarg_specified(
            self, client, formrecognizer_testing_data_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"
        )
        fr_client = client.get_form_recognizer_client()
        blob_sas_url = _get_blob_url(
            formrecognizer_testing_data_container_sas_url, "testingdata",
            "multi1.pdf")

        async with fr_client:
            training_poller = await client.begin_training(
                formrecognizer_testing_data_container_sas_url,
                use_training_labels=False)
            model = await training_poller.result()

            poller = await fr_client.begin_recognize_custom_forms_from_url(
                model.model_id, blob_sas_url, pages=["1"])

            assert '1' == poller._polling_method._initial_response.http_response.request.query[
                'pages']
            result = await poller.result()
            assert result
Ejemplo n.º 17
0
    def test_receipt_multipage_url(self, client):
        # 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"
        )
        
        poller = client.begin_analyze_document_from_url("prebuilt-receipt", self.multipage_receipt_url_pdf)
        result = poller.result()

        assert len(result.documents) == 2
        receipt = result.documents[0]
        assert receipt.fields.get("MerchantAddress").value, '123 Main Street Redmond ==  WA 98052'
        assert receipt.fields.get("MerchantName").value ==  'Contoso'
        assert receipt.fields.get("MerchantPhoneNumber").value ==  '+19876543210'
        assert receipt.fields.get("Subtotal").value ==  11.7
        assert receipt.fields.get("TotalTax").value ==  1.17
        assert receipt.fields.get("Tip").value ==  1.63
        assert receipt.fields.get("Total").value ==  14.5
        assert receipt.fields.get("TransactionDate").value == date(year=2019, month=6, day=10)
        assert receipt.fields.get("TransactionTime").value == time(hour=13, minute=59, second=0)
        assert receipt.doc_type == "receipt.retailMeal"

        receipt = result.documents[1]
        assert receipt.fields.get("MerchantAddress").value, '123 Main Street Redmond ==  WA 98052'
        assert receipt.fields.get("MerchantName").value ==  'Contoso'
        assert receipt.fields.get("Subtotal").value ==  1098.99
        assert receipt.fields.get("TotalTax").value ==  104.4
        assert receipt.fields.get("Total").value ==  1203.39
        assert receipt.fields.get("TransactionDate").value == date(year=2019, month=6, day=10)
        assert receipt.fields.get("TransactionTime").value == time(hour=13, minute=59, second=0)
        assert receipt.doc_type == "receipt.retailMeal"

        assert len(result.pages) == 2
    async def test_form_multipage_labeled(
            self, client,
            formrecognizer_multipage_storage_container_sas_url_v2, **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"
        )
        fr_client = client.get_form_recognizer_client()
        blob_sas_url = _get_blob_url(
            formrecognizer_multipage_storage_container_sas_url_v2,
            "multipage-training-data", "multipage_invoice1.pdf")
        async with client:
            training_poller = await client.begin_training(
                formrecognizer_multipage_storage_container_sas_url_v2,
                use_training_labels=True)
            model = await training_poller.result()

            async with fr_client:
                poller = await fr_client.begin_recognize_custom_forms_from_url(
                    model.model_id, blob_sas_url)
                forms = await poller.result()

        for form in forms:
            assert form.form_type == "custom:" + model.model_id
            self.assertLabeledRecognizedFormHasValues(form, model)
    async def test_new_non_existent_table(self, tables_cosmos_account_name,
                                          tables_primary_cosmos_account_key):
        # 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"
        )

        # Arrange
        await self._set_up(tables_cosmos_account_name,
                           tables_primary_cosmos_account_key,
                           url="cosmos")
        try:
            entity = self._create_random_entity_dict('001', 'batch_negative_1')

            tc = self.ts.get_table_client("doesntexist")

            batch = [('create', entity)]

            with pytest.raises(TableTransactionError):
                resp = await tc.submit_transaction(batch)
            # Assert
        finally:
            await self._tear_down()
Ejemplo n.º 20
0
    async def test_identity_document_jpg_passport(self, client):
        # 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"
        )
        async with client:
            poller = await client.begin_analyze_document_from_url(
                "prebuilt-idDocument", self.identity_document_url_jpg_passport)

            result = await poller.result()
            assert len(result.documents) == 1

            id_document = result.documents[0]
            # check dict values

            passport = id_document.fields.get("MachineReadableZone").value
            assert passport["LastName"].value == "MARTIN"
            assert passport["FirstName"].value == "SARAH"
            assert passport["DocumentNumber"].value == "ZE000509"
            assert passport["DateOfBirth"].value == date(1985, 1, 1)
            assert passport["DateOfExpiration"].value == date(2023, 1, 14)
            assert passport["Sex"].value == "F"
            assert passport["CountryRegion"].value == "CAN"
Ejemplo n.º 21
0
    def test_mgmt_model(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"
        )
        
        poller = client.begin_build_model(formrecognizer_storage_container_sas_url, description="mgmt model")
        model = poller.result()

        model_from_get = client.get_model(model.model_id)

        assert model.model_id == model_from_get.model_id
        assert model.description == model_from_get.description
        assert model.created_on == model_from_get.created_on
        for name, doc_type in model.doc_types.items():
            assert name in model_from_get.doc_types
            for key, field in doc_type.field_schema.items():
                assert key in model_from_get.doc_types[name].field_schema
                assert field["type"] == model_from_get.doc_types[name].field_schema[key]["type"]
                assert doc_type.field_confidence[key] == model_from_get.doc_types[name].field_confidence[key]

        models_list = client.list_models()
        for model in models_list:
            assert model.model_id
            assert model.created_on

        client.delete_model(model.model_id)

        with pytest.raises(ResourceNotFoundError):
            client.get_model(model.model_id)
Ejemplo n.º 22
0
    async def test_identity_document_jpg(self, client):
        # 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"
        )
        async with client:
            poller = await client.begin_analyze_document_from_url(
                "prebuilt-idDocument", self.identity_document_url_jpg)

            result = await poller.result()
        assert len(result.documents) == 1
        id_document = result.documents[0]

        # check dict values
        assert id_document.fields.get("LastName").value == "TALBOT"
        assert id_document.fields.get("FirstName").value == "LIAM R."
        assert id_document.fields.get("DocumentNumber").value == "WDLABCD456DG"
        assert id_document.fields.get("DateOfBirth").value == date(1958, 1, 6)
        assert id_document.fields.get("DateOfExpiration").value == date(
            2020, 8, 12)
        assert id_document.fields.get("Sex").value == "M"
        assert id_document.fields.get(
            "Address").value == "123 STREET ADDRESS YOUR CITY WA 99999-1234"
        assert id_document.fields.get("CountryRegion").value == "USA"
        assert id_document.fields.get("Region").value == "Washington"
Ejemplo n.º 23
0
    async def test_compose_model_invalid_unlabeled_models_v21(
            self, client, formrecognizer_storage_container_sas_url_v2,
            **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"
        )
        async with client:
            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=False)
            model_1 = await poller.result()

            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=False)
            model_2 = await poller.result()

            with pytest.raises(HttpResponseError) as e:
                poller = await client.begin_create_composed_model(
                    [model_1.model_id, model_2.model_id])
                composed_model = await poller.result()
            assert e.value.error.code == "1001"
            assert e.value.error.message
Ejemplo n.º 24
0
    async def test_invoice_tiff(self, client, **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"
        )
        async with client:
            poller = await client.begin_analyze_document_from_url(
                model="prebuilt-invoice", document_url=self.invoice_url_tiff)

            result = await poller.result()
        assert len(result.documents) == 1
        invoice = result.documents[0]

        # check dict values
        assert invoice.fields.get("VendorName").value == "Contoso"
        assert invoice.fields.get(
            "VendorAddress"
        ).value, '1 Redmond way Suite 6000 Redmond ==  WA 99243'
        assert invoice.fields.get(
            "CustomerAddressRecipient").value == "Microsoft"
        assert invoice.fields.get(
            "CustomerAddress"
        ).value, '1020 Enterprise Way Sunnayvale ==  CA 87659'
        assert invoice.fields.get("CustomerName").value == "Microsoft"
        assert invoice.fields.get("InvoiceId").value == '34278587'
        assert invoice.fields.get("InvoiceDate").value, date(2017, 6 == 18)
        assert invoice.fields.get(
            "Items").value[0].value["Amount"].value.amount == 56651.49
        assert invoice.fields.get(
            "Items").value[0].value["Amount"].value.symbol == "$"
        assert invoice.fields.get("DueDate").value, date(2017, 6 == 24)
    def test_poller_metadata(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"
        )
        poller = client.begin_build_model(
            formrecognizer_storage_container_sas_url, "template")
        model_1 = poller.result()

        poller = client.begin_build_model(
            formrecognizer_storage_container_sas_url, "template")
        model_2 = poller.result()

        poller = client.begin_create_composed_model(
            [model_1.model_id, model_2.model_id])
        assert poller.operation_id
        assert poller.percent_completed is not None
        poller.result()
        assert poller.operation_kind == "documentModelCompose"
        assert poller.percent_completed == 100
        assert poller.resource_location_url
        assert poller.created_on
        assert poller.last_updated_on
Ejemplo n.º 26
0
    def test_get_volume_by_name(self):
        # 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"
        )
        create_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      LOCATION,
                      live=self.is_live)

        volume = self.client.volumes.get(TEST_RG, TEST_ACC_1, TEST_POOL_1,
                                         TEST_VOL_1)
        assert volume.name == TEST_ACC_1 + '/' + TEST_POOL_1 + '/' + TEST_VOL_1

        delete_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_pool(self.client,
                    TEST_RG,
                    TEST_ACC_1,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
Ejemplo n.º 27
0
    async def test_build_model_multipage(
            self, client, formrecognizer_multipage_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"
        )
        async with client:
            poller = await client.begin_build_model(
                formrecognizer_multipage_storage_container_sas_url, "template")
            model = await poller.result()

        assert model.model_id
        assert model.api_version
        assert model.tags is None
        assert model.description is None
        assert model.created_on
        for name, doc_type in model.doc_types.items():
            assert name
            for key, field in doc_type.field_schema.items():
                assert key
                assert field["type"]
                assert doc_type.field_confidence[key] is not None
                assert doc_type.build_mode == "template"
Ejemplo n.º 28
0
    def test_patch_volume(self):
        # 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"
        )
        volume = create_volume(self.client,
                               TEST_RG,
                               TEST_ACC_1,
                               TEST_POOL_1,
                               TEST_VOL_1,
                               live=self.is_live)
        assert "Premium" == volume.service_level
        assert 100 * GIGABYTE == volume.usage_threshold

        volume_patch = VolumePatch(usage_threshold=200 * GIGABYTE)
        volume = self.client.volumes.begin_update(TEST_RG, TEST_ACC_1,
                                                  TEST_POOL_1, TEST_VOL_1,
                                                  volume_patch).result()
        assert "Premium" == volume.service_level
        assert 200 * GIGABYTE == volume.usage_threshold

        delete_volume(self.client,
                      TEST_RG,
                      TEST_ACC_1,
                      TEST_POOL_1,
                      TEST_VOL_1,
                      live=self.is_live)
        delete_pool(self.client,
                    TEST_RG,
                    TEST_ACC_1,
                    TEST_POOL_1,
                    live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
Ejemplo n.º 29
0
    async def test_build_model_polling_interval(
            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"
        )

        def check_poll_value(poll):
            if self.is_live:
                assert poll == 5
            else:
                assert poll == 0

        check_poll_value(client._client._config.polling_interval)
        poller = await client.begin_build_model(
            source=formrecognizer_storage_container_sas_url,
            build_mode="template",
            polling_interval=6)
        await poller.wait()
        assert poller._polling_method._timeout == 6
        poller2 = await client.begin_build_model(
            source=formrecognizer_storage_container_sas_url,
            build_mode="template")
        await poller2.wait()
        check_poll_value(
            poller2._polling_method._timeout)  # goes back to client default
        await client.close()
    async def test_copy_model_fail_v21(
            self, client, formrecognizer_storage_container_sas_url_v2,
            formrecognizer_region, formrecognizer_resource_id, **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"
        )
        async with client:
            poller = await client.begin_training(
                formrecognizer_storage_container_sas_url_v2,
                use_training_labels=False)
            model = await poller.result()

            # give an incorrect region
            target = await client.get_copy_authorization(
                resource_region="eastus",
                resource_id=formrecognizer_resource_id)

            with pytest.raises(HttpResponseError) as e:
                poller = await client.begin_copy_model(model.model_id,
                                                       target=target)
                copy = await poller.result()
            assert e.value.error.code == "2024"
            assert e.value.error.message