1616import uuid
1717
1818import backoff
19+ from google .api_core .exceptions import GoogleAPIError
1920from google .cloud import storage
20- from googleapiclient .errors import HttpError
2121import pytest
2222
2323import storage_add_bucket_default_owner
3333
3434# Typically we'd use a @example.com address, but GCS requires a real Google
3535# account. Retrieve a service account email with storage admin permissions.
36- TEST_EMAIL = (
37- "py38-storage-test"
38- "@python-docs-samples-tests.iam.gserviceaccount.com"
39- )
36+ TEST_EMAIL = "py38-storage-test" "@python-docs-samples-tests.iam.gserviceaccount.com"
4037
4138
4239@pytest .fixture (scope = "module" )
@@ -45,8 +42,8 @@ def test_bucket():
4542
4643 # The new projects have uniform bucket-level access and our tests don't
4744 # pass with those buckets. We need to use the old main project for now.
48- original_value = os .environ [' GOOGLE_CLOUD_PROJECT' ]
49- os .environ [' GOOGLE_CLOUD_PROJECT' ] = os .environ [' MAIN_GOOGLE_CLOUD_PROJECT' ]
45+ original_value = os .environ [" GOOGLE_CLOUD_PROJECT" ]
46+ os .environ [" GOOGLE_CLOUD_PROJECT" ] = os .environ [" MAIN_GOOGLE_CLOUD_PROJECT" ]
5047 bucket = None
5148 while bucket is None or bucket .exists ():
5249 bucket_name = "acl-test-{}" .format (uuid .uuid4 ())
@@ -55,7 +52,7 @@ def test_bucket():
5552 yield bucket
5653 bucket .delete (force = True )
5754 # Set the value back.
58- os .environ [' GOOGLE_CLOUD_PROJECT' ] = original_value
55+ os .environ [" GOOGLE_CLOUD_PROJECT" ] = original_value
5956
6057
6158@pytest .fixture
@@ -85,27 +82,26 @@ def test_print_bucket_acl_for_user(test_bucket, capsys):
8582 assert "OWNER" in out
8683
8784
88- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
85+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
8986def test_add_bucket_owner (test_bucket ):
9087 storage_add_bucket_owner .add_bucket_owner (test_bucket .name , TEST_EMAIL )
9188
9289 test_bucket .acl .reload ()
9390 assert "OWNER" in test_bucket .acl .user (TEST_EMAIL ).get_roles ()
9491
9592
96- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
93+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
9794def test_remove_bucket_owner (test_bucket ):
9895 test_bucket .acl .user (TEST_EMAIL ).grant_owner ()
9996 test_bucket .acl .save ()
10097
101- storage_remove_bucket_owner .remove_bucket_owner (
102- test_bucket .name , TEST_EMAIL )
98+ storage_remove_bucket_owner .remove_bucket_owner (test_bucket .name , TEST_EMAIL )
10399
104100 test_bucket .acl .reload ()
105101 assert "OWNER" not in test_bucket .acl .user (TEST_EMAIL ).get_roles ()
106102
107103
108- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
104+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
109105def test_add_bucket_default_owner (test_bucket ):
110106 storage_add_bucket_default_owner .add_bucket_default_owner (
111107 test_bucket .name , TEST_EMAIL
@@ -116,7 +112,7 @@ def test_add_bucket_default_owner(test_bucket):
116112 assert "OWNER" in roles
117113
118114
119- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
115+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
120116def test_remove_bucket_default_owner (test_bucket ):
121117 test_bucket .acl .user (TEST_EMAIL ).grant_owner ()
122118 test_bucket .acl .save ()
@@ -131,13 +127,12 @@ def test_remove_bucket_default_owner(test_bucket):
131127
132128
133129def test_print_blob_acl (test_blob , capsys ):
134- storage_print_file_acl .print_blob_acl (
135- test_blob .bucket .name , test_blob .name )
130+ storage_print_file_acl .print_blob_acl (test_blob .bucket .name , test_blob .name )
136131 out , _ = capsys .readouterr ()
137132 assert out
138133
139134
140- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
135+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
141136def test_print_blob_acl_for_user (test_blob , capsys ):
142137 test_blob .acl .user (TEST_EMAIL ).grant_owner ()
143138 test_blob .acl .save ()
@@ -150,16 +145,17 @@ def test_print_blob_acl_for_user(test_blob, capsys):
150145 assert "OWNER" in out
151146
152147
153- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
148+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
154149def test_add_blob_owner (test_blob ):
155150 storage_add_file_owner .add_blob_owner (
156- test_blob .bucket .name , test_blob .name , TEST_EMAIL )
151+ test_blob .bucket .name , test_blob .name , TEST_EMAIL
152+ )
157153
158154 test_blob .acl .reload ()
159155 assert "OWNER" in test_blob .acl .user (TEST_EMAIL ).get_roles ()
160156
161157
162- @backoff .on_exception (backoff .expo , HttpError , max_time = 60 )
158+ @backoff .on_exception (backoff .expo , GoogleAPIError , max_time = 60 )
163159def test_remove_blob_owner (test_blob ):
164160 test_blob .acl .user (TEST_EMAIL ).grant_owner ()
165161 test_blob .acl .save ()
0 commit comments