Skip to content

Commit

Permalink
refactor: rename 'Client._get_path' -> '_get_resource'
Browse files Browse the repository at this point in the history
For parity with forthcoming '_put_resource', '_patch_resource',
'_post_resource', and '_delete_resource' methods.

Toward #38.
  • Loading branch information
tseaver committed May 10, 2021
1 parent 58df886 commit 44eeeb4
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 171 deletions.
2 changes: 1 addition & 1 deletion google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def reload(
if_metageneration_match=if_metageneration_match,
if_metageneration_not_match=if_metageneration_not_match,
)
api_response = client._get_path(
api_response = client._get_resource(
self.path,
query_params=query_params,
headers=self._encryption_headers(),
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/storage/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):

self.entities.clear()

found = client._get_path(
found = client._get_resource(
path, query_params=query_params, timeout=timeout, retry=retry,
)
self.loaded = True
Expand Down
6 changes: 3 additions & 3 deletions google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def exists(
try:
# We intentionally pass `_target_object=None` since fields=name
# would limit the local properties.
client._get_path(
client._get_resource(
self.path,
query_params=query_params,
timeout=timeout,
Expand Down Expand Up @@ -2828,7 +2828,7 @@ def get_iam_policy(
if requested_policy_version is not None:
query_params["optionsRequestedPolicyVersion"] = requested_policy_version

info = client._get_path(
info = client._get_resource(
"%s/iam" % (self.path,),
query_params=query_params,
timeout=timeout,
Expand Down Expand Up @@ -2968,7 +2968,7 @@ def test_iam_permissions(
query_params["userProject"] = self.user_project

path = "%s/iam/testPermissions" % (self.path,)
resp = client._get_path(
resp = client._get_resource(
path,
query_params=query_params,
timeout=timeout,
Expand Down
6 changes: 3 additions & 3 deletions google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def exists(
try:
# We intentionally pass `_target_object=None` since fields=name
# would limit the local properties.
client._get_path(
client._get_resource(
self.path,
query_params=query_params,
timeout=timeout,
Expand Down Expand Up @@ -2881,7 +2881,7 @@ def get_iam_policy(
if requested_policy_version is not None:
query_params["optionsRequestedPolicyVersion"] = requested_policy_version

info = client._get_path(
info = client._get_resource(
"%s/iam" % (self.path,),
query_params=query_params,
timeout=timeout,
Expand Down Expand Up @@ -3006,7 +3006,7 @@ def test_iam_permissions(
query_params["userProject"] = self.user_project

path = "%s/iam/testPermissions" % (self.path,)
resp = client._get_path(
resp = client._get_resource(
path,
query_params=query_params,
timeout=timeout,
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_service_account_email(
project = self.project

path = "/projects/%s/serviceAccount" % (project,)
api_response = self._get_path(path, timeout=timeout, retry=retry)
api_response = self._get_resource(path, timeout=timeout, retry=retry)
return api_response["email_address"]

def bucket(self, bucket_name, user_project=None):
Expand Down Expand Up @@ -320,7 +320,7 @@ def batch(self):
"""
return Batch(client=self)

def _get_path(
def _get_resource(
self,
path,
query_params=None,
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/storage/hmac_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def exists(self, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
if self.user_project is not None:
qs_params["userProject"] = self.user_project

self._client._get_path(
self._client._get_resource(
self.path, query_params=qs_params, timeout=timeout, retry=retry,
)
except NotFound:
Expand Down Expand Up @@ -262,7 +262,7 @@ def reload(self, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
if self.user_project is not None:
qs_params["userProject"] = self.user_project

self._properties = self._client._get_path(
self._properties = self._client._get_resource(
self.path, query_params=qs_params, timeout=timeout, retry=retry,
)

Expand Down
4 changes: 2 additions & 2 deletions google/cloud/storage/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def exists(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
query_params["userProject"] = self.bucket.user_project

try:
client._get_path(
client._get_resource(
self.path, query_params=query_params, timeout=timeout, retry=retry,
)
except NotFound:
Expand Down Expand Up @@ -377,7 +377,7 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
if self.bucket.user_project is not None:
query_params["userProject"] = self.bucket.user_project

response = client._get_path(
response = client._get_resource(
self.path, query_params=query_params, timeout=timeout, retry=retry,
)
self._set_properties(response)
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def test__query_params_w_user_project(self):
def test_reload_w_defaults(self):
path = "/path"
response = {"foo": "Foo"}
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = response
derived = self._derivedClass(path)()
# Make sure changes is not a set instance before calling reload
# (which will clear / replace it with an empty set), checked below.
Expand All @@ -127,7 +127,7 @@ def test_reload_w_defaults(self):

expected_query_params = {"projection": "noAcl"}
expected_headers = {} # no encryption headers by default
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
path,
query_params=expected_query_params,
headers=expected_headers,
Expand All @@ -142,8 +142,8 @@ def test_reload_w_generation_match_w_timeout(self):
path = "/path"
timeout = 42
response = {"foo": "Foo"}
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = response
derived = self._derivedClass(path)()
# Make sure changes is not a set instance before calling reload
# (which will clear / replace it with an empty set), checked below.
Expand All @@ -165,7 +165,7 @@ def test_reload_w_generation_match_w_timeout(self):
"ifMetagenerationMatch": metageneration_number,
}
expected_headers = {} # no encryption headers by default
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
path,
query_params=expected_query_params,
headers=expected_headers,
Expand All @@ -179,8 +179,8 @@ def test_reload_w_user_project_w_retry(self):
path = "/path"
retry = mock.Mock(spec=[])
response = {"foo": "Foo"}
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = response
derived = self._derivedClass(path, user_project)()
# Make sure changes is not a set instance before calling reload
# (which will clear / replace it with an empty set), checked below.
Expand All @@ -197,7 +197,7 @@ def test_reload_w_user_project_w_retry(self):
"userProject": user_project,
}
expected_headers = {} # no encryption headers by default
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
path,
query_params=expected_query_params,
headers=expected_headers,
Expand All @@ -210,8 +210,8 @@ def test_reload_w_projection_w_explicit_client_w_enc_header(self):
path = "/path"
response = {"foo": "Foo"}
encryption_headers = {"bar": "Bar"}
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = response
derived = self._derivedClass(path)()
# Make sure changes is not a set instance before calling reload
# (which will clear / replace it with an empty set), checked below.
Expand All @@ -224,7 +224,7 @@ def test_reload_w_projection_w_explicit_client_w_enc_header(self):
self.assertEqual(derived._changes, set())

expected_query_params = {"projection": "full"}
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
path,
query_params=expected_query_params,
headers=encryption_headers,
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,15 @@ class Derived(self._get_target_class()):
acl.reload_path = reload_path
acl.loaded = True
acl.entity("allUsers", role)
client = acl.client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = api_response
client = acl.client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = api_response

acl.reload()

self.assertEqual(list(acl), [])

expected_query_params = {}
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
reload_path,
query_params=expected_query_params,
timeout=self._get_default_timeout(),
Expand All @@ -571,16 +571,16 @@ def test_reload_w_empty_result_w_timeout_w_retry_w_explicit_client(self):
acl.reload_path = reload_path
acl.loaded = True
acl.entity("allUsers", role)
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = api_response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = api_response

acl.reload(client=client, timeout=timeout, retry=retry)

self.assertTrue(acl.loaded)
self.assertEqual(list(acl), [])

expected_query_params = {}
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
reload_path,
query_params=expected_query_params,
timeout=timeout,
Expand All @@ -596,16 +596,16 @@ def test_reload_w_nonempty_result_w_user_project(self):
acl.reload_path = reload_path
acl.loaded = True
acl.user_project = user_project
client = mock.Mock(spec=["_get_path"])
client._get_path.return_value = api_response
client = mock.Mock(spec=["_get_resource"])
client._get_resource.return_value = api_response

acl.reload(client=client)

self.assertTrue(acl.loaded)
self.assertEqual(list(acl), [{"entity": "allUsers", "role": role}])

expected_query_params = {"userProject": user_project}
client._get_path.assert_called_once_with(
client._get_resource.assert_called_once_with(
reload_path,
query_params=expected_query_params,
timeout=self._get_default_timeout(),
Expand Down
Loading

0 comments on commit 44eeeb4

Please sign in to comment.