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

tests: avoid requiring real credentials in unit tests #459

Merged
merged 3 commits into from
Jun 9, 2021

Conversation

tseaver
Copy link
Contributor

@tseaver tseaver commented Jun 8, 2021

Fixes #416

Also, adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Remove last uses of '_Client' and '_Connection' shims:  use a mocked
client instead.

Toward #416.
@tseaver tseaver requested review from chrisrossi, andrewsg and a team June 8, 2021 20:30
@tseaver tseaver requested a review from a team as a code owner June 8, 2021 20:30
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Jun 8, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 8, 2021
@tseaver tseaver force-pushed the 416-avoid_real_client_in_bucket_blob_unit_tests branch from cc643b2 to a694cab Compare June 8, 2021 21:11
@tseaver tseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 8, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 8, 2021
@tseaver tseaver requested review from tritone and frankyn June 8, 2021 21:26
@@ -3351,96 +3348,14 @@ def test_make_private_recursive_too_many(self):

client.list_blobs.assert_called_once()

def test_page_empty_response(self):

Choose a reason for hiding this comment

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

Why are these tests being removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are non-unit tests (they really only test the already-well-tested api_core.page_iterator.Iterator). The local bits are replaced by the (new) explicit tests of _item_to_blob and _blobs_page_start (at the top of the file).

@@ -1024,6 +1021,99 @@ def _mock_requests_response(status_code, headers, content=b""):
response.request = requests.Request("POST", "http://example.com").prepare()
return response

def test__extract_headers_from_download_gzipped(self):

Choose a reason for hiding this comment

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

Adding coverage, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests were misnamed, and out of place: I just fixed that, and split a couple of over-large ones.

Copy link

@chrisrossi chrisrossi left a comment

Choose a reason for hiding this comment

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

LGTM!

@tseaver tseaver merged commit 2c87f2f into master Jun 9, 2021
@tseaver tseaver deleted the 416-avoid_real_client_in_bucket_blob_unit_tests branch June 9, 2021 18:43
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Closes googleapis#416.
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Adjust 'Bucket.get_upload_policy' to use credentials from the client,
rather than its connection.

Closes googleapis#416.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit tests must not depend on environment variables
3 participants