aminghadersohi commented on code in PR #39604:
URL: https://github.com/apache/superset/pull/39604#discussion_r3329455048
##########
tests/unit_tests/mcp_service/test_auth_api_key.py:
##########
@@ -54,100 +84,110 @@ def _disable_api_keys(app):
app.config["MCP_DEV_USERNAME"] = old_dev
+@contextmanager
+def _mock_sm_ctx(app: SupersetApp, mock_sm: MagicMock):
+ """Push an app context with g.user cleared and appbuilder.sm mocked.
+
+ Defaults find_user_with_relationships to None so JWT/dev-user lookups
+ that hit the SM (via load_user_with_relationships) behave as "user not
+ found" without a real DB, matching the pre-refactor db.session behavior.
+ Tests that need a specific return value should set it on mock_sm directly.
+ """
+ mock_sm.find_user_with_relationships.return_value = None
Review Comment:
Fixed in a subsequent commit. `_mock_sm_ctx` no longer accesses
`mock_sm.find_user_with_relationships` unconditionally, so passing
`MagicMock(spec=[])` is safe. Tests that need `load_user_with_relationships` to
return `None` now patch
`superset.mcp_service.auth.load_user_with_relationships` directly (via
`_patch_load_user_not_found()`), which matches the actual delegation path
through the global `security_manager` — not `app.appbuilder.sm`.
--
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]