Skip to content

Commit 4db96c9

Browse files
authored
fix: remove deprecated methods in samples and tests (#1274)
* chore: remove deprecated methods in samples and tests * update method
1 parent 3d6d369 commit 4db96c9

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

docs/snippets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def storage_get_started(to_delete):
3939
bucket = client.get_bucket("bucket-id-here")
4040
# Then do other things...
4141
blob = bucket.get_blob("/remote/path/to/file.txt")
42-
assert blob.download_as_string() == b"My old contents!"
42+
assert blob.download_as_bytes() == b"My old contents!"
4343
blob.upload_from_string("New contents!")
4444
blob2 = bucket.blob("/remote/path/storage.txt")
4545
blob2.upload_from_filename(filename="/local/path.txt")

samples/snippets/encryption_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ def test_object_csek_to_cmek(test_blob):
125125
BUCKET, test_blob_name, TEST_ENCRYPTION_KEY_2, KMS_KEY
126126
)
127127

128-
assert cmek_blob.download_as_string(), test_blob_content
128+
assert cmek_blob.download_as_bytes(), test_blob_content

samples/snippets/rpo_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
def dual_region_bucket():
2828
"""Yields a dual region bucket that is deleted after the test completes."""
2929
bucket = None
30+
location = "NAM4"
3031
while bucket is None or bucket.exists():
3132
bucket_name = f"bucket-lock-{uuid.uuid4()}"
3233
bucket = storage.Client().bucket(bucket_name)
33-
bucket.location = "NAM4"
34-
bucket.create()
34+
bucket.create(location=location)
3535
yield bucket
3636
bucket.delete(force=True)
3737

samples/snippets/storage_create_bucket_turbo_replication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def create_bucket_turbo_replication(bucket_name):
3535

3636
storage_client = storage.Client()
3737
bucket = storage_client.bucket(bucket_name)
38-
bucket.location = "NAM4"
38+
bucket_location = "NAM4"
3939
bucket.rpo = RPO_ASYNC_TURBO
40-
bucket.create()
40+
bucket.create(location=bucket_location)
4141

4242
print(f"{bucket.name} created with the recovery point objective (RPO) set to {bucket.rpo} in {bucket.location}.")
4343

tests/system/test_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def test_blob_upload_download_crc32_md5_hash(
761761

762762
download_blob = shared_bucket.blob("MyBuffer")
763763

764-
assert download_blob.download_as_string() == payload
764+
assert download_blob.download_as_bytes() == payload
765765
assert download_blob.crc32c == blob.crc32c
766766
assert download_blob.md5_hash == blob.md5_hash
767767

tests/system/test_bucket.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ def test_bucket_copy_blob_w_metageneration_match(
410410
):
411411
payload = b"DEADBEEF"
412412
bucket_name = _helpers.unique_name("generation-match")
413-
created = _helpers.retry_429_503(storage_client.create_bucket)(
414-
bucket_name, requester_pays=True
415-
)
413+
bucket = storage_client.bucket(bucket_name)
414+
bucket.requester_pays = True
415+
created = _helpers.retry_429_503(storage_client.create_bucket)(bucket)
416416
buckets_to_delete.append(created)
417417
assert created.name == bucket_name
418418

0 commit comments

Comments
 (0)