| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f41f891 commit 84599aa
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -447,6 +447,7 @@ def run_local_server( | |||
| 447 | 447 | webbrowser.get(browser).open(auth_url, new=1, autoraise=True) | |
| 448 | 448 | ||
| 449 | 449 | if authorization_prompt_message: | |
| 450 | + _LOGGER.info(authorization_prompt_message.format(url=auth_url)) | ||
| 450 | 451 | print(authorization_prompt_message.format(url=auth_url)) | |
| 451 | 452 | ||
| 452 | 453 | local_server.timeout = timeout_seconds | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | import datetime | |
| 17 | 17 | from functools import partial | |
| 18 | 18 | import json | |
| 19 | + import logging | ||
| 19 | 20 | import os | |
| 20 | 21 | import re | |
| 21 | 22 | import socket | |
@@ -460,3 +461,38 @@ def test_local_server_socket_cleanup( | |||
| 460 | 461 | instance.run_local_server() | |
| 461 | 462 | ||
| 462 | 463 | server_mock.server_close.assert_called_once() | |
| 464 | + | ||
| 465 | + @mock.patch("builtins.print") | ||
| 466 | + @mock.patch("google_auth_oauthlib.flow.webbrowser", autospec=True) | ||
| 467 | + def test_run_local_server_logs_and_prints_url( | ||
| 468 | + self, webbrowser_mock, print_mock, instance, mock_fetch_token, port, caplog | ||
| 469 | + ): | ||
| 470 | + auth_redirect_url = urllib.parse.urljoin( | ||
| 471 | + f"http://localhost:{port}", self.REDIRECT_REQUEST_PATH | ||
| 472 | + ) | ||
| 473 | + | ||
| 474 | + # Configure caplog to capture INFO logs | ||
| 475 | + caplog.set_level(logging.INFO, logger="google_auth_oauthlib.flow") | ||
| 476 | + | ||
| 477 | + with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool: | ||
| 478 | + future = pool.submit(partial(instance.run_local_server, port=port)) | ||
| 479 | + | ||
| 480 | + while not future.done(): | ||
| 481 | + try: | ||
| 482 | + requests.get(auth_redirect_url) | ||
| 483 | + except requests.ConnectionError: | ||
| 484 | + pass | ||
| 485 | + | ||
| 486 | + future.result() | ||
| 487 | + | ||
| 488 | + # Verify log message | ||
| 489 | + assert "Please visit this URL" in caplog.text | ||
| 490 | + assert urllib.parse.quote(instance.redirect_uri, safe="") in caplog.text | ||
| 491 | + | ||
| 492 | + # Verify print message | ||
| 493 | + print_mock.assert_called_once() | ||
| 494 | + assert "Please visit this URL" in print_mock.call_args[0][0] | ||
| 495 | + assert ( | ||
| 496 | + urllib.parse.quote(instance.redirect_uri, safe="") | ||
| 497 | + in print_mock.call_args[0][0] | ||
| 498 | + ) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments