Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 3942d75

Browse files
committed
refactor: use 'Client._get_path' in 'HMACKeyMetadata.reload'
Toward #38.
1 parent a4b4444 commit 3942d75

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

google/cloud/storage/hmac_key.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,8 @@ def reload(self, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
262262
if self.user_project is not None:
263263
qs_params["userProject"] = self.user_project
264264

265-
self._properties = self._client._connection.api_request(
266-
method="GET",
267-
path=self.path,
268-
query_params=qs_params,
269-
timeout=timeout,
270-
retry=retry,
265+
self._properties = self._client._get_path(
266+
self.path, query_params=qs_params, timeout=timeout, retry=retry,
271267
)
272268

273269
def update(self, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY_IF_ETAG_IN_JSON):

tests/unit/test_hmac_key.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -269,30 +269,28 @@ def test_exists_hit_w_user_project_w_timeout_w_retry(self):
269269
retry=retry,
270270
)
271271

272-
def test_reload_miss_no_project_set(self):
272+
def test_reload_miss_w_defaults(self):
273273
from google.cloud.exceptions import NotFound
274274

275275
access_id = "ACCESS-ID"
276-
connection = mock.Mock(spec=["api_request"])
277-
connection.api_request.side_effect = NotFound("testing")
278-
client = _Client(connection)
276+
project = "PROJECT"
277+
client = mock.Mock(spec=["_get_path", "project"])
278+
client._get_path.side_effect = NotFound("testing")
279+
client.project = project
279280
metadata = self._make_one(client)
280281
metadata._properties["accessId"] = access_id
281282

282283
with self.assertRaises(NotFound):
283-
metadata.reload(timeout=42)
284+
metadata.reload()
284285

285-
expected_path = "/projects/{}/hmacKeys/{}".format(
286-
client.DEFAULT_PROJECT, access_id
286+
expected_path = "/projects/{}/hmacKeys/{}".format(project, access_id)
287+
expected_query_params = {}
288+
client._get_path.assert_called_once_with(
289+
expected_path,
290+
query_params=expected_query_params,
291+
timeout=self._get_default_timeout(),
292+
retry=DEFAULT_RETRY,
287293
)
288-
expected_kwargs = {
289-
"method": "GET",
290-
"path": expected_path,
291-
"query_params": {},
292-
"timeout": 42,
293-
"retry": DEFAULT_RETRY,
294-
}
295-
connection.api_request.assert_called_once_with(**expected_kwargs)
296294

297295
def test_reload_hit_w_project_set(self):
298296
project = "PROJECT-ID"
@@ -304,26 +302,26 @@ def test_reload_hit_w_project_set(self):
304302
"accessId": access_id,
305303
"serviceAccountEmail": email,
306304
}
307-
connection = mock.Mock(spec=["api_request"])
308-
connection.api_request.return_value = resource
309-
client = _Client(connection)
305+
timeout = 42
306+
retry = mock.Mock(spec=[])
307+
client = mock.Mock(spec=["_get_path"])
308+
client._get_path.return_value = resource
310309
metadata = self._make_one(client, user_project=user_project)
311310
metadata._properties["accessId"] = access_id
312311
metadata._properties["projectId"] = project
313312

314-
metadata.reload()
313+
metadata.reload(timeout=timeout, retry=retry)
315314

316315
self.assertEqual(metadata._properties, resource)
317316

318317
expected_path = "/projects/{}/hmacKeys/{}".format(project, access_id)
319-
expected_kwargs = {
320-
"method": "GET",
321-
"path": expected_path,
322-
"query_params": {"userProject": user_project},
323-
"timeout": self._get_default_timeout(),
324-
"retry": DEFAULT_RETRY,
325-
}
326-
connection.api_request.assert_called_once_with(**expected_kwargs)
318+
expected_query_params = {"userProject": user_project}
319+
client._get_path.assert_called_once_with(
320+
expected_path,
321+
query_params=expected_query_params,
322+
timeout=timeout,
323+
retry=retry,
324+
)
327325

328326
def test_update_miss_no_project_set(self):
329327
from google.cloud.exceptions import NotFound

0 commit comments

Comments
 (0)