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


##########
tests/unit_tests/mcp_service/sql_lab/tool/test_save_sql_query.py:
##########
@@ -0,0 +1,112 @@
+# 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 MCP save_sql_query tool."""
+
+import pytest
+
+from superset.mcp_service.sql_lab.schemas import (
+    SaveSqlQueryRequest,
+    SaveSqlQueryResponse,
+)
+
+
+class TestSaveSqlQuerySchemas:
+    """Tests for save_sql_query request/response schemas."""
+
+    def test_valid_request(self):
+        """Test creating a valid SaveSqlQueryRequest."""
+        request = SaveSqlQueryRequest(
+            database_id=1,
+            sql="SELECT * FROM users",
+            label="All Users",
+        )
+        assert request.database_id == 1
+        assert request.sql == "SELECT * FROM users"
+        assert request.label == "All Users"
+        assert request.description is None
+        assert request.schema_name is None
+        assert request.catalog is None
+        assert request.template_parameters is None
+
+    def test_request_with_all_fields(self):
+        """Test request with all optional fields populated."""
+        request = SaveSqlQueryRequest(
+            database_id=1,
+            sql="SELECT * FROM {{ table }}",
+            label="Parameterized Query",
+            description="A query with Jinja2 templates",
+            schema="public",
+            catalog="main",
+            template_parameters='{"table": "users"}',
+        )
+        assert request.description == "A query with Jinja2 templates"
+        assert request.schema_name == "public"
+        assert request.catalog == "main"
+        assert request.template_parameters == '{"table": "users"}'
+
+    def test_request_rejects_empty_sql(self):
+        """Test that empty SQL is rejected."""
+        with pytest.raises(ValueError, match="SQL query cannot be empty"):
+            SaveSqlQueryRequest(
+                database_id=1,
+                sql="   ",
+                label="Bad Query",
+            )
+
+    def test_request_rejects_empty_label(self):
+        """Test that empty label is rejected."""
+        with pytest.raises(ValueError):
+            SaveSqlQueryRequest(
+                database_id=1,
+                sql="SELECT 1",
+                label="",
+            )

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect exception type in test</b></div>
   <div id="fix">
   
   The test expects ValueError for empty label, but pydantic v2 raises 
ValidationError for min_length violations. Update to match actual behavior.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    --- tests/unit_tests/mcp_service/sql_lab/tool/test_save_sql_query.py
    +++ tests/unit_tests/mcp_service/sql_lab/tool/test_save_sql_query.py
    @@ -20,6 +20,7 @@ import pytest
    
     from superset.mcp_service.sql_lab.schemas import (
         SaveSqlQueryRequest,
         SaveSqlQueryResponse,
     )
    +from pydantic import ValidationError
    
    
     class TestSaveSqlQuerySchemas:
    @@ -71,7 +72,7 @@ class TestSaveSqlQuerySchemas:
         def test_request_rejects_empty_label(self):
             """Test that empty label is rejected."""
    -        with pytest.raises(ValueError):
    +        with pytest.raises(ValidationError):
                 SaveSqlQueryRequest(
                     database_id=1,
                     sql="SELECT 1",
                     label="",
                 )
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #974105</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