-
Notifications
You must be signed in to change notification settings - Fork 151
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
samples: add cloud client samples from python-docs-samples #626
Merged
Merged
Changes from all commits
Commits
Show all changes
201 commits
Select commit
Hold shift + click to select a range
d0e44f4
Renaming storage gcloud samples folder. (#418)
9e4c4e8
Add gcloud-based storage usage samples. (#419)
625e4da
Refactor cloud client storage samples. (#421)
677d2cf
Add more storage samples for the cloud client libraries. (#432)
667c262
Auto-update dependencies. (#456)
dpebot a9d1ebc
Fix import order lint errors
1460861
Add storage acl samples
430c4bb
Address review comments
79aa1f5
Fix lint issue
93b7b07
Auto-update dependencies. (#540)
dpebot 2a0b60a
Auto-update dependencies. (#542)
dpebot deff097
Move to google-cloud (#544)
197a0d5
Add new "quickstart" samples (#547)
jmdobry a6edaff
Quickstart tests (#569)
73df899
Add basic readme generator (#580)
2e3f667
Generate readmes for most service samples (#599)
8141e0a
Update samples to support latest Google Cloud Python (#656)
3510b2d
Edited upload/download to perform encryption properly (#667)
ryanmats 3f9071f
Storage Encryption Key Rotation Sample using Veneer + Tests (#672)
ryanmats 0f5037b
Auto-update dependencies. (#715)
dpebot 003648d
Adds storage Pub/Sub notification polling tutorial (#875)
BrandonY b17b759
Remove cloud config fixture (#887)
21f7db6
Auto-update dependencies. (#914)
dpebot fba8c2d
Re-generate all readmes
afd5ed6
Add bucket-level IAM samples (#919)
be5c929
Auto-update dependencies. (#927)
dpebot e7b7ccd
Fix README rst links (#962)
waprin 299847e
Auto-update dependencies. (#1004)
dpebot 8e71bd5
Add bucket label samples (#1045)
2dc3106
Auto-update dependencies. (#1055)
dpebot 453206e
Auto-update dependencies. (#1057)
dpebot dc7f8c7
Auto-update dependencies. (#1073)
dpebot 201867d
Auto-update dependencies. (#1093)
dpebot 5f81798
Auto-update dependencies. (#1097)
dpebot 782de87
Update all generated readme auth instructions (#1121)
4b7bc6f
Fix TypeError when running Storage notification polling exmaple. (#1135)
BrandonY 077282f
Add support for overwrite attributes (#1142)
BrandonY e4c0cda
Handle case where attribute not set (#1143)
BrandonY bb637d6
Added Link to Python Setup Guide (#1158)
b40d2fc
Auto-update dependencies. (#1138)
dpebot 9f1c1fa
storage requester pays samples (#1122)
ryanmats 42fa87b
Auto-update dependencies. (#1186)
dpebot cb0f1cd
Auto-update dependencies. (#1234)
dpebot 992b4f6
Auto-update dependencies. (#1239)
dpebot ebe578b
Added "Open in Cloud Shell" buttons to README files (#1254)
55cf1e2
Auto-update dependencies. (#1263)
dpebot 132c57a
Auto-update dependencies. (#1272)
dpebot 2dc734b
Auto-update dependencies. (#1282)
dpebot a9d3af4
Auto-update dependencies. (#1320)
dpebot e2b368c
Auto-update dependencies. (#1359)
dpebot d20daa6
Auto-update dependencies. (#1377)
dpebot 221ef4c
Auto-update dependencies. (#1389)
dpebot 0e217fb
Auto-update dependencies.
dpebot c875b4c
Regenerate the README files and fix the Open in Cloud Shell link for …
32a3dd4
Update READMEs to fix numbering and add git clone (#1464)
frankyn ac3b25f
Fix typo. (#1509)
SurferJeffAtGoogle 1884a24
Storage: add KMS samples (#1510)
broady 3e89f19
[Storage] Update kms samples (#1517)
frankyn 7f1943b
Resolved conflicts.
michaelawyu 123fbc9
Remove leftover merge conflict. (#1657)
kurtisvg 6db621b
Add region tag to upload_blob snippet (#1671)
alixhami 9dfc16e
Bucket lock samples (#1588)
billyjacobson d22155b
[Storage] Add spacing in sample code. (#1735)
frankyn f8218b9
Auto-update dependencies. (#1846)
dpebot 9abddd9
Update requirements.txt (#1944)
engelke f1c494d
Auto-update dependencies. (#1980)
dpebot 00f34a9
storage: bucket policy only samples (#1976)
frankyn 9ea1806
Add sleep to avoid bucket rate limit (#2136)
engelke 8f15a51
feat(storage): Add snippets for v4 signed URLs (#2142)
jkwlui 36df2ac
storage: add list buckets (#2149)
frankyn b752829
Drop xfail for passing test_remove_bucket_label (#2173)
jwhitlock 70ea399
Update string reported in snippet and update test
gguuss b760eb4
Update list blobs to use new client.list_blobs() method. (#2296)
frankyn 1106886
[Storage] Add comment to clarify which package version is necessary (…
frankyn bbf79fa
Storage: HMAC key samples (#2372)
tritone dea500b
Remove required argument from list buckets sample (#2394)
JesseLovelace 81690d3
Fixup sample for list_hmac_keys (#2404)
tritone d25fbb6
Bucket metadata sample (#2414)
JesseLovelace e195db7
Adds updates for samples profiler ... vision (#2439)
gguuss fd92a5d
fix: add bucket-name as required arg to v4 snippets (#2502)
jkwlui f955a69
[Storage] Support rename of BPO to UniformBucketLevelAccess (#2335)
frankyn eb1b646
Fix region tag (#2515)
frankyn 56583f9
Update documentation for prefix, delimiter search (#2537)
frankyn ed3cff2
[Storage] Split samples (#2602)
frankyn f28ca5b
Auto-update dependencies. (#2005)
dpebot a128459
samples(storage): IAM conditions samples (#2730)
jkwlui 6f1483a
fix: Use unique resources for storage snippets. (#3029)
crwilcox a6d4783
fix: Reuse HMAC key as we have a limit of 5 (#3037)
crwilcox 3e3c55a
fix: harden storage test fixtures (#3039)
crwilcox e14b9cd
storage: Fix docs for signed URL generation (#3008)
jakestambaugh a39b28f
chore(deps): update dependency google-cloud-storage to v1.26.0 (#3046)
renovate-bot ac7d9d2
feat: add remove conditional binding sample (#3107)
frankyn a49107e
Simplify noxfile setup. (#2806)
kurtisvg 806536a
[storage] feat: add post policy sample (#3231)
frankyn 886117a
Update dependency google-cloud-pubsub to v1.4.2 in Storage and Pub/Su…
busunkim96 de19d53
Remove name attribute from the input (#3569)
matarrese b2f7edd
[storage] fix: use unique blob name (#3568)
f4df95c
chore(deps): update dependency google-cloud-storage to v1.28.0 (#3260)
renovate-bot d9014d1
[storage] fix: use a different bucket for requester_pays_test (#3655)
fff3b99
docs(storage): add samples for lifer cycle and versioning (#3578)
HemangChothani 2d338b5
chore: some lint fixes (#3750)
ef9c89d
chore(deps): update dependency google-cloud-pubsub to v1.4.3 (#3725)
renovate-bot 80d2a25
docs(storage): add samples (#3687)
HemangChothani 6a65819
chore(deps): update dependency google-cloud-storage to v1.28.1 (#3785)
renovate-bot faf59e8
docs(storage): add samples for file archive generation and cors conf…
HemangChothani 1b1ef86
chore(deps): update dependency google-cloud-pubsub to v1.5.0 (#3781)
renovate-bot be94be0
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. (#4022)
kurtisvg 3e00322
[storage] testing: use multiple projects (#4048)
d927604
chore(deps): update dependency google-cloud-storage to v1.29.0 (#4040)
renovate-bot 01bf3f6
Update dependency google-cloud-pubsub to v1.6.0 (#4039)
renovate-bot 00702c3
chore(deps): update dependency google-cloud-pubsub to v1.6.1 (#4242)
renovate-bot 6bcb58d
chore(deps): update dependency pytest to v5.4.3 (#4279)
renovate-bot c7edd26
chore(deps): update dependency mock to v4 (#4287)
renovate-bot f83c9b6
chore(deps): update dependency google-cloud-pubsub to v1.7.0 (#4290)
renovate-bot a8a789a
Fix mismatched storage region tags (#4194)
5d85bc4
Update dependency google-cloud-storage to v1.30.0
renovate-bot 6f4edb3
Update dependency pytest to v6 (#4390)
renovate-bot e0d18e5
Resolved merge conflicts in requirements.txt files
engelke f6b9dcc
chore(deps): update dependency google-cloud-storage to v1.31.0 (#4564)
renovate-bot a5c72fc
chore: fix some more unmatched region tags (#4585)
948cd73
Update storage_get_metadata.py (#4615)
frankyn d2fa080
chore(deps): update dependency google-cloud-storage to v1.31.1 (#4714)
renovate-bot e1f90e7
chore(deps): update dependency google-cloud-storage to v1.31.2 (#4750)
renovate-bot 19ebef4
chore(deps): update dependency pytest to v6.1.1 (#4761)
renovate-bot 30dbe36
chore(deps): update dependency google-cloud-storage to v1.32.0 (#4871)
renovate-bot c2d76c4
chore(deps): update dependency pytest to v6.1.2 (#4921)
renovate-bot 400fccf
change pprint to print. (#4856)
shivajid 1deb741
chore(deps): update dependency google-cloud-storage to v1.33.0 (#4990)
renovate-bot 9c44c38
Add patch call (#5013)
sdspikes 147937e
fix: add a comment to draw attention to using get_blob, not blob (#5052)
crwilcox 92d9955
chore(deps): update dependency mock to v4.0.3 (#5062)
renovate-bot 3916356
fix(storage): Update comment, prefix should include delimiter (#5064)
crwilcox 5df5392
chore(deps): update dependency google-cloud-storage to v1.35.0 (#5074)
renovate-bot 56ef6f6
chore(deps): update dependency pytest to v6.2.1 (#5076)
renovate-bot 8191ef8
chore(deps): update dependency google-cloud-pubsub to v2.2.0 (#4673)
renovate-bot acadcf7
chore(Dockerfile): add Python 3.9 (#4968)
63ca127
fix(storage): list all versions (#5325)
daquinoaldo 5e3776a
docs: address sample feedback issues (#5329)
frankyn 30b4c0c
chore(deps): update dependency google-cloud-pubsub to v2.3.0 (#5347)
renovate-bot e6cf484
chore(deps): update dependency google-cloud-storage to v1.35.1 (#5321)
renovate-bot 173579b
chore(deps): update dependency google-cloud-pubsub to v2.4.0 (#5399)
renovate-bot a75684d
chore(deps): update dependency google-cloud-storage to v1.36.1 (#5353)
renovate-bot 179c9f5
chore(deps): update dependency google-cloud-storage to v1.36.2 (#5520)
renovate-bot 2283865
chore(deps): update dependency google-cloud-storage to v1.37.0 (#5580)
renovate-bot ada6fca
chore(deps): update dependency google-cloud-pubsub to v2.4.1 (#5610)
renovate-bot 510cf40
docs: update description of parameters in storage_upload_file (#5707)
BenWhitehead 3ff9770
samples(storage): update storage_set_bucket_public_iam to explicitly …
BenWhitehead 1715fa6
chore: fix typo on noxfile (#5739)
dandhlee 5eaf0e8
fix(storage): retry flaky test (#5744)
cojenco bd2f638
chore(deps): update dependency google-api-python-client to v2.3.0 (#5…
renovate-bot 37efbc8
Update storage_list_files_with_prefix.py (#5747)
frankyn 396bfe9
chore(deps): update dependency google-cloud-storage to v1.38.0 (#5640)
renovate-bot dad104c
chore(deps): update dependency pytest to v6.2.4 (#5787)
renovate-bot 618b574
chore(deps): update dependency google-cloud-pubsub to v2.4.2 (#5810)
renovate-bot 676d926
chore(deps): update dependency google-cloud-pubsub to v2.5.0 (#5845)
renovate-bot 735dfad
chore(deps): update dependency google-api-python-client to v2.4.0 (#5…
renovate-bot 8a0558a
chore(deps): update dependency google-api-python-client to v2.5.0 (#5…
renovate-bot 36da4d0
chore(deps): update dependency google-api-python-client to v2.6.0 (#5…
renovate-bot 0307fc0
chore(deps): update dependency google-api-python-client to v2.7.0 (#6…
renovate-bot 79c76c3
chore(deps): update dependency google-cloud-pubsub to v2.6.0 (#6233)
renovate-bot 4e210ca
public access prevention samples & tests (#4971)
shaffeeullah 742d0ec
chore(deps): update dependency google-api-python-client to v2.11.0 (#…
renovate-bot d925aaa
chore(deps): update dependency google-cloud-pubsub to v2.6.1 (#6284)
renovate-bot ce6c7b4
chore(deps): update dependency backoff to v1.11.0 (#6285)
renovate-bot 421cd6a
chore(deps): update dependency google-cloud-storage to v1.41.0 (#6197)
renovate-bot c6c1069
chore(deps): update dependency google-api-python-client to v2.12.0 (#…
renovate-bot 458cc61
chore(deps): update dependency google-cloud-pubsub to v2.7.0 (#6486)
renovate-bot e070c90
fix(storage): update service account email for acl tests (#6529)
cojenco 8762b13
docs(storage): update description in storage_download_file (#6553)
cojenco bd89e1d
Add storage move_blob sample and fix confusion with rename (#6554)
9f3fe3d
chore(deps): update dependency backoff to v1.11.1 (#6571)
renovate-bot ef138d6
chore(deps): update dependency google-api-python-client to v2.15.0 (#…
renovate-bot 1a01d0c
chore(deps): update dependency google-cloud-storage to v1.42.0 (#6576)
renovate-bot f546502
chore(deps): update dependency google-api-python-client to v2.17.0 (#…
renovate-bot 9d1326c
chore: Review the language fixes. (#6591)
pallabiwrites 9ffb02c
chore(deps): update dependency google-cloud-pubsub to v2.7.1 (#6598)
renovate-bot 0bd3c15
chore(deps): update dependency google-api-python-client to v2.18.0 (#…
renovate-bot 5417de9
chore(deps): update dependency google-api-python-client to v2.19.0 (#…
renovate-bot 0685d49
chore(deps): update dependency google-cloud-pubsub to v2.8.0 (#6664)
renovate-bot 40fa6dc
chore(deps): update dependency google-api-python-client to v2.19.1 (#…
renovate-bot 20a8096
chore(deps): update dependency google-cloud-storage to v1.42.1 (#6677)
renovate-bot 8303373
chore(deps): update dependency google-api-python-client to v2.20.0 (#…
renovate-bot 556555c
chore(deps): update dependency google-cloud-storage to v1.42.2 (#6700)
renovate-bot 4d6b185
chore(deps): update dependency google-api-python-client to v2.21.0 (#…
renovate-bot 2882b2a
chore(deps): update dependency google-api-python-client to v2.22.0 (#…
renovate-bot 7c13d0f
fix(storage): skip test temporarily before pap changes release (#6750)
cojenco a844fca
fix(storage): add time for bucket patch changes to propagate (#6752)
cojenco 2b2e9d9
fix(storage): add backoff to retry flaky test (#6745)
cojenco fd9d96f
chore(deps): update dependency google-api-python-client to v2.23.0 (#…
renovate-bot cbb361b
fix: update samples for pap, unspecified -> inherited (#6757)
12952ec
chore(deps): update dependency google-api-python-client to v2.24.0 (#…
renovate-bot cbe5676
fix(storage): add py-3.10 configs to noxfile config (#6903)
cojenco 12d7382
chore(deps): update dependency google-api-python-client to v2.25.0 (#…
renovate-bot 6982834
feat(storage): add retry configurations sample and test (#6900)
cojenco 121fa16
samples: add cloud client samples from python-docs-samples
cojenco 3800e64
Merge branch 'samples18' of /Users/cathyo/Dev/migration/sam-fork/pyth…
cojenco 0a5c42b
🦉 Updates from OwlBot
gcf-owl-bot[bot] f609a81
add noxfile
cojenco c447719
noxfile
cojenco ab7ec09
🦉 Updates from OwlBot
gcf-owl-bot[bot] 4f80ae0
remove invalid unused region tags
cojenco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
For requester_pays_test.py, we need to use a different Storage bucket. | ||
|
||
The test looks for an environment variable `REQUESTER_PAYS_TEST_BUCKET`. | ||
|
||
Also, the service account for the test needs to have `Billing Project | ||
Manager` role in order to make changes on buckets with requester pays | ||
enabled. | ||
|
||
We added that role to the test service account. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# Copyright 2016 Google, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import uuid | ||
|
||
import backoff | ||
from google.cloud import storage | ||
from googleapiclient.errors import HttpError | ||
import pytest | ||
|
||
import storage_add_bucket_default_owner | ||
import storage_add_bucket_owner | ||
import storage_add_file_owner | ||
import storage_print_bucket_acl | ||
import storage_print_bucket_acl_for_user | ||
import storage_print_file_acl | ||
import storage_print_file_acl_for_user | ||
import storage_remove_bucket_default_owner | ||
import storage_remove_bucket_owner | ||
import storage_remove_file_owner | ||
|
||
# Typically we'd use a @example.com address, but GCS requires a real Google | ||
# account. Retrieve a service account email with storage admin permissions. | ||
TEST_EMAIL = ( | ||
"py38-storage-test" | ||
"@python-docs-samples-tests.iam.gserviceaccount.com" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def test_bucket(): | ||
"""Yields a bucket that is deleted after the test completes.""" | ||
|
||
# The new projects have uniform bucket-level access and our tests don't | ||
# pass with those buckets. We need to use the old main project for now. | ||
original_value = os.environ['GOOGLE_CLOUD_PROJECT'] | ||
os.environ['GOOGLE_CLOUD_PROJECT'] = os.environ['MAIN_GOOGLE_CLOUD_PROJECT'] | ||
bucket = None | ||
while bucket is None or bucket.exists(): | ||
bucket_name = "acl-test-{}".format(uuid.uuid4()) | ||
bucket = storage.Client().bucket(bucket_name) | ||
bucket.create() | ||
yield bucket | ||
bucket.delete(force=True) | ||
# Set the value back. | ||
os.environ['GOOGLE_CLOUD_PROJECT'] = original_value | ||
|
||
|
||
@pytest.fixture | ||
def test_blob(test_bucket): | ||
"""Yields a blob that is deleted after the test completes.""" | ||
bucket = test_bucket | ||
blob = bucket.blob("storage_acl_test_sigil-{}".format(uuid.uuid4())) | ||
blob.upload_from_string("Hello, is it me you're looking for?") | ||
yield blob | ||
|
||
|
||
def test_print_bucket_acl(test_bucket, capsys): | ||
storage_print_bucket_acl.print_bucket_acl(test_bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert out | ||
|
||
|
||
def test_print_bucket_acl_for_user(test_bucket, capsys): | ||
test_bucket.acl.user(TEST_EMAIL).grant_owner() | ||
test_bucket.acl.save() | ||
|
||
storage_print_bucket_acl_for_user.print_bucket_acl_for_user( | ||
test_bucket.name, TEST_EMAIL | ||
) | ||
|
||
out, _ = capsys.readouterr() | ||
assert "OWNER" in out | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_add_bucket_owner(test_bucket): | ||
storage_add_bucket_owner.add_bucket_owner(test_bucket.name, TEST_EMAIL) | ||
|
||
test_bucket.acl.reload() | ||
assert "OWNER" in test_bucket.acl.user(TEST_EMAIL).get_roles() | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_remove_bucket_owner(test_bucket): | ||
test_bucket.acl.user(TEST_EMAIL).grant_owner() | ||
test_bucket.acl.save() | ||
|
||
storage_remove_bucket_owner.remove_bucket_owner( | ||
test_bucket.name, TEST_EMAIL) | ||
|
||
test_bucket.acl.reload() | ||
assert "OWNER" not in test_bucket.acl.user(TEST_EMAIL).get_roles() | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_add_bucket_default_owner(test_bucket): | ||
storage_add_bucket_default_owner.add_bucket_default_owner( | ||
test_bucket.name, TEST_EMAIL | ||
) | ||
|
||
test_bucket.default_object_acl.reload() | ||
roles = test_bucket.default_object_acl.user(TEST_EMAIL).get_roles() | ||
assert "OWNER" in roles | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_remove_bucket_default_owner(test_bucket): | ||
test_bucket.acl.user(TEST_EMAIL).grant_owner() | ||
test_bucket.acl.save() | ||
|
||
storage_remove_bucket_default_owner.remove_bucket_default_owner( | ||
test_bucket.name, TEST_EMAIL | ||
) | ||
|
||
test_bucket.default_object_acl.reload() | ||
roles = test_bucket.default_object_acl.user(TEST_EMAIL).get_roles() | ||
assert "OWNER" not in roles | ||
|
||
|
||
def test_print_blob_acl(test_blob, capsys): | ||
storage_print_file_acl.print_blob_acl( | ||
test_blob.bucket.name, test_blob.name) | ||
out, _ = capsys.readouterr() | ||
assert out | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_print_blob_acl_for_user(test_blob, capsys): | ||
test_blob.acl.user(TEST_EMAIL).grant_owner() | ||
test_blob.acl.save() | ||
|
||
storage_print_file_acl_for_user.print_blob_acl_for_user( | ||
test_blob.bucket.name, test_blob.name, TEST_EMAIL | ||
) | ||
|
||
out, _ = capsys.readouterr() | ||
assert "OWNER" in out | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_add_blob_owner(test_blob): | ||
storage_add_file_owner.add_blob_owner( | ||
test_blob.bucket.name, test_blob.name, TEST_EMAIL) | ||
|
||
test_blob.acl.reload() | ||
assert "OWNER" in test_blob.acl.user(TEST_EMAIL).get_roles() | ||
|
||
|
||
@backoff.on_exception(backoff.expo, HttpError, max_time=60) | ||
def test_remove_blob_owner(test_blob): | ||
test_blob.acl.user(TEST_EMAIL).grant_owner() | ||
test_blob.acl.save() | ||
|
||
storage_remove_file_owner.remove_blob_owner( | ||
test_blob.bucket.name, test_blob.name, TEST_EMAIL | ||
) | ||
|
||
test_blob.acl.reload() | ||
assert "OWNER" not in test_blob.acl.user(TEST_EMAIL).get_roles() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import time | ||
import uuid | ||
|
||
from google.cloud import storage | ||
import pytest | ||
|
||
import storage_disable_default_event_based_hold | ||
import storage_enable_default_event_based_hold | ||
import storage_get_default_event_based_hold | ||
import storage_get_retention_policy | ||
import storage_lock_retention_policy | ||
import storage_release_event_based_hold | ||
import storage_release_temporary_hold | ||
import storage_remove_retention_policy | ||
import storage_set_event_based_hold | ||
import storage_set_retention_policy | ||
import storage_set_temporary_hold | ||
|
||
|
||
BLOB_NAME = "storage_snippets_test_sigil" | ||
BLOB_CONTENT = "Hello, is it me you're looking for?" | ||
# Retention policy for 5 seconds | ||
RETENTION_POLICY = 5 | ||
|
||
|
||
@pytest.fixture | ||
def bucket(): | ||
"""Yields a bucket that is deleted after the test completes.""" | ||
bucket = None | ||
while bucket is None or bucket.exists(): | ||
bucket_name = "bucket-lock-{}".format(uuid.uuid4()) | ||
bucket = storage.Client().bucket(bucket_name) | ||
bucket.create() | ||
yield bucket | ||
bucket.delete(force=True) | ||
|
||
|
||
def test_retention_policy_no_lock(bucket, capsys): | ||
storage_set_retention_policy.set_retention_policy( | ||
bucket.name, RETENTION_POLICY | ||
) | ||
bucket.reload() | ||
|
||
assert bucket.retention_period is RETENTION_POLICY | ||
assert bucket.retention_policy_effective_time is not None | ||
assert bucket.retention_policy_locked is None | ||
|
||
storage_get_retention_policy.get_retention_policy(bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert "Retention Policy for {}".format(bucket.name) in out | ||
assert "Retention Period: 5" in out | ||
assert "Effective Time: " in out | ||
assert "Retention Policy is locked" not in out | ||
|
||
blob = bucket.blob(BLOB_NAME) | ||
blob.upload_from_string(BLOB_CONTENT) | ||
|
||
assert blob.retention_expiration_time is not None | ||
|
||
storage_remove_retention_policy.remove_retention_policy(bucket.name) | ||
bucket.reload() | ||
assert bucket.retention_period is None | ||
|
||
time.sleep(RETENTION_POLICY) | ||
|
||
|
||
def test_retention_policy_lock(bucket, capsys): | ||
storage_set_retention_policy.set_retention_policy( | ||
bucket.name, RETENTION_POLICY | ||
) | ||
bucket.reload() | ||
assert bucket.retention_policy_locked is None | ||
|
||
storage_lock_retention_policy.lock_retention_policy(bucket.name) | ||
bucket.reload() | ||
assert bucket.retention_policy_locked is True | ||
|
||
storage_get_retention_policy.get_retention_policy(bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert "Retention Policy is locked" in out | ||
|
||
|
||
def test_enable_disable_bucket_default_event_based_hold(bucket, capsys): | ||
storage_get_default_event_based_hold.get_default_event_based_hold( | ||
bucket.name | ||
) | ||
out, _ = capsys.readouterr() | ||
assert ( | ||
"Default event-based hold is not enabled for {}".format(bucket.name) | ||
in out | ||
) | ||
assert ( | ||
"Default event-based hold is enabled for {}".format(bucket.name) | ||
not in out | ||
) | ||
|
||
storage_enable_default_event_based_hold.enable_default_event_based_hold( | ||
bucket.name | ||
) | ||
bucket.reload() | ||
|
||
assert bucket.default_event_based_hold is True | ||
|
||
storage_get_default_event_based_hold.get_default_event_based_hold( | ||
bucket.name | ||
) | ||
out, _ = capsys.readouterr() | ||
assert ( | ||
"Default event-based hold is enabled for {}".format(bucket.name) in out | ||
) | ||
|
||
# Changes to the bucket will be readable immediately after writing, | ||
# but configuration changes may take time to propagate. | ||
time.sleep(10) | ||
|
||
blob = bucket.blob(BLOB_NAME) | ||
blob.upload_from_string(BLOB_CONTENT) | ||
assert blob.event_based_hold is True | ||
|
||
storage_release_event_based_hold.release_event_based_hold( | ||
bucket.name, blob.name | ||
) | ||
blob.reload() | ||
assert blob.event_based_hold is False | ||
|
||
storage_disable_default_event_based_hold.disable_default_event_based_hold( | ||
bucket.name | ||
) | ||
bucket.reload() | ||
assert bucket.default_event_based_hold is False | ||
|
||
|
||
def test_enable_disable_temporary_hold(bucket): | ||
blob = bucket.blob(BLOB_NAME) | ||
blob.upload_from_string(BLOB_CONTENT) | ||
assert blob.temporary_hold is None | ||
|
||
storage_set_temporary_hold.set_temporary_hold(bucket.name, blob.name) | ||
blob.reload() | ||
assert blob.temporary_hold is True | ||
|
||
storage_release_temporary_hold.release_temporary_hold( | ||
bucket.name, blob.name | ||
) | ||
blob.reload() | ||
assert blob.temporary_hold is False | ||
|
||
|
||
def test_enable_disable_event_based_hold(bucket): | ||
blob = bucket.blob(BLOB_NAME) | ||
blob.upload_from_string(BLOB_CONTENT) | ||
assert blob.event_based_hold is None | ||
|
||
storage_set_event_based_hold.set_event_based_hold(bucket.name, blob.name) | ||
blob.reload() | ||
assert blob.event_based_hold is True | ||
|
||
storage_release_event_based_hold.release_event_based_hold( | ||
bucket.name, blob.name | ||
) | ||
blob.reload() | ||
assert blob.event_based_hold is False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a fossil from samples that used
googleapiclient
. I'm pretty sure that doing backoff / retries around this error is pointless -- nothing else ingoogle-cloud-storage
ever raises it (or imports / depends ongoogleapiclient
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct error class is probably
google.api_core.exceptions.GoogleAPIError
.