bito-code-review[bot] commented on code in PR #36279:
URL: https://github.com/apache/superset/pull/36279#discussion_r2562103325
##########
tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py:
##########
@@ -1201,27 +1199,24 @@ def test_sortable_columns_in_docstring(self):
assert col in list_datasets.__doc__
@patch("superset.daos.dataset.DatasetDAO.list")
- @patch("superset.mcp_service.auth.get_user_from_request")
@pytest.mark.asyncio
- async def test_default_ordering(self, mock_get_user, mock_dataset_list):
+ async def test_default_ordering(self, mock_list, mcp_server):
"""Test default ordering behavior for datasets."""
- from superset.mcp_service.dataset.tool.list_datasets import
list_datasets
-
- mock_get_user.return_value = MagicMock(id=1)
- # Mock the DAO to return empty list and count
- mock_dataset_list.return_value = ([], 0)
- mock_ctx = MagicMock()
- mock_ctx.info = AsyncMock()
- mock_ctx.debug = AsyncMock()
- mock_ctx.error = AsyncMock()
- request = ListDatasetsRequest() # No order specified
- await list_datasets(request, mock_ctx)
-
- # When order_column is None, the default "changed_on" is used by
ModelListCore
- call_args = mock_dataset_list.call_args[1]
- assert (
- call_args["order_column"] == "changed_on"
- ) # Default applied by ModelListCore
- assert (
- call_args["order_direction"] == "desc"
- ) # From ListDatasetsRequest default
+ # Create mock dataset
+ dataset = create_mock_dataset(
+ dataset_id=1, table_name="Test Dataset", schema="main"
+ )
+ mock_list.return_value = ([dataset], 1)
+
+ async with Client(mcp_server) as client:
+ # Test with no order specified
+ request = ListDatasetsRequest() # No order specified
+ result = await client.call_tool(
+ "list_datasets", {"request": request.model_dump()}
+ )
+ assert result.content is not None
+ data = json.loads(result.content[0].text)
+ assert data["datasets"] is not None
+ assert len(data["datasets"]) == 1
+ # Verify the mock was called
+ mock_list.assert_called_once()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete test assertions for ordering
parameters</b></div>
<div id="fix">
The test for valid order column does not verify that DatasetDAO.list is
called with the correct order_column and order_direction parameters. This could
allow regressions where the ordering logic fails without detection. Add
assertions to check the call arguments match the expected values.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Verify the mock was called
mock_list.assert_called_once()
call_args = mock_list.call_args
assert call_args.kwargs["order_column"] == "table_name"
assert call_args.kwargs["order_direction"] == "asc"
````
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/36279#issuecomment-3578156505>#54e06e</a></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
##########
tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py:
##########
@@ -1201,27 +1199,24 @@ def test_sortable_columns_in_docstring(self):
assert col in list_datasets.__doc__
@patch("superset.daos.dataset.DatasetDAO.list")
- @patch("superset.mcp_service.auth.get_user_from_request")
@pytest.mark.asyncio
- async def test_default_ordering(self, mock_get_user, mock_dataset_list):
+ async def test_default_ordering(self, mock_list, mcp_server):
"""Test default ordering behavior for datasets."""
- from superset.mcp_service.dataset.tool.list_datasets import
list_datasets
-
- mock_get_user.return_value = MagicMock(id=1)
- # Mock the DAO to return empty list and count
- mock_dataset_list.return_value = ([], 0)
- mock_ctx = MagicMock()
- mock_ctx.info = AsyncMock()
- mock_ctx.debug = AsyncMock()
- mock_ctx.error = AsyncMock()
- request = ListDatasetsRequest() # No order specified
- await list_datasets(request, mock_ctx)
-
- # When order_column is None, the default "changed_on" is used by
ModelListCore
- call_args = mock_dataset_list.call_args[1]
- assert (
- call_args["order_column"] == "changed_on"
- ) # Default applied by ModelListCore
- assert (
- call_args["order_direction"] == "desc"
- ) # From ListDatasetsRequest default
+ # Create mock dataset
+ dataset = create_mock_dataset(
+ dataset_id=1, table_name="Test Dataset", schema="main"
+ )
+ mock_list.return_value = ([dataset], 1)
+
+ async with Client(mcp_server) as client:
+ # Test with no order specified
+ request = ListDatasetsRequest() # No order specified
+ result = await client.call_tool(
+ "list_datasets", {"request": request.model_dump()}
+ )
+ assert result.content is not None
+ data = json.loads(result.content[0].text)
+ assert data["datasets"] is not None
+ assert len(data["datasets"]) == 1
+ # Verify the mock was called
+ mock_list.assert_called_once()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete test assertions for default ordering</b></div>
<div id="fix">
The test for default ordering does not verify that DatasetDAO.list is called
with the correct default order_column and order_direction parameters. This
could allow regressions where default ordering fails. Add assertions to check
the call arguments use the expected defaults.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Verify the mock was called
mock_list.assert_called_once()
call_args = mock_list.call_args
assert call_args.kwargs["order_column"] == "changed_on"
assert call_args.kwargs["order_direction"] == "desc"
````
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/36279#issuecomment-3578156505>#54e06e</a></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]