Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make black happy #1

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion storages/backends/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def client(self):
if self._client is None:
if self.iam_sign_blob and not self.credentials:
self.credentials, self.project_id = auth.default(
scopes=['https://www.googleapis.com/auth/cloud-platform']
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
self._client = Client(project=self.project_id, credentials=self.credentials)
return self._client
Expand Down
34 changes: 14 additions & 20 deletions tests/test_gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,24 +511,18 @@ def test_dupe_file_chunk_size(self):

def test_iam_sign_blob_setting(self):
self.assertEqual(self.storage.iam_sign_blob, False)
with override_settings(
GS_IAM_SIGN_BLOB=True
):
with override_settings(GS_IAM_SIGN_BLOB=True):
storage = gcloud.GoogleCloudStorage()
self.assertEqual(storage.iam_sign_blob, True)

def test_sa_email_setting(self):
self.assertEqual(self.storage.sa_email, None)
with override_settings(
GS_SA_EMAIL="[email protected]"
):
with override_settings(GS_SA_EMAIL="[email protected]"):
storage = gcloud.GoogleCloudStorage()
self.assertEqual(storage.sa_email, "[email protected]")

def test_iam_sign_blob_no_service_account_email_raises_attribute_error(self):
with override_settings(
GS_IAM_SIGN_BLOB=True
):
with override_settings(GS_IAM_SIGN_BLOB=True):
storage = gcloud.GoogleCloudStorage()
storage._bucket = mock.MagicMock()
storage.credentials = mock.MagicMock()
Expand All @@ -537,16 +531,17 @@ def test_iam_sign_blob_no_service_account_email_raises_attribute_error(self):
# simulating access token
storage.credentials.token = "1234"
# no sa_email or adc service_account_email found
with self.assertRaises(AttributeError, msg=(
"Sign Blob API requires service_account_email to be available "
"through ADC or setting `sa_email`"
)):
with self.assertRaises(
AttributeError,
msg=(
"Sign Blob API requires service_account_email to be available "
"through ADC or setting `sa_email`"
),
):
storage.url(self.filename)

def test_iam_sign_blob_with_adc_service_account_email(self):
with override_settings(
GS_IAM_SIGN_BLOB=True
):
with override_settings(GS_IAM_SIGN_BLOB=True):
storage = gcloud.GoogleCloudStorage()
storage._bucket = mock.MagicMock()
storage.credentials = mock.MagicMock()
Expand All @@ -562,13 +557,12 @@ def test_iam_sign_blob_with_adc_service_account_email(self):
expiration=timedelta(seconds=86400),
version="v4",
service_account_email=storage.credentials.service_account_email,
access_token=storage.credentials.token
access_token=storage.credentials.token,
)

def test_iam_sign_blob_with_sa_email_setting(self):
with override_settings(
GS_IAM_SIGN_BLOB=True,
GS_SA_EMAIL="[email protected]"
GS_IAM_SIGN_BLOB=True, GS_SA_EMAIL="[email protected]"
):
storage = gcloud.GoogleCloudStorage()
storage._bucket = mock.MagicMock()
Expand All @@ -585,7 +579,7 @@ def test_iam_sign_blob_with_sa_email_setting(self):
expiration=timedelta(seconds=86400),
version="v4",
service_account_email=storage.sa_email,
access_token=storage.credentials.token
access_token=storage.credentials.token,
)


Expand Down