def test_update_instance(self):
        # Setup Expected Response
        name = 'name3373707'
        config = 'config-1354792126'
        display_name = 'displayName1615086568'
        node_count = 1539922066
        expected_response = {
            'name': name,
            'config': config,
            'display_name': display_name,
            'node_count': node_count
        }
        expected_response = spanner_instance_admin_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 = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

        # Setup Request
        instance = {}
        field_mask = {}

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

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.UpdateInstanceRequest(
            instance=instance, field_mask=field_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #2
0
    def test_list_instance_configs(self):
        # Setup Expected Response
        next_page_token = ""
        instance_configs_element = {}
        instance_configs = [instance_configs_element]
        expected_response = {
            "next_page_token": next_page_token,
            "instance_configs": instance_configs,
        }
        expected_response = spanner_instance_admin_pb2.ListInstanceConfigsResponse(
            **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 = spanner_admin_instance_v1.InstanceAdminClient()

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

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

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

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.ListInstanceConfigsRequest(
            parent=parent
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_instance(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        config = 'config-1354792126'
        display_name = 'displayName1615086568'
        node_count = 1539922066
        expected_response = {
            'name': name_2,
            'config': config,
            'display_name': display_name,
            'node_count': node_count
        }
        expected_response = spanner_instance_admin_pb2.Instance(
            **expected_response)

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

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

        response = client.get_instance(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.GetInstanceRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_iam_policy(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
        resource = client.instance_path('[PROJECT]', '[INSTANCE]')

        # Mock response
        version = 351608024
        etag = b'21'
        expected_response = {'version': version, 'etag': etag}
        expected_response = policy_pb2.Policy(**expected_response)
        grpc_stub.GetIamPolicy.return_value = expected_response

        response = client.get_iam_policy(resource)
        self.assertEqual(expected_response, response)

        grpc_stub.GetIamPolicy.assert_called_once()
        args, kwargs = grpc_stub.GetIamPolicy.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = iam_policy_pb2.GetIamPolicyRequest(
            resource=resource)
        self.assertEqual(expected_request, actual_request)
Example #5
0
    def test_test_iam_permissions(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = iam_policy_pb2.TestIamPermissionsResponse(
            **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 = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup Request
        resource = client.instance_path("[PROJECT]", "[INSTANCE]")
        permissions = []

        response = client.test_iam_permissions(resource, permissions)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = iam_policy_pb2.TestIamPermissionsRequest(
            resource=resource, permissions=permissions
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_test_iam_permissions(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
        resource = client.instance_path('[PROJECT]', '[INSTANCE]')
        permissions = []

        # Mock response
        expected_response = {}
        expected_response = iam_policy_pb2.TestIamPermissionsResponse(
            **expected_response)
        grpc_stub.TestIamPermissions.return_value = expected_response

        response = client.test_iam_permissions(resource, permissions)
        self.assertEqual(expected_response, response)

        grpc_stub.TestIamPermissions.assert_called_once()
        args, kwargs = grpc_stub.TestIamPermissions.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = iam_policy_pb2.TestIamPermissionsRequest(
            resource=resource, permissions=permissions)
        self.assertEqual(expected_request, actual_request)
Example #7
0
    def test_set_iam_policy(self):
        # Setup Expected Response
        version = 351608024
        etag = b"21"
        expected_response = {"version": version, "etag": etag}
        expected_response = policy_pb2.Policy(**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 = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup Request
        resource = client.instance_path("[PROJECT]", "[INSTANCE]")
        policy = {}

        response = client.set_iam_policy(resource, policy)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = iam_policy_pb2.SetIamPolicyRequest(
            resource=resource, policy=policy
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_instance_config(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
        name = client.instance_config_path('[PROJECT]', '[INSTANCE_CONFIG]')

        # Mock response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        expected_response = {'name': name_2, 'display_name': display_name}
        expected_response = spanner_instance_admin_pb2.InstanceConfig(
            **expected_response)
        grpc_stub.GetInstanceConfig.return_value = expected_response

        response = client.get_instance_config(name)
        self.assertEqual(expected_response, response)

        grpc_stub.GetInstanceConfig.assert_called_once()
        args, kwargs = grpc_stub.GetInstanceConfig.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name)
        self.assertEqual(expected_request, actual_request)
Example #9
0
    def test_get_instance(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        config = "config-1354792126"
        display_name = "displayName1615086568"
        node_count = 1539922066
        expected_response = {
            "name": name_2,
            "config": config,
            "display_name": display_name,
            "node_count": node_count,
        }
        expected_response = spanner_instance_admin_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 = spanner_admin_instance_v1.InstanceAdminClient()

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

        response = client.get_instance(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.GetInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #10
0
    def test_get_iam_policy(self):
        # Setup Expected Response
        version = 351608024
        etag = b'21'
        expected_response = {'version': version, 'etag': etag}
        expected_response = policy_pb2.Policy(**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 = spanner_admin_instance_v1.InstanceAdminClient()

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

        response = client.get_iam_policy(resource)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = iam_policy_pb2.GetIamPolicyRequest(
            resource=resource)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
def sample_create_instance():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

    # Initialize request argument(s)
    instance = spanner_admin_instance_v1.Instance()
    instance.name = "name_value"
    instance.config = "config_value"
    instance.display_name = "display_name_value"

    request = spanner_admin_instance_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)
Example #12
0
    def test_get_instance_config(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        expected_response = {'name': name_2, 'display_name': display_name}
        expected_response = spanner_instance_admin_pb2.InstanceConfig(
            **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 = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup Request
        name = client.instance_config_path('[PROJECT]', '[INSTANCE_CONFIG]')

        response = client.get_instance_config(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_list_instance_configs(self):
        # Setup Expected Response
        next_page_token = ''
        instance_configs_element = {}
        instance_configs = [instance_configs_element]
        expected_response = {
            'next_page_token': next_page_token,
            'instance_configs': instance_configs
        }
        expected_response = spanner_instance_admin_pb2.ListInstanceConfigsResponse(
            **expected_response)

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

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

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

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

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.ListInstanceConfigsRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_delete_instance_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

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

        with pytest.raises(CustomException):
            client.delete_instance(name)
def sample_delete_instance():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

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

    # Make the request
    client.delete_instance(request=request)
    def test_list_instance_configs_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

        # Setup request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.list_instance_configs(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
    def test_get_iam_policy_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

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

        with pytest.raises(CustomException):
            client.get_iam_policy(resource)
def sample_get_instance():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

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

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

    # Handle the response
    print(response)
Example #19
0
def sample_set_iam_policy():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

    # Initialize request argument(s)
    request = iam_policy_pb2.SetIamPolicyRequest(resource="resource_value", )

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

    # Handle the response
    print(response)
Example #20
0
    def test_delete_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 = spanner_admin_instance_v1.InstanceAdminClient()

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

        with pytest.raises(CustomException):
            client.delete_instance(name)
Example #21
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 = spanner_admin_instance_v1.InstanceAdminClient()

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

        paged_list_response = client.list_instances(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Example #22
0
    def test_get_iam_policy_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 = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup request
        resource = client.instance_path("[PROJECT]", "[INSTANCE]")

        with pytest.raises(CustomException):
            client.get_iam_policy(resource)
def sample_list_instance_configs():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

    # Initialize request argument(s)
    request = spanner_admin_instance_v1.ListInstanceConfigsRequest(
        parent="parent_value", )

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

    # Handle the response
    for response in page_result:
        print(response)
    def test_get_iam_policy_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
        resource = client.instance_path('[PROJECT]', '[INSTANCE]')

        # Mock exception response
        grpc_stub.GetIamPolicy.side_effect = CustomException()

        self.assertRaises(errors.GaxError, client.get_iam_policy, resource)
    def test_delete_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
        name = client.instance_path('[PROJECT]', '[INSTANCE]')

        # Mock exception response
        grpc_stub.DeleteInstance.side_effect = CustomException()

        self.assertRaises(errors.GaxError, client.delete_instance, name)
    def test_delete_instance(self):
        channel = ChannelStub()
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

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

        client.delete_instance(name)

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.DeleteInstanceRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #27
0
    def test_test_iam_permissions_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 = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup request
        resource = "resource-341064690"
        permissions = []

        with pytest.raises(CustomException):
            client.test_iam_permissions(resource, permissions)
    def test_list_instance_configs_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]')

        # Mock exception response
        grpc_stub.ListInstanceConfigs.side_effect = CustomException()

        paged_list_response = client.list_instance_configs(parent)
        self.assertRaises(errors.GaxError, list, paged_list_response)
def sample_test_iam_permissions():
    # Create a client
    client = spanner_admin_instance_v1.InstanceAdminClient()

    # Initialize request argument(s)
    request = iam_policy_pb2.TestIamPermissionsRequest(
        resource="resource_value",
        permissions=['permissions_value_1', 'permissions_value_2'],
    )

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

    # Handle the response
    print(response)
Example #30
0
    def test_delete_instance(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = spanner_admin_instance_v1.InstanceAdminClient()

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

        client.delete_instance(name)

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.DeleteInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request