codeant-ai-for-open-source[bot] commented on code in PR #40957:
URL: https://github.com/apache/superset/pull/40957#discussion_r3493688839
##########
tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py:
##########
@@ -309,3 +309,152 @@ async def test_xss_only_title_is_rejected(self,
mcp_server) -> None:
}
},
)
+
+ @patch("superset.commands.utils.update_tags")
+ @patch("superset.commands.utils.validate_tags")
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_update_tags_replaces(
+ self, mock_session, mock_get, mock_validate_tags, mock_update_tags,
mcp_server
+ ) -> None:
+ """``tags`` routes through the same validate/update helpers the REST
+ UpdateDashboardCommand uses, and reports ``tags`` as changed."""
+ from superset.tags.models import ObjectType
+
+ dash = _mock_dashboard(id=42)
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ result = await client.call_tool(
+ "update_dashboard",
+ {"request": {"identifier": 42, "tags": [3, 7]}},
+ )
+
+ mock_validate_tags.assert_called_once()
+ mock_update_tags.assert_called_once()
+ update_args = mock_update_tags.call_args.args
+ assert update_args[0] == ObjectType.dashboard
+ assert update_args[1] == 42
+ assert update_args[3] == [3, 7]
+ payload = json.loads(result.content[0].text)
+ assert "tags" in payload.get("changed_fields", [])
+
+ @patch("superset.commands.utils.update_tags")
+ @patch("superset.commands.utils.validate_tags")
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_update_tags_empty_list_clears(
+ self, mock_session, mock_get, mock_validate_tags, mock_update_tags,
mcp_server
+ ) -> None:
+ """An empty ``tags`` list is a full replacement that clears all
+ custom tags — it must still reach ``update_tags`` (not be treated
+ as 'unchanged')."""
+ dash = _mock_dashboard(id=42)
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ await client.call_tool(
+ "update_dashboard",
+ {"request": {"identifier": 42, "tags": []}},
+ )
+
+ mock_update_tags.assert_called_once()
+ assert mock_update_tags.call_args.args[3] == []
+
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_typed_metadata_toggles_fold_into_json_metadata(
+ self, mock_session, mock_get, mcp_server
+ ) -> None:
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require type hints for patch-injected Mock parameters in this test
file; keep these async test methods consistent with the existing unannotated
patterns used elsewhere in the file.
**Applied to:**
- `tests/unit_tests/mcp_service/dashboard/tool/**`
---
💡 *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_update_dashboard.py:
##########
@@ -309,3 +309,152 @@ async def test_xss_only_title_is_rejected(self,
mcp_server) -> None:
}
},
)
+
+ @patch("superset.commands.utils.update_tags")
+ @patch("superset.commands.utils.validate_tags")
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_update_tags_replaces(
+ self, mock_session, mock_get, mock_validate_tags, mock_update_tags,
mcp_server
+ ) -> None:
+ """``tags`` routes through the same validate/update helpers the REST
+ UpdateDashboardCommand uses, and reports ``tags`` as changed."""
+ from superset.tags.models import ObjectType
+
+ dash = _mock_dashboard(id=42)
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ result = await client.call_tool(
+ "update_dashboard",
+ {"request": {"identifier": 42, "tags": [3, 7]}},
+ )
+
+ mock_validate_tags.assert_called_once()
+ mock_update_tags.assert_called_once()
+ update_args = mock_update_tags.call_args.args
+ assert update_args[0] == ObjectType.dashboard
+ assert update_args[1] == 42
+ assert update_args[3] == [3, 7]
+ payload = json.loads(result.content[0].text)
+ assert "tags" in payload.get("changed_fields", [])
+
+ @patch("superset.commands.utils.update_tags")
+ @patch("superset.commands.utils.validate_tags")
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_update_tags_empty_list_clears(
+ self, mock_session, mock_get, mock_validate_tags, mock_update_tags,
mcp_server
+ ) -> None:
+ """An empty ``tags`` list is a full replacement that clears all
+ custom tags — it must still reach ``update_tags`` (not be treated
+ as 'unchanged')."""
+ dash = _mock_dashboard(id=42)
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ await client.call_tool(
+ "update_dashboard",
+ {"request": {"identifier": 42, "tags": []}},
+ )
+
+ mock_update_tags.assert_called_once()
+ assert mock_update_tags.call_args.args[3] == []
+
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_typed_metadata_toggles_fold_into_json_metadata(
+ self, mock_session, mock_get, mcp_server
+ ) -> None:
+ """Typed convenience fields are merged into json_metadata without
+ clobbering unrelated keys."""
+ dash = _mock_dashboard(
+ id=42, json_metadata=json.dumps({"label_colors": {"A": "#111"}})
+ )
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ result = await client.call_tool(
+ "update_dashboard",
+ {
+ "request": {
+ "identifier": 42,
+ "cross_filters_enabled": False,
+ "refresh_frequency": 300,
+ "filter_bar_orientation": "HORIZONTAL",
+ }
+ },
+ )
+
+ merged = json.loads(dash.json_metadata)
+ assert merged["cross_filters_enabled"] is False
+ assert merged["refresh_frequency"] == 300
+ assert merged["filter_bar_orientation"] == "HORIZONTAL"
+ assert merged["label_colors"] == {"A": "#111"} # preserved
+ payload = json.loads(result.content[0].text)
+ assert "json_metadata" in payload.get("changed_fields", [])
+
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_typed_metadata_conflict_is_rejected(
+ self, mock_session, mock_get, mcp_server
+ ) -> None:
+ """Setting the same key via a typed field AND json_metadata_overrides
+ is ambiguous and rejected before any write."""
+ dash = _mock_dashboard(id=42)
+ mock_get.return_value = dash
+
+ async with Client(mcp_server) as client:
+ result = await client.call_tool(
+ "update_dashboard",
+ {
+ "request": {
+ "identifier": 42,
+ "cross_filters_enabled": False,
+ "json_metadata_overrides": {"cross_filters_enabled":
True},
+ }
+ },
+ )
+
+ payload = json.loads(result.content[0].text)
+ assert "cross_filters_enabled" in (payload.get("error") or "")
+ mock_session.commit.assert_not_called()
+
+ @patch("superset.dashboards.schemas.validate_css")
+ @patch("superset.daos.dashboard.DashboardDAO.get_by_id_or_slug")
+ @patch("superset.extensions.db.session")
+ @pytest.mark.asyncio
+ async def test_invalid_css_is_rejected(
+ self, mock_session, mock_get, mock_validate_css, mcp_server
+ ) -> None:
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require type hints for pytest test functions or fixtures in unit
test files.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.<ext>`
---
💡 *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]