Beispiel #1
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 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
Beispiel #3
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
Beispiel #4
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
Beispiel #6
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
    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