Пример #1
0
    def test_deploy_model_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_deploy_model_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = automl_v1beta1.AutoMlClient()

        # Setup Request
        name = client.model_path("[PROJECT]", "[LOCATION]", "[MODEL]")

        response = client.deploy_model(name)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_restore_agent_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_restore_agent_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")

        response = client.restore_agent(parent)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_instantiate_workflow_template_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_instantiate_workflow_template_exception',
            done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = dataproc_v1beta2.WorkflowTemplateServiceClient(
            channel=channel)

        # Setup Request
        name = client.workflow_template_path('[PROJECT]', '[REGION]',
                                             '[WORKFLOW_TEMPLATE]')

        response = client.instantiate_workflow_template(name)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #4
0
    def test_update_cluster_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_update_cluster_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = bigtable_admin_v2.BigtableInstanceAdminClient()

        # Setup Request
        serve_nodes = 1288838783

        response = client.update_cluster(serve_nodes)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #5
0
    def test_delete_glossary_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_delete_glossary_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = translate_v3beta1.TranslationServiceClient()

        # Setup Request
        name = client.glossary_path("[PROJECT]", "[LOCATION]", "[GLOSSARY]")

        response = client.delete_glossary(name)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #6
0
    def test_update_instance_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = instance_admin_client.InstanceAdminClient()

        # Mock request
        instance = spanner_instance_admin_pb2.Instance()
        field_mask = field_mask_pb2.FieldMask()

        # Mock exception response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_update_instance_exception', done=True)
        operation.error.CopyFrom(error)
        grpc_stub.UpdateInstance.return_value = operation

        response = client.update_instance(instance, field_mask)
        self.assertEqual(error, response.exception())
Пример #7
0
def get_hyperparameter_tuning_job_mock_with_fail():
    with patch.object(job_service_client.JobServiceClient,
                      "get_hyperparameter_tuning_job"
                      ) as get_hyperparameter_tuning_job_mock:
        get_hyperparameter_tuning_job_mock.side_effect = [
            _get_hyperparameter_tuning_job_proto(
                name=_TEST_HYPERPARAMETERTUNING_JOB_NAME,
                state=gca_job_state_compat.JobState.JOB_STATE_PENDING,
            ),
            _get_hyperparameter_tuning_job_proto(
                name=_TEST_HYPERPARAMETERTUNING_JOB_NAME,
                state=gca_job_state_compat.JobState.JOB_STATE_RUNNING,
            ),
            _get_hyperparameter_tuning_job_proto(
                name=_TEST_HYPERPARAMETERTUNING_JOB_NAME,
                state=gca_job_state_compat.JobState.JOB_STATE_FAILED,
                error=status_pb2.Status(message="Test Error"),
            ),
        ]
        yield get_hyperparameter_tuning_job_mock
    def test_run_asset_discovery_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_run_asset_discovery_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = securitycenter_v1p1beta1.SecurityCenterClient()

        # Setup Request
        parent = client.organization_path("[ORGANIZATION]")

        response = client.run_asset_discovery(parent)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #9
0
    def __init__(self, grpc_error):
        assert (grpc_error.code() == grpc.StatusCode.UNKNOWN)
        self.grpc_error = grpc_error

        error = None
        # The gRPC Python package does not have a convenient way to access the
        # binary details for the error: they are treated as trailing metadata.
        for meta in self.grpc_error.trailing_metadata():
            if meta[0] == "grpc-status-details-bin":
                error = status_pb2.Status()
                error.ParseFromString(meta[1])
                break
        if error is None:
            raise P4RuntimeErrorFormatException("No binary details field")

        if len(error.details) == 0:
            raise P4RuntimeErrorFormatException(
                "Binary details field has empty Any details repeated field")
        self.errors = error.details
        self.idx = 0
    def test_purge_products_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_purge_products_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = vision_v1p4beta1.ProductSearchClient()

        # Setup Request
        parent = client.location_path("[PROJECT]", "[LOCATION]")

        response = client.purge_products(parent)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_delete_instance_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_delete_instance_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = redis_v1.CloudRedisClient()

        # Setup Request
        name = client.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]")

        response = client.delete_instance(name)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_batch_delete_entities_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_batch_delete_entities_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.EntityTypesClient()

        # Setup Request
        parent = client.entity_type_path("[PROJECT]", "[ENTITY_TYPE]")
        entity_values = []

        response = client.batch_delete_entities(parent, entity_values)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_create_instance_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_create_instance_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = bigtable_admin_v2.BigtableInstanceAdminClient(channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')
        instance_id = 'instanceId-2101995259'
        instance = {}
        clusters = {}

        response = client.create_instance(parent, instance_id, instance,
                                          clusters)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #14
0
    def test_import_product_sets_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_import_product_sets_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = vision_v1p3beta1.ProductSearchClient()

        # Setup Request
        parent = client.location_path('[PROJECT]', '[LOCATION]')
        input_config = {}

        response = client.import_product_sets(parent, input_config)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_delete_document_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_delete_document_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.DocumentsClient()

        # Setup Request
        name = client.document_path("[PROJECT]", "[KNOWLEDGE_BASE]",
                                    "[DOCUMENT]")

        response = client.delete_document(name)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_batch_update_jobs_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_batch_update_jobs_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = talent_v4beta1.JobServiceClient()

        # Setup Request
        parent = client.tenant_path("[PROJECT]", "[TENANT]")
        jobs = []

        response = client.batch_update_jobs(parent, jobs)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #17
0
    def test_async_batch_annotate_files_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_async_batch_annotate_files_exception",
            done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = vision_v1p4beta1.ImageAnnotatorClient()

        # Setup Request
        requests = []

        response = client.async_batch_annotate_files(requests)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_snapshot_table_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_snapshot_table_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = bigtable_admin_v2.BigtableTableAdminClient(channel=channel)

        # Setup Request
        name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
        cluster = 'cluster872092154'
        snapshot_id = 'snapshotId-168585866'
        description = 'description-1724546052'

        response = client.snapshot_table(name, cluster, snapshot_id,
                                         description)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #19
0
    def test_annotate_video_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = videointelligence_v1p1beta1.VideoIntelligenceServiceClient(
            channel=channel)

        # Setup Request
        input_uri = 'gs://demomaker/cat.mp4'
        features_element = enums.Feature.LABEL_DETECTION
        features = [features_element]

        response = client.annotate_video(
            input_uri=input_uri, features=features)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #20
0
    def test_export_model_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_export_model_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = automl_v1beta1.AutoMlClient()

        # Setup Request
        name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
        output_config = {}

        response = client.export_model(name, output_config)
        exception = response.exception()
        assert exception.errors[0] == error
    def test__request_not_200(self):
        from google.cloud.exceptions import BadRequest
        from google.rpc import status_pb2

        error = status_pb2.Status()
        error.message = 'Entity value is indexed.'
        error.code = 9  # FAILED_PRECONDITION

        PROJECT = 'PROJECT'
        METHOD = 'METHOD'
        DATA = 'DATA'
        URI = 'http://api-url'
        conn = _Connection(URI)
        datastore_api = self._make_one(conn)
        conn.http = Http({'status': '400'}, error.SerializeToString())
        with self.assertRaises(BadRequest) as exc:
            datastore_api._request(PROJECT, METHOD, DATA)
        expected_message = '400 Entity value is indexed.'
        self.assertEqual(str(exc.exception), expected_message)
        self.assertEqual(conn.build_kwargs,
                         [{'method': METHOD, 'project': PROJECT}])
Пример #22
0
    def test_batch_update_entity_types_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_batch_update_entity_types_exception',
            done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2.EntityTypesClient()

        # Setup Request
        parent = client.project_agent_path('[PROJECT]')

        response = client.batch_update_entity_types(parent)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_create_table_from_snapshot_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_create_table_from_snapshot_exception',
            done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = bigtable_admin_v2.BigtableTableAdminClient(channel=channel)

        # Setup Request
        parent = client.instance_path('[PROJECT]', '[INSTANCE]')
        table_id = 'tableId-895419604'
        source_snapshot = 'sourceSnapshot-947679896'

        response = client.create_table_from_snapshot(parent, table_id,
                                                     source_snapshot)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_export_data_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_export_data_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = automl_v1.AutoMlClient()

        # Setup Request
        name = client.dataset_path("[PROJECT]", "[LOCATION]", "[DATASET]")
        output_config = {}

        response = client.export_data(name, output_config)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_update_database_ddl_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = database_admin_client.DatabaseAdminClient()

        # Mock request
        database = client.database_path('[PROJECT]', '[INSTANCE]',
                                        '[DATABASE]')
        statements = []

        # Mock exception response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_update_database_ddl_exception', done=True)
        operation.error.CopyFrom(error)
        grpc_stub.UpdateDatabaseDdl.return_value = operation

        response = client.update_database_ddl(database, statements)
        self.assertEqual(error, response.exception())
    def test_create_instance_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = spanner_admin_instance_v1.InstanceAdminClient()

        # Mock request
        parent = client.project_path('[PROJECT]')
        instance_id = 'instanceId-2101995259'
        instance = {}

        # Mock exception response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_create_instance_exception', done=True)
        operation.error.CopyFrom(error)
        grpc_stub.CreateInstance.return_value = operation

        response = client.create_instance(parent, instance_id, instance)
        self.assertEqual(error, response.exception())
Пример #27
0
    def test_export_assets_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_export_assets_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        parent = "parent-995424086"
        output_config = {}

        response = client.export_assets(parent, output_config)
        exception = response.exception()
        assert exception.errors[0] == error
Пример #28
0
    def test_annotate_video_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = video_intelligence_service_client.VideoIntelligenceServiceClient(
        )

        # Mock request
        input_uri = 'inputUri1707300727'
        features = []

        # Mock exception response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video_exception', done=True)
        operation.error.CopyFrom(error)
        grpc_stub.AnnotateVideo.return_value = operation

        response = client.annotate_video(input_uri, features)
        self.assertEqual(error, response.exception())
    def test_restore_database_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_restore_database_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = spanner_admin_database_v1.DatabaseAdminClient()

        # Setup Request
        parent = client.instance_path("[PROJECT]", "[INSTANCE]")
        database_id = "databaseId816491103"

        response = client.restore_database(parent, database_id)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_export_instance_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_export_instance_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = redis_v1beta1.CloudRedisClient()

        # Setup Request
        name = "name3373707"
        output_config = {}

        response = client.export_instance(name, output_config)
        exception = response.exception()
        assert exception.errors[0] == error