Skip to content

Commit 4fb93ff

Browse files
1 parent 678c5c8 commit 4fb93ff

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

‎google/auth/_helpers.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
try:
3030
from google.api_core import client_logging
31+
3132
CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
3233
# TODO(https://github.com/googleapis/google-auth-library-python/issues/1690): Remove `pragma: NO COVER` once
3334
# logging is supported in minimum version of google-api-core.
@@ -337,7 +338,13 @@ def is_logging_enabled(logger: logging.Logger) -> bool:
337338
return CLIENT_LOGGING_SUPPORTED and logger.isEnabledFor(logging.DEBUG)
338339

339340

340-
def request_log(logger: logging.Logger, method: str, url: str, body: Optional[Any], headers: Optional[Dict[str, str]]) -> None:
341+
def request_log(
342+
logger: logging.Logger,
343+
method: str,
344+
url: str,
345+
body: Optional[Any],
346+
headers: Optional[Dict[str, str]],
347+
) -> None:
341348
"""
342349
Logs an HTTP request at the DEBUG level if logging is enabled.
343350

‎tests/test__helpers.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,20 @@ def test_hash_value_none():
274274

275275

276276
def test_is_logging_enabled_with_no_level_set(logger):
277-
277+
278278
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):
279279
assert _helpers.is_logging_enabled(logger) is False
280280

281281

282282
def test_is_logging_enabled_with_client_logging_not_supported(caplog, logger):
283-
283+
284284
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", False):
285285
caplog.set_level(logging.DEBUG, logger=__name__)
286286
assert _helpers.is_logging_enabled(logger) is False
287287

288288

289289
def test_is_logging_enabled_with_debug_disabled(caplog, logger):
290-
290+
291291
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):
292292
caplog.set_level(logging.INFO, logger=__name__)
293293
assert _helpers.is_logging_enabled(logger) is False
@@ -302,21 +302,36 @@ def test_is_logging_enabled_with_debug_enabled(caplog, logger):
302302
def test_request_log_debug_enabled(logger, caplog):
303303
logger.setLevel(logging.DEBUG)
304304
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):
305-
_helpers.request_log(logger, "GET", "http://example.com", {"key": "value"}, {"Authorization": "Bearer token"})
305+
_helpers.request_log(
306+
logger,
307+
"GET",
308+
"http://example.com",
309+
{"key": "value"},
310+
{"Authorization": "Bearer token"},
311+
)
306312
assert "Making request: GET http://example.com" in caplog.text
307313

314+
308315
def test_request_log_debug_disabled(logger, caplog):
309316
logger.setLevel(logging.INFO)
310317
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):
311-
_helpers.request_log(logger, "POST", "https://api.example.com", "data", {"Content-Type": "application/json"})
318+
_helpers.request_log(
319+
logger,
320+
"POST",
321+
"https://api.example.com",
322+
"data",
323+
{"Content-Type": "application/json"},
324+
)
312325
assert "Making request: POST https://api.example.com" not in caplog.text
313326

327+
314328
def test_response_log_debug_enabled(logger, caplog):
315329
logger.setLevel(logging.DEBUG)
316330
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):
317331
_helpers.response_log(logger, "response_object")
318332
assert "Response received..." in caplog.text
319333

334+
320335
def test_response_log_debug_disabled(logger, caplog):
321336
logger.setLevel(logging.INFO)
322337
with mock.patch("google.auth._helpers.CLIENT_LOGGING_SUPPORTED", True):

0 commit comments

Comments
 (0)