def test_update_table_cmek(client, to_delete):
    """Patch a table's metadata."""
    dataset_id = "update_table_cmek_{}".format(_millis())
    table_id = "update_table_cmek_{}".format(_millis())
    dataset = bigquery.Dataset(client.dataset(dataset_id))
    client.create_dataset(dataset)
    to_delete.append(dataset)

    table = bigquery.Table(dataset.table(table_id))
    original_kms_key_name = "projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}".format(
        "cloud-samples-tests", "us-central1", "test", "test"
    )
    table.encryption_configuration = bigquery.EncryptionConfiguration(
        kms_key_name=original_kms_key_name
    )
    table = client.create_table(table)

    # [START bigquery_update_table_cmek]
    # from google.cloud import bigquery
    # client = bigquery.Client()

    assert table.encryption_configuration.kms_key_name == original_kms_key_name

    # Set a new encryption key to use for the destination.
    # TODO: Replace this key with a key you have created in KMS.
    updated_kms_key_name = (
        "projects/cloud-samples-tests/locations/us-central1/"
        "keyRings/test/cryptoKeys/otherkey"
    )
    table.encryption_configuration = bigquery.EncryptionConfiguration(
        kms_key_name=updated_kms_key_name
    )

    table = client.update_table(table, ["encryption_configuration"])  # API request

    assert table.encryption_configuration.kms_key_name == updated_kms_key_name
    assert original_kms_key_name != updated_kms_key_name
def test_update_table_cmek ( client , to_delete ) : dataset_id = "update_table_cmek_{}" . format ( _millis ( ) ) table_id = "update_table_cmek_{}" . format ( _millis ( ) ) dataset = bigquery . Dataset ( client . dataset ( dataset_id ) ) client . create_dataset ( dataset ) to_delete . append ( dataset ) table = bigquery . Table ( dataset . table ( table_id ) ) original_kms_key_name = "projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}" . format ( "cloud-samples-tests" , "us-central1" , "test" , "test" ) table . encryption_configuration = bigquery . EncryptionConfiguration ( kms_key_name = original_kms_key_name ) table = client . create_table ( table ) assert table . encryption_configuration . kms_key_name == original_kms_key_name updated_kms_key_name = ( "projects/cloud-samples-tests/locations/us-central1/" "keyRings/test/cryptoKeys/otherkey" ) table . encryption_configuration = bigquery . EncryptionConfiguration ( kms_key_name = updated_kms_key_name ) table = client . update_table ( table , [ "encryption_configuration" ] ) assert table . encryption_configuration . kms_key_name == updated_kms_key_name assert original_kms_key_name != updated_kms_key_name
Patch a table's metadata.