aminghadersohi commented on code in PR #41611: URL: https://github.com/apache/superset/pull/41611#discussion_r3531356907
########## tests/unit_tests/mcp_service/utils/test_query_utils.py: ########## @@ -0,0 +1,62 @@ +# 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 service query utilities. +""" + +from superset.mcp_service.utils.query_utils import validate_names + + +class TestValidateNames: + """Test validate_names function.""" + + def test_all_names_valid_returns_no_errors(self): + """Should return an empty list when every name is valid.""" + errors = validate_names( + ["region", "product"], {"region", "product"}, "dimension" + ) + assert errors == [] + + def test_empty_requested_returns_no_errors(self): + """Should return an empty list when nothing was requested.""" + errors = validate_names([], {"region"}, "dimension") + assert errors == [] + + def test_unknown_name_without_close_match(self): + """Should report an unknown name with no suggestion when nothing is close.""" + errors = validate_names(["zzz_unknown"], {"region", "product"}, "dimension") + assert len(errors) == 1 + assert errors[0] == "Unknown dimension: 'zzz_unknown'" + + def test_unknown_name_with_close_match_suggests_alternatives(self): + """Should suggest close matches when available.""" + errors = validate_names(["regoin"], {"region", "product"}, "dimension") + assert len(errors) == 1 + assert errors[0].startswith("Unknown dimension: 'regoin'") + assert "Did you mean: region" in errors[0] + + def test_multiple_unknown_names_produce_multiple_errors(self): + """Should produce one error per unknown name.""" + errors = validate_names(["revenue", "bogus_metric"], {"revenue"}, "metric") + assert len(errors) == 1 + assert "bogus_metric" in errors[0] Review Comment: Good catch — fixed. The test previously included "revenue" (a valid name) alongside "bogus_metric", so it never actually exercised the multi-error path. Updated to use two unknown names (`bogus_metric`, `zzz_unknown`) and assert `len(errors) == 2`. -- 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]
