Skip to content

Commit 06a40e8

Browse files
author
Takashi Matsuo
authored
[storage] fix: use unique blob name (GoogleCloudPlatform#3568)
* [storage] fix: use unique blob name fixes GoogleCloudPlatform#3567 * add some comments
1 parent a788087 commit 06a40e8

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

storage/cloud-client/encryption_test.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import base64
1616
import os
1717
import tempfile
18+
import uuid
1819

20+
from google.api_core.exceptions import NotFound
1921
from google.cloud import storage
2022
from google.cloud.storage import Blob
2123
import pytest
@@ -54,18 +56,36 @@ def test_upload_encrypted_blob():
5456
)
5557

5658

57-
@pytest.fixture
59+
@pytest.fixture(scope="module")
5860
def test_blob():
5961
"""Provides a pre-existing blob in the test bucket."""
6062
bucket = storage.Client().bucket(BUCKET)
63+
blob_name = "test_blob_{}".format(uuid.uuid4().hex)
6164
blob = Blob(
62-
"encryption_test_sigil",
65+
blob_name,
6366
bucket,
6467
encryption_key=TEST_ENCRYPTION_KEY_DECODED,
6568
)
6669
content = "Hello, is it me you're looking for?"
6770
blob.upload_from_string(content)
68-
return blob.name, content
71+
72+
yield blob.name, content
73+
74+
# To delete an encrypted blob, you have to provide the same key
75+
# used for the blob. When you provide a wrong key, you'll get
76+
# NotFound.
77+
try:
78+
# Clean up for the case that the rotation didn't occur.
79+
blob.delete()
80+
except NotFound as e:
81+
# For the case that the rotation succeeded.
82+
print("Ignoring 404, detail: {}".format(e))
83+
blob = Blob(
84+
blob_name,
85+
bucket,
86+
encryption_key=TEST_ENCRYPTION_KEY_2_DECODED
87+
)
88+
blob.delete()
6989

7090

7191
def test_download_blob(test_blob):

0 commit comments

Comments
 (0)