bito-code-review[bot] commented on code in PR #44765:
URL: https://github.com/apache/superset/pull/44765#discussion_r4154202119
##########
tests/unit_tests/utils/oauth2_tests.py:
##########
@@ -239,6 +245,50 @@ def test_execute_with_oauth2_retry_forces_refresh_once(
db.session.expire.assert_called_once_with(token)
[email protected]("retry_fails", [False, True])
[email protected]("outer_active", [False, True])
+def test_execute_with_oauth2_retry_guards_both_attempts(
+ mocker: MockerFixture,
+ retry_fails: bool,
+ outer_active: bool,
+) -> None:
+ """Both attempts own connection recovery, and every exit restores the
guard."""
+ mocker.patch(
+ "superset.utils.oauth2._oauth2_retry_active",
+ ContextVar("test_oauth2_retry_active", default=outer_active),
+ )
+ database = mocker.MagicMock(id=1)
+ database.is_oauth2_enabled.return_value = True
+ database.db_engine_spec.needs_oauth2.return_value = True
+ database.get_oauth2_config.return_value = DUMMY_OAUTH2_CONFIG
+ mocker.patch("superset.utils.oauth2.g").user.id = 2
+ db = mocker.patch("superset.utils.oauth2.db")
+ db.session.query().filter_by().one_or_none.return_value = None
+ refresh = mocker.patch(
+ "superset.utils.oauth2.refresh_oauth2_token", return_value="new-token"
+ )
Review Comment:
<!-- Bito Reply -->
The suggestion to verify the full call signature of the `refresh` mock is
appropriate. Asserting the specific arguments (such as the configuration, user
ID, and flags) ensures that the `execute_with_oauth2_retry` function correctly
handles the token refresh process, preventing potential regressions where
incorrect parameters might be passed.
**tests/unit_tests/utils/oauth2_tests.py**
```
refresh.assert_called_once_with(
database, DUMMY_OAUTH2_CONFIG, user_id=2, force=True
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]