From 1436382131c489253cac4245749596965c589adc Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Tue, 14 May 2024 16:26:09 -0700 Subject: [PATCH 1/2] chore: remove deprecated methods in samples and tests --- docs/snippets.py | 2 +- samples/snippets/encryption_test.py | 2 +- samples/snippets/rpo_test.py | 7 ++++--- .../snippets/storage_create_bucket_turbo_replication.py | 4 ++-- tests/system/test_blob.py | 2 +- tests/system/test_bucket.py | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/snippets.py b/docs/snippets.py index 93884900f..631dca468 100644 --- a/docs/snippets.py +++ b/docs/snippets.py @@ -39,7 +39,7 @@ def storage_get_started(to_delete): bucket = client.get_bucket("bucket-id-here") # Then do other things... blob = bucket.get_blob("/remote/path/to/file.txt") - assert blob.download_as_string() == b"My old contents!" + assert blob.download_as_bytes() == b"My old contents!" blob.upload_from_string("New contents!") blob2 = bucket.blob("/remote/path/storage.txt") blob2.upload_from_filename(filename="/local/path.txt") diff --git a/samples/snippets/encryption_test.py b/samples/snippets/encryption_test.py index ff7a568e0..9039b1fad 100644 --- a/samples/snippets/encryption_test.py +++ b/samples/snippets/encryption_test.py @@ -125,4 +125,4 @@ def test_object_csek_to_cmek(test_blob): BUCKET, test_blob_name, TEST_ENCRYPTION_KEY_2, KMS_KEY ) - assert cmek_blob.download_as_string(), test_blob_content + assert cmek_blob.download_as_bytes(), test_blob_content diff --git a/samples/snippets/rpo_test.py b/samples/snippets/rpo_test.py index befc0334a..d57fbd9d4 100644 --- a/samples/snippets/rpo_test.py +++ b/samples/snippets/rpo_test.py @@ -26,12 +26,13 @@ @pytest.fixture def dual_region_bucket(): """Yields a dual region bucket that is deleted after the test completes.""" + storage_client = storage.Client() bucket = None + location = "NAM4" while bucket is None or bucket.exists(): bucket_name = f"bucket-lock-{uuid.uuid4()}" - bucket = storage.Client().bucket(bucket_name) - bucket.location = "NAM4" - bucket.create() + bucket = storage_client.bucket(bucket_name) + storage_client.create_bucket(bucket, location=location) yield bucket bucket.delete(force=True) diff --git a/samples/snippets/storage_create_bucket_turbo_replication.py b/samples/snippets/storage_create_bucket_turbo_replication.py index 3d26616ec..efb772c86 100644 --- a/samples/snippets/storage_create_bucket_turbo_replication.py +++ b/samples/snippets/storage_create_bucket_turbo_replication.py @@ -35,9 +35,9 @@ def create_bucket_turbo_replication(bucket_name): storage_client = storage.Client() bucket = storage_client.bucket(bucket_name) - bucket.location = "NAM4" + bucket_location = "NAM4" bucket.rpo = RPO_ASYNC_TURBO - bucket.create() + storage_client.create_bucket(bucket, location=bucket_location) print(f"{bucket.name} created with the recovery point objective (RPO) set to {bucket.rpo} in {bucket.location}.") diff --git a/tests/system/test_blob.py b/tests/system/test_blob.py index a35c047b1..6069725ce 100644 --- a/tests/system/test_blob.py +++ b/tests/system/test_blob.py @@ -761,7 +761,7 @@ def test_blob_upload_download_crc32_md5_hash( download_blob = shared_bucket.blob("MyBuffer") - assert download_blob.download_as_string() == payload + assert download_blob.download_as_bytes() == payload assert download_blob.crc32c == blob.crc32c assert download_blob.md5_hash == blob.md5_hash diff --git a/tests/system/test_bucket.py b/tests/system/test_bucket.py index 9b2fcd614..735570f6c 100644 --- a/tests/system/test_bucket.py +++ b/tests/system/test_bucket.py @@ -410,9 +410,9 @@ def test_bucket_copy_blob_w_metageneration_match( ): payload = b"DEADBEEF" bucket_name = _helpers.unique_name("generation-match") - created = _helpers.retry_429_503(storage_client.create_bucket)( - bucket_name, requester_pays=True - ) + bucket = storage_client.bucket(bucket_name) + bucket.requester_pays = True + created = _helpers.retry_429_503(storage_client.create_bucket)(bucket) buckets_to_delete.append(created) assert created.name == bucket_name From f236d0c4c9b09cac32762580a1d3ab7072903a53 Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Wed, 15 May 2024 10:50:11 -0700 Subject: [PATCH 2/2] update method --- samples/snippets/rpo_test.py | 5 ++--- samples/snippets/storage_create_bucket_turbo_replication.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/snippets/rpo_test.py b/samples/snippets/rpo_test.py index d57fbd9d4..0dcf15746 100644 --- a/samples/snippets/rpo_test.py +++ b/samples/snippets/rpo_test.py @@ -26,13 +26,12 @@ @pytest.fixture def dual_region_bucket(): """Yields a dual region bucket that is deleted after the test completes.""" - storage_client = storage.Client() bucket = None location = "NAM4" while bucket is None or bucket.exists(): bucket_name = f"bucket-lock-{uuid.uuid4()}" - bucket = storage_client.bucket(bucket_name) - storage_client.create_bucket(bucket, location=location) + bucket = storage.Client().bucket(bucket_name) + bucket.create(location=location) yield bucket bucket.delete(force=True) diff --git a/samples/snippets/storage_create_bucket_turbo_replication.py b/samples/snippets/storage_create_bucket_turbo_replication.py index efb772c86..bc0559795 100644 --- a/samples/snippets/storage_create_bucket_turbo_replication.py +++ b/samples/snippets/storage_create_bucket_turbo_replication.py @@ -37,7 +37,7 @@ def create_bucket_turbo_replication(bucket_name): bucket = storage_client.bucket(bucket_name) bucket_location = "NAM4" bucket.rpo = RPO_ASYNC_TURBO - storage_client.create_bucket(bucket, location=bucket_location) + bucket.create(location=bucket_location) print(f"{bucket.name} created with the recovery point objective (RPO) set to {bucket.rpo} in {bucket.location}.")