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

Commit 47f0753

Browse files
committed
fixed 3.7 test errors
1 parent 1e1ed0a commit 47f0753

7 files changed

Lines changed: 30 additions & 14 deletions

File tree

tests/compute_engine/test_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ def test_get_id_token_from_metadata(
13071307
)
13081308
cred.refresh(request=mock.Mock())
13091309

1310-
assert get.call_args.kwargs["headers"] == {
1310+
assert get.call_args[1]["headers"] == {
13111311
"x-goog-api-client": ID_TOKEN_REQUEST_METRICS_HEADER_VALUE
13121312
}
13131313

tests/oauth2/test_webauthn_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_success_get_assertion(os_get_stub, subprocess_run_stub):
107107
os_get_stub.assert_called_once()
108108
subprocess_run_stub.assert_called_once()
109109

110-
stdin_input = subprocess_run_stub.call_args.kwargs["input"]
110+
stdin_input = subprocess_run_stub.call_args[1]["input"]
111111
input_json_len_le = stdin_input[:4]
112112
input_json_len = struct.unpack("<I", input_json_len_le)[0]
113113
input_json = stdin_input[4:]

tests/test__exponential_backoff.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ def test_minimum_total_attempts():
5757
_exponential_backoff.ExponentialBackoff(total_attempts=1)
5858

5959

60+
async def async_sleep(delay):
61+
pass
62+
63+
6064
@pytest.mark.asyncio
61-
@mock.patch("asyncio.sleep", return_value=None)
65+
@mock.patch("asyncio.sleep", side_effect=async_sleep)
6266
async def test_exponential_backoff_async(mock_time_async):
6367
eb = _exponential_backoff.AsyncExponentialBackoff()
6468
curr_wait = eb._current_wait_in_seconds

tests/test_impersonated_credentials.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_refresh_success(
344344
assert credentials.valid
345345
assert not credentials.expired
346346
assert (
347-
request.call_args.kwargs["headers"]["x-goog-api-client"]
347+
request.call_args[1]["headers"]["x-goog-api-client"]
348348
== ACCESS_TOKEN_REQUEST_METRICS_HEADER_VALUE
349349
)
350350

@@ -1075,7 +1075,7 @@ def test_id_token_metrics(self, mock_donor_credentials):
10751075
ID_TOKEN_EXPIRY
10761076
)
10771077
assert (
1078-
mock_post.call_args.kwargs["headers"]["x-goog-api-client"]
1078+
mock_post.call_args[1]["headers"]["x-goog-api-client"]
10791079
== ID_TOKEN_REQUEST_METRICS_HEADER_VALUE
10801080
)
10811081

@@ -1145,9 +1145,11 @@ def _test_id_token_helper(
11451145
id_creds = id_creds.from_credentials(target_credentials=target_credentials)
11461146
id_creds.refresh(request)
11471147

1148-
args = mock_authorizedsession_idtoken.call_args.args
1149-
1150-
assert args[2] == expected_url
1148+
# In Python 3.7, self might not be in call_args for autospecced methods
1149+
args = mock_authorizedsession_idtoken.call_args[0]
1150+
1151+
# Look for expected_url in args
1152+
assert expected_url in args
11511153

11521154
assert id_creds.token == ID_TOKEN_DATA
11531155
assert id_creds._include_email is True

tests/transport/aio/test_sessions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ async def test_request_max_allowed_time_exceeded_error(self):
261261
@pytest.mark.parametrize("retry_status", DEFAULT_RETRYABLE_STATUS_CODES)
262262
@pytest.mark.asyncio
263263
async def test_request_max_retries(self, retry_status):
264+
async def async_sleep(delay):
265+
pass
266+
264267
mocked_response = MockResponse(status_code=retry_status)
265268
auth_request = MockRequest(mocked_response)
266-
with patch("asyncio.sleep", return_value=None):
269+
with patch("asyncio.sleep", side_effect=async_sleep):
267270
authed_session = sessions.AsyncAuthorizedSession(
268271
self.credentials, auth_request
269272
)

tests_async/oauth2/test__client_async.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ def make_request(response_data, status=http_client.OK, text=False):
3737
response = AsyncMock(spec=["transport.Response"])
3838
response.status = status
3939
data = response_data if text else json.dumps(response_data).encode("utf-8")
40+
41+
async def get_content(*args, **kwargs):
42+
return data
43+
4044
response.data = AsyncMock(spec=["__call__", "read"])
41-
response.data.read = AsyncMock(spec=["__call__"], return_value=data)
42-
response.content = AsyncMock(spec=["__call__"], return_value=data)
45+
response.data.read = AsyncMock(spec=["__call__"], side_effect=get_content)
46+
response.content = AsyncMock(spec=["__call__"], side_effect=get_content)
4347
request = AsyncMock(spec=["transport.Request"])
4448
request.return_value = response
4549
return request

tests_async/oauth2/test_id_token.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ def make_request(status, data=None):
3838

3939
if data is not None:
4040
response.data = AsyncMock(spec=["__call__", "read"])
41-
response.content = AsyncMock(
42-
spec=["__call__"], return_value=json.dumps(data).encode("utf-8")
43-
)
41+
42+
async def get_content(*args, **kwargs):
43+
return json.dumps(data).encode("utf-8")
44+
45+
response.data.read = AsyncMock(spec=["__call__"], side_effect=get_content)
46+
response.content = AsyncMock(spec=["__call__"], side_effect=get_content)
4447

4548
request = AsyncMock(spec=["transport.Request"])
4649
request.return_value = response

0 commit comments

Comments
 (0)