Skip to content

docs(storage): add samples #3687

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

Merged
merged 13 commits into from
May 15, 2020

Conversation

HemangChothani
Copy link
Contributor

Add samples:

  1. storage_bucket_delete_default_kms_key

  2. storage_compose_file

  3. storage_create_bucket_class_location

  4. storage_define_bucket_website_configuration

  5. storage_download_public_file

  6. storage_get_service_account

  7. storage_object_csek_to_cmek

  8. storage_object_get_kms_key

  9. storage_set_bucket_public_iam

@HemangChothani HemangChothani requested review from crwilcox and a team as code owners May 5, 2020 05:40
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 5, 2020

def test_create_bucket_class_location():
bucket = storage_create_bucket_class_location.create_bucket_class_location(
"storage-snippets-test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a UUID for bucket names to ensure they don't conflict when running multiple times


assert bucket.location == 'US'
assert bucket.storage_class == "COLDLINE"
bucket.delete(force=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a fixture to delete these bucket, so it's always done even if the test fails or encounters another error. You can use a generator to return a UUID above clean up after the bucket it created.

)

out, _ = capsys.readouterr()
assert test_bucket.default_kms_key_name is None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like this tests anything

Suggested change
assert test_bucket.default_kms_key_name is None

test_blob.bucket.name, test_blob.name, dest_file.name
)

assert dest_file.read()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually verify this sample works? Won't this just ready an empty file if not?

The preferred pattern for samples is Arrange, Act, Assert:

  1. Arrange - prepare the request
  2. Act - send request, and receive response
  3. Assert - Print response (to show the user how to interact with it) and assert the response occurred when the sample was run

It's an explict non-goal for our samples tests to test the service or product. Instead they should be that the sample ran successfully, and should verify the output of the sample in a reasonable way. Thus, most sample tests should be in the pattern:

  1. Run the sample
  2. Check the output of the sample

Comment on lines 337 to 338
bucket = storage_define_bucket_website_configuration.\
define_bucket_website_configuration(test_bucket.name, "index.html", "404.html")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can also use black to auto format these files

Suggested change
bucket = storage_define_bucket_website_configuration.\
define_bucket_website_configuration(test_bucket.name, "index.html", "404.html")
bucket = storage_define_bucket_website_configuration.define_bucket_website_configuration(
test_bucket.name, "index.html", "404.html")

@@ -0,0 +1,47 @@
#!/usr/bin/env python

# Copyright 2020 Google Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2020 Google Inc. All Rights Reserved.
# Copyright 2020 Google LLC. All Rights Reserved.

Please adjust everywhere.

@HemangChothani
Copy link
Contributor Author

@frankyn Could you please review this PR, I am unable to add you as a reviewer.

@frankyn frankyn requested a review from JesseLovelace May 11, 2020 16:39
@frankyn
Copy link
Contributor

frankyn commented May 11, 2020

@JesseLovelace is on point for these reviews. Assigning it to them!

@busunkim96 busunkim96 added automerge Merge the pull request once unit tests and other checks pass. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels May 14, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@busunkim96 busunkim96 added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed automerge Merge the pull request once unit tests and other checks pass. labels May 14, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@frankyn frankyn added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 14, 2020
@busunkim96
Copy link
Contributor

@HemangChothani Could you investigate the failing test? Do we need to add a new resource to the project?

================================== FAILURES ===================================
___________________________ test_object_csek_to_cmek ___________________________
Traceback (most recent call last):
  File "/tmpfs/src/github/python-docs-samples/storage/cloud-client/encryption_test.py", line 122, in test_object_csek_to_cmek
    BUCKET, test_blob_name, TEST_ENCRYPTION_KEY, KMS_KEY
  File "/tmpfs/src/github/python-docs-samples/storage/cloud-client/storage_object_csek_to_cmek.py", line 40, in object_csek_to_cmek
    token, rewritten, total = dest.rewrite(source_blob)
  File "/tmpfs/src/github/python-docs-samples/storage/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/google/cloud/storage/blob.py", line 2098, in rewrite
    timeout=timeout,
  File "/tmpfs/src/github/python-docs-samples/storage/cloud-client/.nox/py-3-6/lib/python3.6/site-packages/google/cloud/_http.py", line 423, in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.BadRequest: 400 POST https://storage.googleapis.com/storage/v1/b/python-docs-samples-tests/o/test_blob_2eed0931e61a435a98f112685f291785/rewriteTo/b/python-docs-samples-tests/o/test_blob_2eed0931e61a435a98f112685f291785?destinationKmsKeyName=projects%2Fpython-docs-samples-tests%2Flocations%2Fus%2FkeyRings%2Fgcs-kms-key-ring%2FcryptoKeys%2Fgcs-kms-key: The provided encryption key is incorrect.
--------------------------- Captured stdout teardown ---------------------------
Ignoring 404, detail: 404 DELETE https://storage.googleapis.com/storage/v1/b/python-docs-samples-tests/o/test_blob_2eed0931e61a435a98f112685f291785?generation=1589490963804584: No such object: python-docs-samples-tests/test_blob_2eed0931e61a435a98f112685f291785

@gcf-merge-on-green
Copy link
Contributor

Your PR has attempted to merge for 3 hours. Please check that all required checks have passed, you have an automerge label, and that all your reviewers have approved the PR

@gcf-merge-on-green
Copy link
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, or one of your required reviews was not approved. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@frankyn frankyn added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 15, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 15, 2020
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 15, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 15, 2020
@busunkim96 busunkim96 merged commit d103a57 into GoogleCloudPlatform:master May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants