Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit eec54f3

Browse files
authored
tests: replace spurious googleapis exception w/ api_core (#636)
Closes #630. See #626 (comment)
1 parent 420591a commit eec54f3

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

samples/snippets/acl_test.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import uuid
1717

1818
import backoff
19+
from google.api_core.exceptions import GoogleAPIError
1920
from google.cloud import storage
20-
from googleapiclient.errors import HttpError
2121
import pytest
2222

2323
import storage_add_bucket_default_owner
@@ -33,10 +33,7 @@
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)
8986
def 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)
9794
def 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)
109105
def 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)
120116
def 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

133129
def 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)
141136
def 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)
154149
def 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)
163159
def test_remove_blob_owner(test_blob):
164160
test_blob.acl.user(TEST_EMAIL).grant_owner()
165161
test_blob.acl.save()

samples/snippets/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
google-cloud-pubsub==2.8.0
22
google-cloud-storage==1.42.3
3-
google-api-python-client==2.25.0

0 commit comments

Comments
 (0)