def test_modify_column_families(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        expected_response = {"name": name_2}
        expected_response = table_pb2.Table(**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 = bigtable_admin_v2.BigtableTableAdminClient()

        # Setup Request
        name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]")
        modifications = []

        response = client.modify_column_families(name, modifications)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_table_admin_pb2.ModifyColumnFamiliesRequest(
            name=name, modifications=modifications)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def _update_test_helper(self, gc_rule=None):
        from tests.unit._testing import _FakeStub
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_table_admin_pb2 as table_admin_v2_pb2,
        )
        from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client

        project_id = "project-id"
        zone = "zone"
        cluster_id = "cluster-id"
        table_id = "table-id"
        column_family_id = "column-family-id"
        table_name = (
            "projects/"
            + project_id
            + "/zones/"
            + zone
            + "/clusters/"
            + cluster_id
            + "/tables/"
            + table_id
        )

        api = bigtable_table_admin_client.BigtableTableAdminClient(mock.Mock())
        credentials = _make_credentials()
        client = self._make_client(
            project=project_id, credentials=credentials, admin=True
        )
        table = _Table(table_name, client=client)
        column_family = self._make_one(column_family_id, table, gc_rule=gc_rule)

        # Create request_pb
        if gc_rule is None:
            column_family_pb = _ColumnFamilyPB()
        else:
            column_family_pb = _ColumnFamilyPB(gc_rule=gc_rule.to_pb())
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(name=table_name)
        request_pb.modifications.add(id=column_family_id, update=column_family_pb)

        # Create response_pb
        response_pb = _ColumnFamilyPB()

        # Patch the stub used by the API method.
        stub = _FakeStub(response_pb)
        client._table_admin_client = api
        client._table_admin_client.transport.update = stub

        # Create expected_result.
        expected_result = None  # update() has no return value.

        # Perform the method and check the result.
        self.assertEqual(stub.results, (response_pb,))
        result = column_family.update()
        self.assertEqual(result, expected_result)
Example #3
0
    def _update_test_helper(self, gc_rule=None):
        from tests.unit._testing import _FakeStub
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_table_admin_pb2 as table_admin_v2_pb2)

        project_id = 'project-id'
        zone = 'zone'
        cluster_id = 'cluster-id'
        table_id = 'table-id'
        column_family_id = 'column-family-id'
        table_name = ('projects/' + project_id + '/zones/' + zone +
                      '/clusters/' + cluster_id + '/tables/' + table_id)

        channel = _make_channel()
        client = self._make_client(project=project_id,
                                   channel=channel,
                                   admin=True)
        table = _Table(table_name, client=client)
        column_family = self._make_one(column_family_id,
                                       table,
                                       gc_rule=gc_rule)

        # Create request_pb
        if gc_rule is None:
            column_family_pb = _ColumnFamilyPB()
        else:
            column_family_pb = _ColumnFamilyPB(gc_rule=gc_rule.to_pb())
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
            name=table_name)
        request_pb.modifications.add(
            id=column_family_id,
            update=column_family_pb,
        )

        # Create response_pb
        response_pb = _ColumnFamilyPB()

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

        # Create expected_result.
        expected_result = None  # update() has no return value.

        # Perform the method and check the result.
        self.assertEqual(stub.results, (response_pb, ))
        result = column_family.update()
        self.assertEqual(result, expected_result)
Example #4
0
    def test_delete(self):
        from google.protobuf import empty_pb2
        from google.cloud.bigtable_admin_v2.proto import (
            bigtable_table_admin_pb2 as table_admin_v2_pb2)
        from tests.unit._testing import _FakeStub
        from google.cloud.bigtable_admin_v2.gapic import (
            bigtable_table_admin_client)

        project_id = 'project-id'
        zone = 'zone'
        cluster_id = 'cluster-id'
        table_id = 'table-id'
        column_family_id = 'column-family-id'
        table_name = ('projects/' + project_id + '/zones/' + zone +
                      '/clusters/' + cluster_id + '/tables/' + table_id)

        api = bigtable_table_admin_client.BigtableTableAdminClient(mock.Mock())
        credentials = _make_credentials()
        client = self._make_client(project=project_id,
                                   credentials=credentials, admin=True)
        table = _Table(table_name, client=client)
        column_family = self._make_one(column_family_id, table)

        # Create request_pb
        request_pb = table_admin_v2_pb2.ModifyColumnFamiliesRequest(
            name=table_name)
        request_pb.modifications.add(
            id=column_family_id,
            drop=True)

        # Create response_pb
        response_pb = empty_pb2.Empty()

        # Patch the stub used by the API method.
        stub = _FakeStub(response_pb)
        client._table_admin_client = api
        client._table_admin_client.transport.delete = stub

        # Create expected_result.
        expected_result = None  # delete() has no return value.

        # Perform the method and check the result.
        self.assertEqual(stub.results, (response_pb,))
        result = column_family.delete()
        self.assertEqual(result, expected_result)
    def test_modify_column_families(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        expected_response = {'name': name_2}
        expected_response = table_pb2.Table(**expected_response)

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

        # Setup Request
        name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
        modifications = []

        response = client.modify_column_families(name, modifications)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_table_admin_pb2.ModifyColumnFamiliesRequest(
            name=name, modifications=modifications)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request