codeant-ai-for-open-source[bot] commented on code in PR #41472:
URL: https://github.com/apache/superset/pull/41472#discussion_r3555950276


##########
tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py:
##########
@@ -0,0 +1,233 @@
+# 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 delete_dashboard MCP tool.
+
+Run through the async MCP Client; auth is mocked via the autouse mock_auth
+fixture, matching the other dashboard tool test files.
+"""
+
+from collections.abc import Iterator
+from unittest.mock import Mock, patch
+
+import pytest
+from fastmcp import Client
+
+from superset.mcp_service.app import mcp
+
+_FIND = (
+    
"superset.mcp_service.dashboard.tool.delete_dashboard._find_dashboard_by_identifier"
+)
+_RUN = "superset.commands.dashboard.delete.DeleteDashboardCommand.run"
+_FLAG = 
"superset.mcp_service.dashboard.tool.delete_dashboard.is_feature_enabled"

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag unannotated module-level string constants or inline 
side_effect lambdas with inferable types in tests/unit_tests/mcp_service; this 
test suite follows existing repo convention and mypy already passes.
   
   **Applied to:**
     - `tests/unit_tests/mcp_service/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py:
##########
@@ -0,0 +1,233 @@
+# 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 delete_dashboard MCP tool.
+
+Run through the async MCP Client; auth is mocked via the autouse mock_auth
+fixture, matching the other dashboard tool test files.
+"""
+
+from collections.abc import Iterator
+from unittest.mock import Mock, patch
+
+import pytest
+from fastmcp import Client
+
+from superset.mcp_service.app import mcp
+
+_FIND = (
+    
"superset.mcp_service.dashboard.tool.delete_dashboard._find_dashboard_by_identifier"
+)
+_RUN = "superset.commands.dashboard.delete.DeleteDashboardCommand.run"
+_FLAG = 
"superset.mcp_service.dashboard.tool.delete_dashboard.is_feature_enabled"
+
+
[email protected]
+def mcp_server() -> object:
+    """Provide the FastMCP app instance under test."""
+    return mcp
+
+
[email protected](autouse=True)
+def mock_auth() -> Iterator[Mock]:
+    """Authenticate every tool call as a mock admin user."""
+    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
+
+
+def _mock_dashboard(dashboard_id: int = 1, title: str = "Sales Dashboard") -> 
Mock:
+    """Build a minimal dashboard stand-in with the attributes the tool 
reads."""
+    dashboard = Mock()
+    dashboard.id = dashboard_id
+    dashboard.dashboard_title = title
+    return dashboard
+
+
+@patch(_FIND)
[email protected]
+async def test_delete_dashboard_not_found(mock_find: Mock, mcp_server: object) 
-> None:
+    mock_find.return_value = None
+
+    async with Client(mcp_server) as client:
+        result = await client.call_tool(
+            "delete_dashboard", {"request": {"identifier": 999}}
+        )
+
+    content = result.structured_content
+    assert content["success"] is False
+    assert content["error_type"] == "NotFound"
+    assert "999" in (content["error"] or "")
+
+
+@patch(_RUN)
+@patch(_FIND)
[email protected]
+async def test_delete_dashboard_success(
+    mock_find: Mock, mock_run: Mock, mcp_server: object
+) -> None:
+    mock_find.return_value = _mock_dashboard(1, "Sales Dashboard")
+    mock_run.return_value = None
+
+    async with Client(mcp_server) as client:
+        result = await client.call_tool(
+            "delete_dashboard", {"request": {"identifier": 1}}
+        )
+
+    content = result.structured_content
+    assert content["success"] is True
+    assert content["deleted_id"] == 1
+    assert content["deleted_name"] == "Sales Dashboard"
+    assert content["permission_denied"] is False
+    assert "Its charts were not deleted" in (content["message"] or "")
+    mock_run.assert_called_once()
+
+
+@patch(_FLAG)
+@patch(_RUN)
+@patch(_FIND)
[email protected]
+async def test_delete_dashboard_soft_delete_reports_restorable(
+    mock_find: Mock, mock_run: Mock, mock_flag: Mock, mcp_server: object
+) -> None:
+    mock_find.return_value = _mock_dashboard(1, "Sales Dashboard")
+    mock_run.return_value = None
+    mock_flag.side_effect = lambda flag: flag == "SOFT_DELETE"

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag module-level string constants or inline side_effect lambdas in 
test files when their types are inferable and the project’s test-suite 
convention is to leave them unannotated/named.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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