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

Storage: add 'Client.list_blobs(bucket_or_name)'. #8375

Merged
merged 10 commits into from
Jun 28, 2019
Merged

Storage: add 'Client.list_blobs(bucket_or_name)'. #8375

merged 10 commits into from
Jun 28, 2019

Conversation

IlyaFaer
Copy link

@IlyaFaer IlyaFaer commented Jun 17, 2019

Made item from redesign doc: "New method: client.list_blobs(bucket_or_name), which functions the same as Bucket.list_blobs()"
https://github.com/googleapis/google-cloud-python/issues/7762

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 17, 2019
@@ -153,6 +153,26 @@ def _pop_batch(self):
"""
return self._batch_stack.pop()

def _use_or_init_bucket(self, bucket_or_name):
Copy link
Author

Choose a reason for hiding this comment

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

Made a helper - for now it's used in 3 places

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit on naming: how about _bucket_arg_to_bucket to align with the similar helper in BigQuery?

def _table_arg_to_table(value, default_project=None):

Also, this might be well suited for the bucket.py module, similar to BigQuery, as I expect the client.py file will expand and the bucket.py file will shrink as we move implementation over to get ready for deprecation.

Copy link
Author

Choose a reason for hiding this comment

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

No problem, renamed

kw, = connection._requested
self.assertEqual(kw["method"], "GET")
self.assertEqual(kw["path"], "/b/%s/o" % NAME)
self.assertEqual(kw["query_params"], {"projection": "noAcl"})
Copy link
Author

Choose a reason for hiding this comment

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

This is full copy of another test named test_list_blobs_defaults

@@ -821,3 +896,39 @@ def dummy_response():
self.assertEqual(page.remaining, 0)
self.assertIsInstance(bucket, Bucket)
self.assertEqual(bucket.name, blob_name)


class _Connection(object):
Copy link
Author

Choose a reason for hiding this comment

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

Analogy to class from bucket tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that we use mocks rather than add this class.

See:

def make_connection(*responses):
import google.cloud.bigquery._http
import mock
from google.cloud.exceptions import NotFound
mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)
mock_conn.user_agent = "testing 1.2.3"
mock_conn.api_request.side_effect = list(responses) + [NotFound("miss")]
return mock_conn

and how it is used:

conn.api_request.assert_called_once_with(
method="GET",
path="/projects/other-project/queries/nothere",
query_params={"maxResults": 0, "timeoutMs": 500, "location": self.LOCATION},
)

Copy link
Author

Choose a reason for hiding this comment

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

Redone with similar mock

@IlyaFaer IlyaFaer marked this pull request as ready for review June 17, 2019 09:08
"Bucket.list_blobs method is deprecated. Use Client.list_blobs instead.",
PendingDeprecationWarning,
stacklevel=2,
)
Copy link
Author

Choose a reason for hiding this comment

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

Not sure about this. It will warn if you call Client.list_blobs too

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's wait to mark these as deprecated until we move all the actual implementation out of the Blob and Bucket classes into the Client class.

@frankyn frankyn requested a review from tswast June 17, 2019 16:37
@tseaver tseaver changed the title Storage client redesign 7762 Storage: add 'Client.list_blobs(bucket_or_name)'. Jun 19, 2019
@tseaver tseaver added the api: storage Issues related to the Cloud Storage API. label Jun 19, 2019
"Bucket.list_blobs method is deprecated. Use Client.list_blobs instead.",
PendingDeprecationWarning,
stacklevel=2,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's wait to mark these as deprecated until we move all the actual implementation out of the Blob and Bucket classes into the Client class.

@@ -153,6 +153,26 @@ def _pop_batch(self):
"""
return self._batch_stack.pop()

def _use_or_init_bucket(self, bucket_or_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit on naming: how about _bucket_arg_to_bucket to align with the similar helper in BigQuery?

def _table_arg_to_table(value, default_project=None):

Also, this might be well suited for the bucket.py module, similar to BigQuery, as I expect the client.py file will expand and the bucket.py file will shrink as we move implementation over to get ready for deprecation.

]):
The bucket resource to pass or name to create.

:type max_results: int
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Okey, it's done

@@ -821,3 +896,39 @@ def dummy_response():
self.assertEqual(page.remaining, 0)
self.assertIsInstance(bucket, Bucket)
self.assertEqual(bucket.name, blob_name)


class _Connection(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that we use mocks rather than add this class.

See:

def make_connection(*responses):
import google.cloud.bigquery._http
import mock
from google.cloud.exceptions import NotFound
mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)
mock_conn.user_agent = "testing 1.2.3"
mock_conn.api_request.side_effect = list(responses) + [NotFound("miss")]
return mock_conn

and how it is used:

conn.api_request.assert_called_once_with(
method="GET",
path="/projects/other-project/queries/nothere",
query_params={"maxResults": 0, "timeoutMs": 500, "location": self.LOCATION},
)

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 24, 2019
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

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

Thanks! One nit, but otherwise LGTM.

Thanks for your patience.

@@ -721,6 +721,9 @@ def list_blobs(
):
"""Return an iterator used to find blobs in the bucket.

.. note::
Direct use of this method is deprecated. Use Client.list_blobs instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Add backticks for sphinx to render as code font.

Use ``Client.list_blobs`` instead.

Add backticks for sphinx
@tswast tswast merged commit c737b74 into googleapis:master Jun 28, 2019
@IlyaFaer IlyaFaer deleted the storage_client_redesign_7762 branch July 2, 2019 11:32
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 Cloud Storage API. cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants