bito-code-review[bot] commented on code in PR #40355:
URL: https://github.com/apache/superset/pull/40355#discussion_r3337294710


##########
tests/unit_tests/mcp_service/theme/tool/test_create_theme.py:
##########
@@ -0,0 +1,364 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from unittest.mock import MagicMock, patch
+
+import pytest
+from fastmcp import Client
+
+from superset.mcp_service.app import mcp
+from superset.mcp_service.theme.schemas import CreateThemeRequest, 
UpdateThemeRequest
+from superset.utils import json
+
+
[email protected]
+def mcp_server():
+    return mcp
+
+
[email protected](autouse=True)
+def mock_auth():
+    from unittest.mock import Mock, patch as _patch
+
+    with _patch("superset.mcp_service.auth.get_user_from_request") as 
mock_get_user:
+        mock_user = Mock()
+        mock_user.id = 1
+        mock_user.username = "admin"
+        mock_get_user.return_value = mock_user
+        yield mock_get_user

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing event_logger mock in tests</b></div>
   <div id="fix">
   
   The `mock_auth` fixture mocks `get_user_from_request` but not 
`event_logger.log_context` used at lines 82 and 99 in the tool implementations. 
When the logged code paths execute (create_theme line 82, update_theme line 
99), the event logger will attempt to insert audit rows with the mock user's 
ID, causing a FK constraint failure against the real `users` table. See 
`test_get_chart_data.py` for the established pattern: `_noop_log_context` 
context manager + `patch.object(module, 'event_logger', mock_event_logger)`.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #93b4ad</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to