bito-code-review[bot] commented on code in PR #40399: URL: https://github.com/apache/superset/pull/40399#discussion_r3349604875
########## tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py: ########## @@ -0,0 +1,278 @@ +# 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. + +"""Tests for the update_dashboard MCP tool.""" + +from datetime import datetime +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp +from superset.utils import json + + [email protected] +def mcp_server(): + return mcp + + [email protected](autouse=True) +def mock_auth(): + """Mock authentication for all tests in this module.""" + with patch( + "superset.mcp_service.auth.get_user_from_request" + ) as mock_get_user: + with patch("superset.security_manager.raise_for_ownership"): + 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( + id: int = 42, + title: str = "Test Dashboard", + slug: str | None = "test-slug", + published: bool = True, + css: str | None = None, + json_metadata: str | None = None, + position_json: str | None = None, +): + """Build a Mock with EVERY field the DashboardInfo serializer touches + explicitly set. Without this, Mock returns auto-Mock objects for + unset attributes, which Pydantic rejects as wrong-type.""" + dashboard = Mock() + dashboard.id = id + dashboard.dashboard_title = title + dashboard.slug = slug + dashboard.description = "desc" + dashboard.published = published + dashboard.css = css + dashboard.json_metadata = json_metadata or json.dumps({"label_colors": {}}) + dashboard.position_json = position_json + dashboard.certified_by = None + dashboard.certification_details = None + dashboard.is_managed_externally = False + dashboard.external_url = None + dashboard.created_on = datetime(2024, 1, 1) + dashboard.changed_on = datetime(2024, 1, 1) + dashboard.created_by = Mock(username="admin") + dashboard.changed_by = Mock(username="admin") + dashboard.created_by_name = "admin" + dashboard.changed_by_name = "admin" + dashboard.created_on_humanized = "a day ago" + dashboard.changed_on_humanized = "a day ago" + dashboard.uuid = f"dashboard-uuid-{id}" + dashboard.slices = [] + dashboard.owners = [] + dashboard.tags = [] + return dashboard + + +class TestUpdateDashboard: + """update_dashboard patches existing dashboard layout/theme/CSS.""" Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing description field test</b></div> <div id="fix"> The `UpdateDashboardRequest` schema supports `description` as an optional field (schemas.py:714-717), and `_apply_field_updates` applies it (update_dashboard.py:113-115), but no test validates this behavior. Without a dedicated test, a regression in description handling would go undetected. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` --- a/tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py +++ b/tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py @@ -207,6 +207,23 @@ class TestUpdateDashboard: assert dash.slug == "renamed-slug" assert dash.published is True + @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug") + @patch("superset.extensions.db.session") + @pytest.mark.asyncio + async def test_update_description( + self, mock_session, mock_get, mcp_server + ) -> None: + dash = _mock_dashboard(id=42) + dash.description = "old description" + mock_get.return_value = dash + + async with Client(mcp_server) as client: + await client.call_tool( + "update_dashboard", + {"request": {"identifier": 42, "description": "New description"}}, + ) + + assert dash.description == "New description" + @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug") @patch("superset.extensions.db.session") @pytest.mark.asyncio ``` </div> </details> </div> <small><i>Code Review Run #b55fb6</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]
