示例#1
0
    def test_update(self):
        from gcloud._testing import _Monkey
        from gcloud.bigtable._generated import (
            bigtable_cluster_data_pb2 as data_pb2)
        from gcloud.bigtable._generated import operations_pb2
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable import cluster as MUT

        project = 'PROJECT'
        zone = 'zone'
        cluster_id = 'cluster-id'
        serve_nodes = 81
        display_name = 'display_name'
        timeout_seconds = 9

        client = _Client(project, timeout_seconds=timeout_seconds)
        cluster = self._makeOne(zone, cluster_id, client,
                                display_name=display_name,
                                serve_nodes=serve_nodes)

        # Create request_pb
        cluster_name = ('projects/' + project + '/zones/' + zone +
                        '/clusters/' + cluster_id)
        request_pb = data_pb2.Cluster(
            name=cluster_name,
            display_name=display_name,
            serve_nodes=serve_nodes,
        )

        # Create response_pb
        current_op = operations_pb2.Operation()
        response_pb = data_pb2.Cluster(current_operation=current_op)

        # Patch the stub used by the API method.
        client._cluster_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        op_id = 5678
        op_begin = object()
        expected_result = MUT.Operation('update', op_id, op_begin,
                                        cluster=cluster)

        # Create mocks
        process_operation_called = []

        def mock_process_operation(operation_pb):
            process_operation_called.append(operation_pb)
            return op_id, op_begin

        # Perform the method and check the result.
        with _Monkey(MUT, _process_operation=mock_process_operation):
            result = cluster.update()

        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'UpdateCluster',
            (request_pb, timeout_seconds),
            {},
        )])
        self.assertEqual(process_operation_called, [current_op])
示例#2
0
    def test_create(self):
        from google.longrunning import operations_pb2
        from gcloud._testing import _Monkey
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable import cluster as MUT

        client = _Client(self.PROJECT, timeout_seconds=self.TIMEOUT_SECONDS)
        instance = _Instance(self.INSTANCE_ID, client)
        cluster = self._makeOne(self.CLUSTER_ID, instance)

        # Create request_pb. Just a mock since we monkey patch
        # _prepare_create_request
        request_pb = object()

        # Create response_pb
        OP_ID = 5678
        OP_NAME = (
            'operations/projects/%s/instances/%s/clusters/%s/operations/%d' %
            (self.PROJECT, self.INSTANCE_ID, self.CLUSTER_ID, OP_ID))
        response_pb = operations_pb2.Operation(name=OP_NAME)

        # Patch the stub used by the API method.
        client._instance_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        expected_result = MUT.Operation('create', OP_ID, cluster=cluster)

        # Create the mocks.
        prep_create_called = []

        def mock_prep_create_req(cluster):
            prep_create_called.append(cluster)
            return request_pb

        process_operation_called = []

        def mock_process_operation(operation_pb):
            process_operation_called.append(operation_pb)
            return OP_ID

        # Perform the method and check the result.
        with _Monkey(MUT,
                     _prepare_create_request=mock_prep_create_req,
                     _process_operation=mock_process_operation):
            result = cluster.create()

        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'CreateCluster',
            (request_pb, self.TIMEOUT_SECONDS),
            {},
        )])
        self.assertEqual(prep_create_called, [cluster])
        self.assertEqual(process_operation_called, [response_pb])
示例#3
0
    def test_undelete(self):
        from google.longrunning import operations_pb2
        from gcloud._testing import _Monkey
        from gcloud.bigtable._generated import (
            bigtable_cluster_service_messages_pb2 as messages_pb2)
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable import cluster as MUT

        project = 'PROJECT'
        zone = 'zone'
        cluster_id = 'cluster-id'
        timeout_seconds = 78

        client = _Client(project, timeout_seconds=timeout_seconds)
        cluster = self._makeOne(zone, cluster_id, client)

        # Create request_pb
        cluster_name = ('projects/' + project + '/zones/' + zone +
                        '/clusters/' + cluster_id)
        request_pb = messages_pb2.UndeleteClusterRequest(name=cluster_name)

        # Create response_pb
        response_pb = operations_pb2.Operation()

        # Patch the stub used by the API method.
        client._cluster_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        op_id = 5678
        op_begin = object()
        expected_result = MUT.Operation('undelete',
                                        op_id,
                                        op_begin,
                                        cluster=cluster)

        # Create the mocks.
        process_operation_called = []

        def mock_process_operation(operation_pb):
            process_operation_called.append(operation_pb)
            return op_id, op_begin

        # Perform the method and check the result.
        with _Monkey(MUT, _process_operation=mock_process_operation):
            result = cluster.undelete()

        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'UndeleteCluster',
            (request_pb, timeout_seconds),
            {},
        )])
        self.assertEqual(process_operation_called, [response_pb])
示例#4
0
    def test_update(self):
        from google.longrunning import operations_pb2
        from gcloud._testing import _Monkey
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable import cluster as MUT

        SERVE_NODES = 81

        client = _Client(self.PROJECT, timeout_seconds=self.TIMEOUT_SECONDS)
        instance = _Instance(self.INSTANCE_ID, client)
        cluster = self._makeOne(self.CLUSTER_ID,
                                instance,
                                serve_nodes=SERVE_NODES)

        # Create request_pb
        request_pb = _ClusterPB(
            name=self.CLUSTER_NAME,
            serve_nodes=SERVE_NODES,
        )

        # Create response_pb
        response_pb = operations_pb2.Operation()

        # Patch the stub used by the API method.
        client._instance_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        OP_ID = 5678
        expected_result = MUT.Operation('update', OP_ID, cluster=cluster)

        # Create mocks
        process_operation_called = []

        def mock_process_operation(operation_pb):
            process_operation_called.append(operation_pb)
            return OP_ID

        # Perform the method and check the result.
        with _Monkey(MUT, _process_operation=mock_process_operation):
            result = cluster.update()

        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'UpdateCluster',
            (request_pb, self.TIMEOUT_SECONDS),
            {},
        )])
        self.assertEqual(process_operation_called, [response_pb])
示例#5
0
    def test_create(self):
        from google.longrunning import operations_pb2
        from gcloud._testing import _Monkey
        from gcloud.bigtable._generated import (bigtable_cluster_data_pb2 as
                                                data_pb2)
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable import cluster as MUT

        project = 'PROJECT'
        zone = 'zone'
        cluster_id = 'cluster-id'
        timeout_seconds = 578

        client = _Client(project, timeout_seconds=timeout_seconds)
        cluster = self._makeOne(zone, cluster_id, client)

        # Create request_pb. Just a mock since we monkey patch
        # _prepare_create_request
        request_pb = object()

        # Create response_pb
        op_id = 5678
        op_begin = object()
        op_name = ('operations/projects/%s/zones/%s/clusters/%s/'
                   'operations/%d' % (project, zone, cluster_id, op_id))
        current_op = operations_pb2.Operation(name=op_name)
        response_pb = data_pb2.Cluster(current_operation=current_op)

        # Patch the stub used by the API method.
        client._cluster_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        expected_result = MUT.Operation('create',
                                        op_id,
                                        op_begin,
                                        cluster=cluster)

        # Create the mocks.
        prep_create_called = []

        def mock_prep_create_req(cluster):
            prep_create_called.append(cluster)
            return request_pb

        process_operation_called = []

        def mock_process_operation(operation_pb):
            process_operation_called.append(operation_pb)
            return op_id, op_begin

        # Perform the method and check the result.
        with _Monkey(MUT,
                     _prepare_create_request=mock_prep_create_req,
                     _process_operation=mock_process_operation):
            result = cluster.create()

        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'CreateCluster',
            (request_pb, timeout_seconds),
            {},
        )])
        self.assertEqual(prep_create_called, [cluster])
        self.assertEqual(process_operation_called, [current_op])