File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 15
15
import base64
16
16
import os
17
17
import tempfile
18
+ import uuid
18
19
20
+ from google .api_core .exceptions import NotFound
19
21
from google .cloud import storage
20
22
from google .cloud .storage import Blob
21
23
import pytest
@@ -54,18 +56,36 @@ def test_upload_encrypted_blob():
54
56
)
55
57
56
58
57
- @pytest .fixture
59
+ @pytest .fixture ( scope = "module" )
58
60
def test_blob ():
59
61
"""Provides a pre-existing blob in the test bucket."""
60
62
bucket = storage .Client ().bucket (BUCKET )
63
+ blob_name = "test_blob_{}" .format (uuid .uuid4 ().hex )
61
64
blob = Blob (
62
- "encryption_test_sigil" ,
65
+ blob_name ,
63
66
bucket ,
64
67
encryption_key = TEST_ENCRYPTION_KEY_DECODED ,
65
68
)
66
69
content = "Hello, is it me you're looking for?"
67
70
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 ()
69
89
70
90
71
91
def test_download_blob (test_blob ):
You can’t perform that action at this time.
0 commit comments