-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Storage: add 'Client.list_blobs(bucket_or_name)'. #8375
Conversation
@@ -153,6 +153,26 @@ def _pop_batch(self): | |||
""" | |||
return self._batch_stack.pop() | |||
|
|||
def _use_or_init_bucket(self, bucket_or_name): |
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.
Made a helper - for now it's used in 3 places
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.
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.
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.
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"}) |
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 is full copy of another test named test_list_blobs_defaults
storage/tests/unit/test_client.py
Outdated
@@ -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): |
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.
Analogy to class from bucket tests
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.
I'd prefer that we use mocks rather than add this class.
See:
google-cloud-python/bigquery/tests/unit/helpers.py
Lines 16 to 24 in 0e231ca
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:
google-cloud-python/bigquery/tests/unit/test_client.py
Lines 169 to 173 in 0e231ca
conn.api_request.assert_called_once_with( | |
method="GET", | |
path="/projects/other-project/queries/nothere", | |
query_params={"maxResults": 0, "timeoutMs": 500, "location": self.LOCATION}, | |
) |
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.
Redone with similar mock
"Bucket.list_blobs method is deprecated. Use Client.list_blobs instead.", | ||
PendingDeprecationWarning, | ||
stacklevel=2, | ||
) |
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.
Not sure about this. It will warn if you call Client.list_blobs too
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.
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.
"Bucket.list_blobs method is deprecated. Use Client.list_blobs instead.", | ||
PendingDeprecationWarning, | ||
stacklevel=2, | ||
) |
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.
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): |
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.
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 |
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.
Use Google-style docstrings. https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html#example-google
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.
Okey, it's done
storage/tests/unit/test_client.py
Outdated
@@ -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): |
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.
I'd prefer that we use mocks rather than add this class.
See:
google-cloud-python/bigquery/tests/unit/helpers.py
Lines 16 to 24 in 0e231ca
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:
google-cloud-python/bigquery/tests/unit/test_client.py
Lines 169 to 173 in 0e231ca
conn.api_request.assert_called_once_with( | |
method="GET", | |
path="/projects/other-project/queries/nothere", | |
query_params={"maxResults": 0, "timeoutMs": 500, "location": self.LOCATION}, | |
) |
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.
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. |
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.
Nit. Add backticks for sphinx to render as code font.
Use ``Client.list_blobs`` instead.
Add backticks for sphinx
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