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 1515import base64
1616import os
1717import tempfile
18+ import uuid
1819
20+ from google .api_core .exceptions import NotFound
1921from google .cloud import storage
2022from google .cloud .storage import Blob
2123import pytest
@@ -54,18 +56,36 @@ def test_upload_encrypted_blob():
5456 )
5557
5658
57- @pytest .fixture
59+ @pytest .fixture ( scope = "module" )
5860def 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
7191def test_download_blob (test_blob ):
You can’t perform that action at this time.
0 commit comments