Esempio n. 1
0
    def test_update_instance_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_update_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
        paths_element = "display_name"
        paths_element_2 = "memory_size_gb"
        paths = [paths_element, paths_element_2]
        update_mask = {"paths": paths}
        display_name = "UpdatedDisplayName"
        memory_size_gb = 4
        instance = {
            "display_name": display_name,
            "memory_size_gb": memory_size_gb
        }

        response = client.update_instance(update_mask, instance)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 2
0
    def test_update_instance(self):
        # Setup Expected Response
        name = "name3373707"
        display_name_2 = "displayName21615000987"
        location_id = "locationId552319461"
        alternative_location_id = "alternativeLocationId-718920621"
        redis_version = "redisVersion-685310444"
        reserved_ip_range = "reservedIpRange-1082940580"
        host = "host3208616"
        port = 3446913
        current_location_id = "currentLocationId1312712735"
        status_message = "statusMessage-239442758"
        memory_size_gb_2 = 1493816946
        authorized_network = "authorizedNetwork-1733809270"
        expected_response = {
            "name": name,
            "display_name": display_name_2,
            "location_id": location_id,
            "alternative_location_id": alternative_location_id,
            "redis_version": redis_version,
            "reserved_ip_range": reserved_ip_range,
            "host": host,
            "port": port,
            "current_location_id": current_location_id,
            "status_message": status_message,
            "memory_size_gb": memory_size_gb_2,
            "authorized_network": authorized_network,
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_update_instance", done=True
        )
        operation.response.Pack(expected_response)

        # 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
        paths_element = "display_name"
        paths_element_2 = "memory_size_gb"
        paths = [paths_element, paths_element_2]
        update_mask = {"paths": paths}
        display_name = "UpdatedDisplayName"
        memory_size_gb = 4
        instance = {"display_name": display_name, "memory_size_gb": memory_size_gb}

        response = client.update_instance(update_mask, instance)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.UpdateInstanceRequest(
            update_mask=update_mask, instance=instance
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
def sample_create_instance():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    instance = redis_v1.Instance()
    instance.name = "name_value"
    instance.tier = "STANDARD_HA"
    instance.memory_size_gb = 1499

    request = redis_v1.CreateInstanceRequest(
        parent="parent_value",
        instance_id="instance_id_value",
        instance=instance,
    )

    # Make the request
    operation = client.create_instance(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
Esempio n. 4
0
    def test_delete_instance(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = empty_pb2.Empty(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_delete_instance", done=True)
        operation.response.Pack(expected_response)

        # 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)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.DeleteInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 5
0
    def test_list_instances(self):
        # Setup Expected Response
        next_page_token = ''
        instances_element = {}
        instances = [instances_element]
        expected_response = {
            'next_page_token': next_page_token,
            'instances': instances
        }
        expected_response = cloud_redis_pb2.ListInstancesResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = redis_v1.CloudRedisClient(channel=channel)

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

        paged_list_response = client.list_instances(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.instances[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.ListInstancesRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 6
0
    def test_update_instance_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_update_instance_exception', done=True)
        operation.error.CopyFrom(error)

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

        # Setup Request
        paths_element = 'display_name'
        paths_element_2 = 'memory_size_gb'
        paths = [paths_element, paths_element_2]
        update_mask = {'paths': paths}
        display_name = 'UpdatedDisplayName'
        memory_size_gb = 4
        instance = {
            'display_name': display_name,
            'memory_size_gb': memory_size_gb
        }

        response = client.update_instance(update_mask, instance)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 7
0
    def test_list_instances(self):
        # Setup Expected Response
        next_page_token = ""
        instances_element = {}
        instances = [instances_element]
        expected_response = {
            "next_page_token": next_page_token,
            "instances": instances
        }
        expected_response = cloud_redis_pb2.ListInstancesResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        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
        parent = client.location_path("[PROJECT]", "[LOCATION]")

        paged_list_response = client.list_instances(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.instances[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.ListInstancesRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_instance(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        location_id = "locationId552319461"
        alternative_location_id = "alternativeLocationId-718920621"
        redis_version = "redisVersion-685310444"
        reserved_ip_range = "reservedIpRange-1082940580"
        host = "host3208616"
        port = 3446913
        current_location_id = "currentLocationId1312712735"
        status_message = "statusMessage-239442758"
        memory_size_gb_2 = 1493816946
        authorized_network = "authorizedNetwork-1733809270"
        persistence_iam_identity = "persistenceIamIdentity1061944584"
        expected_response = {
            "name": name,
            "display_name": display_name,
            "location_id": location_id,
            "alternative_location_id": alternative_location_id,
            "redis_version": redis_version,
            "reserved_ip_range": reserved_ip_range,
            "host": host,
            "port": port,
            "current_location_id": current_location_id,
            "status_message": status_message,
            "memory_size_gb": memory_size_gb_2,
            "authorized_network": authorized_network,
            "persistence_iam_identity": persistence_iam_identity,
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_create_instance", done=True
        )
        operation.response.Pack(expected_response)

        # 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
        parent = client.location_path("[PROJECT]", "[LOCATION]")
        instance_id = "test_instance"
        tier = enums.Instance.Tier.BASIC
        memory_size_gb = 1
        instance = {"tier": tier, "memory_size_gb": memory_size_gb}

        response = client.create_instance(parent, instance_id, instance)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.CreateInstanceRequest(
            parent=parent, instance_id=instance_id, instance=instance
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 9
0
    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])
        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
        parent = client.location_path("[PROJECT]", "[LOCATION]")
        instance_id = "test_instance"
        tier = enums.Instance.Tier.BASIC
        memory_size_gb = 1
        instance = {"tier": tier, "memory_size_gb": memory_size_gb}

        response = client.create_instance(parent, instance_id, instance)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 10
0
    def test_failover_instance(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        location_id = "locationId552319461"
        alternative_location_id = "alternativeLocationId-718920621"
        redis_version = "redisVersion-685310444"
        reserved_ip_range = "reservedIpRange-1082940580"
        host = "host3208616"
        port = 3446913
        current_location_id = "currentLocationId1312712735"
        status_message = "statusMessage-239442758"
        memory_size_gb = 34199707
        authorized_network = "authorizedNetwork-1733809270"
        persistence_iam_identity = "persistenceIamIdentity1061944584"
        expected_response = {
            "name": name_2,
            "display_name": display_name,
            "location_id": location_id,
            "alternative_location_id": alternative_location_id,
            "redis_version": redis_version,
            "reserved_ip_range": reserved_ip_range,
            "host": host,
            "port": port,
            "current_location_id": current_location_id,
            "status_message": status_message,
            "memory_size_gb": memory_size_gb,
            "authorized_network": authorized_network,
            "persistence_iam_identity": persistence_iam_identity,
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_failover_instance", done=True
        )
        operation.response.Pack(expected_response)

        # 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]")
        data_protection_mode = (
            enums.FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED
        )

        response = client.failover_instance(name, data_protection_mode)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.FailoverInstanceRequest(
            name=name, data_protection_mode=data_protection_mode
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 11
0
    def test_update_instance(self):
        # Setup Expected Response
        name = 'name3373707'
        display_name_2 = 'displayName21615000987'
        location_id = 'locationId552319461'
        alternative_location_id = 'alternativeLocationId-718920621'
        redis_version = 'redisVersion-685310444'
        reserved_ip_range = 'reservedIpRange-1082940580'
        host = 'host3208616'
        port = 3446913
        current_location_id = 'currentLocationId1312712735'
        status_message = 'statusMessage-239442758'
        memory_size_gb_2 = 1493816946
        authorized_network = 'authorizedNetwork-1733809270'
        expected_response = {
            'name': name,
            'display_name': display_name_2,
            'location_id': location_id,
            'alternative_location_id': alternative_location_id,
            'redis_version': redis_version,
            'reserved_ip_range': reserved_ip_range,
            'host': host,
            'port': port,
            'current_location_id': current_location_id,
            'status_message': status_message,
            'memory_size_gb': memory_size_gb_2,
            'authorized_network': authorized_network
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_update_instance', done=True)
        operation.response.Pack(expected_response)

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

        # Setup Request
        paths_element = 'display_name'
        paths_element_2 = 'memory_size_gb'
        paths = [paths_element, paths_element_2]
        update_mask = {'paths': paths}
        display_name = 'UpdatedDisplayName'
        memory_size_gb = 4
        instance = {
            'display_name': display_name,
            'memory_size_gb': memory_size_gb
        }

        response = client.update_instance(update_mask, instance)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.UpdateInstanceRequest(
            update_mask=update_mask, instance=instance)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_instance(self):
        # Setup Expected Response
        name = 'name3373707'
        display_name = 'displayName1615086568'
        location_id = 'locationId552319461'
        alternative_location_id = 'alternativeLocationId-718920621'
        redis_version = 'redisVersion-685310444'
        reserved_ip_range = 'reservedIpRange-1082940580'
        host = 'host3208616'
        port = 3446913
        current_location_id = 'currentLocationId1312712735'
        status_message = 'statusMessage-239442758'
        memory_size_gb_2 = 1493816946
        authorized_network = 'authorizedNetwork-1733809270'
        expected_response = {
            'name': name,
            'display_name': display_name,
            'location_id': location_id,
            'alternative_location_id': alternative_location_id,
            'redis_version': redis_version,
            'reserved_ip_range': reserved_ip_range,
            'host': host,
            'port': port,
            'current_location_id': current_location_id,
            'status_message': status_message,
            'memory_size_gb': memory_size_gb_2,
            'authorized_network': authorized_network
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_create_instance', done=True)
        operation.response.Pack(expected_response)

        # 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
        parent = client.location_path('[PROJECT]', '[LOCATION]')
        instance_id = 'test_instance'
        tier = enums.Instance.Tier.BASIC
        memory_size_gb = 1
        instance = {'tier': tier, 'memory_size_gb': memory_size_gb}

        response = client.create_instance(parent, instance_id, instance)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.CreateInstanceRequest(
            parent=parent, instance_id=instance_id, instance=instance)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 13
0
    def test_get_instance_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = redis_v1.CloudRedisClient(channel=channel)

        # Setup request
        name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')

        with pytest.raises(CustomException):
            client.get_instance(name)
Esempio n. 14
0
    def test_list_instances_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        client = redis_v1.CloudRedisClient(channel=channel)

        # Setup request
        parent = client.location_path('[PROJECT]', '[LOCATION]')

        paged_list_response = client.list_instances(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Esempio n. 15
0
def sample_get_instance():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.GetInstanceRequest(name="name_value", )

    # Make the request
    response = client.get_instance(request=request)

    # Handle the response
    print(response)
Esempio n. 16
0
def sample_list_instances():
    """Snippet for list_instances"""

    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.ListInstancesRequest()

    # Make the request
    page_result = client.list_instances(request=request)
    for response in page_result:
        print("{}".format(response))
Esempio n. 17
0
    def test_list_instances_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        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
        parent = client.location_path("[PROJECT]", "[LOCATION]")

        paged_list_response = client.list_instances(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Esempio n. 18
0
    def test_get_instance_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        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]")

        with pytest.raises(CustomException):
            client.get_instance(name)
def sample_list_instances():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.ListInstancesRequest(parent="parent_value", )

    # Make the request
    page_result = client.list_instances(request=request)

    # Handle the response
    for response in page_result:
        print(response)
Esempio n. 20
0
def sample_get_instance():
    """Snippet for get_instance"""

    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.GetInstanceRequest()

    # Make the request
    response = client.get_instance(request=request)

    # Handle response
    print("{}".format(response))
Esempio n. 21
0
def sample_delete_instance():
    """Snippet for delete_instance"""

    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.DeleteInstanceRequest()

    # Make the request
    operation = client.delete_instance(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()
    print("{}".format(response))
def sample_delete_instance():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    request = redis_v1.DeleteInstanceRequest(name="name_value", )

    # Make the request
    operation = client.delete_instance(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
    def test_get_instance(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        location_id = 'locationId552319461'
        alternative_location_id = 'alternativeLocationId-718920621'
        redis_version = 'redisVersion-685310444'
        reserved_ip_range = 'reservedIpRange-1082940580'
        host = 'host3208616'
        port = 3446913
        current_location_id = 'currentLocationId1312712735'
        status_message = 'statusMessage-239442758'
        memory_size_gb = 34199707
        authorized_network = 'authorizedNetwork-1733809270'
        expected_response = {
            'name': name_2,
            'display_name': display_name,
            'location_id': location_id,
            'alternative_location_id': alternative_location_id,
            'redis_version': redis_version,
            'reserved_ip_range': reserved_ip_range,
            'host': host,
            'port': port,
            'current_location_id': current_location_id,
            'status_message': status_message,
            'memory_size_gb': memory_size_gb,
            'authorized_network': authorized_network
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        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.get_instance(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.GetInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 24
0
    def test_get_instance(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        location_id = "locationId552319461"
        alternative_location_id = "alternativeLocationId-718920621"
        redis_version = "redisVersion-685310444"
        reserved_ip_range = "reservedIpRange-1082940580"
        host = "host3208616"
        port = 3446913
        current_location_id = "currentLocationId1312712735"
        status_message = "statusMessage-239442758"
        memory_size_gb = 34199707
        authorized_network = "authorizedNetwork-1733809270"
        expected_response = {
            "name": name_2,
            "display_name": display_name,
            "location_id": location_id,
            "alternative_location_id": alternative_location_id,
            "redis_version": redis_version,
            "reserved_ip_range": reserved_ip_range,
            "host": host,
            "port": port,
            "current_location_id": current_location_id,
            "status_message": status_message,
            "memory_size_gb": memory_size_gb,
            "authorized_network": authorized_network,
        }
        expected_response = cloud_redis_pb2.Instance(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        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.get_instance(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloud_redis_pb2.GetInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 25
0
    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])
        client = redis_v1.CloudRedisClient(channel=channel)

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

        response = client.delete_instance(name)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 26
0
    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_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_v1.CloudRedisClient()

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

        response = client.export_instance(name, output_config)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 28
0
    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 = redis_v1.CloudRedisClient(channel=channel)

        # Setup Request
        parent = client.location_path('[PROJECT]', '[LOCATION]')
        instance_id = 'test_instance'
        tier = enums.Instance.Tier.BASIC
        memory_size_gb = 1
        instance = {'tier': tier, 'memory_size_gb': memory_size_gb}

        response = client.create_instance(parent, instance_id, instance)
        exception = response.exception()
        assert exception.errors[0] == error
Esempio n. 29
0
def sample_import_instance():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    input_config = redis_v1.InputConfig()
    input_config.gcs_source.uri = "uri_value"

    request = redis_v1.ImportInstanceRequest(
        name="name_value",
        input_config=input_config,
    )

    # Make the request
    operation = client.import_instance(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
def sample_export_instance():
    # Create a client
    client = redis_v1.CloudRedisClient()

    # Initialize request argument(s)
    output_config = redis_v1.OutputConfig()
    output_config.gcs_destination.uri = "uri_value"

    request = redis_v1.ExportInstanceRequest(
        name="name_value",
        output_config=output_config,
    )

    # Make the request
    operation = client.export_instance(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)