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


##########
tests/unit_tests/mcp_service/theme/tool/test_create_theme.py:
##########
@@ -0,0 +1,256 @@
+# 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.
+
+"""Unit tests for the create_theme MCP tool."""
+
+import importlib
+from collections.abc import Iterator
+from unittest.mock import MagicMock, Mock, patch
+
+import pytest
+from fastmcp import Client
+from marshmallow import ValidationError
+
+from superset.mcp_service.app import mcp
+from superset.utils import json
+
+# Resolve the module object directly so patch.object targets the module, not
+# the function re-exported through __init__.py.
+create_theme_module = importlib.import_module(
+    "superset.mcp_service.theme.tool.create_theme"
+)
+
+
+def _make_mock_theme(
+    theme_id: int = 7,
+    theme_name: str = "Corporate Blue",
+    uuid: str = "22222222-2222-2222-2222-222222222222",
+) -> MagicMock:
+    theme = MagicMock()
+    theme.id = theme_id
+    theme.theme_name = theme_name
+    theme.uuid = uuid
+    return theme
+
+
[email protected]
+def mcp_server() -> object:
+    return mcp
+
+
[email protected](autouse=True)
+def mock_auth() -> Iterator[Mock]:
+    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
+
+
[email protected](create_theme_module.db.session, "commit")
+@patch("superset.daos.theme.ThemeDAO.create")
[email protected](create_theme_module, "_sanitize_and_validate_theme_config")
[email protected]
+async def test_create_theme_success_with_dict(
+    mock_sanitize: MagicMock,
+    mock_create: MagicMock,
+    mock_commit: MagicMock,
+    mcp_server: object,
+) -> None:
+    """Happy path: dict json_data is sanitized, persisted, and id/uuid 
returned."""
+    config = {"token": {"colorPrimary": "#1d4ed8"}}
+    mock_sanitize.return_value = config
+    mock_create.return_value = _make_mock_theme()
+
+    async with Client(mcp_server) as client:
+        result = await client.call_tool(
+            "create_theme",
+            {
+                "request": {
+                    "theme_name": "Corporate Blue",
+                    "json_data": config,
+                }
+            },
+        )
+        data = json.loads(result.content[0].text)
+
+    assert data["success"] is True
+    assert data["id"] == 7
+    assert data["uuid"] == "22222222-2222-2222-2222-222222222222"
+    assert "Corporate Blue" in data["theme_name"]

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Test assertion weakened</b></div>
   <div id="fix">
   
   The assertion was weakened from `==` to `in` operator. While both pass with 
the current mock value, `==` is more precise and would catch incorrect theme 
names (e.g., empty strings, typos). Using `in` permits partial matches and 
could allow bugs to go undetected.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #67a75f</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