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


##########
tests/unit_tests/views/test_base.py:
##########
@@ -0,0 +1,93 @@
+# 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 superset.views.base module"""
+
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+
+@patch("superset.views.base.utils.get_user_id", return_value=1)
+@patch(
+    "superset.views.base.cached_common_bootstrap_data", return_value={"test": 
"data"}
+)
+@patch("superset.views.base.get_locale")
+def test_common_bootstrap_payload_converts_locale_to_string(
+    mock_get_locale: MagicMock,
+    mock_cached: MagicMock,
+    mock_user_id: MagicMock,
+) -> None:
+    """Test that common_bootstrap_payload converts locale to string for cache 
key"""
+    # Mock get_locale to return a Locale-like object with __str__
+    mock_locale = MagicMock()
+    mock_locale.__str__ = lambda self: "de_DE"
+    mock_get_locale.return_value = mock_locale
+
+    # Import here to avoid initialization issues
+    from superset.views.base import common_bootstrap_payload
+
+    result = common_bootstrap_payload()
+
+    # Verify cached_common_bootstrap_data was called with string locale
+    mock_cached.assert_called_once_with(1, "de_DE")
+    assert result == {"test": "data"}
+
+
+@patch("superset.views.base.utils.get_user_id", return_value=1)
+@patch(
+    "superset.views.base.cached_common_bootstrap_data", return_value={"test": 
"data"}
+)
+@patch("superset.views.base.get_locale", return_value=None)
+def test_common_bootstrap_payload_handles_none_locale(
+    mock_get_locale: MagicMock,
+    mock_cached: MagicMock,
+    mock_user_id: MagicMock,
+) -> None:
+    """Test that None locale is passed through correctly"""
+    from superset.views.base import common_bootstrap_payload
+
+    common_bootstrap_payload()
+
+    mock_cached.assert_called_once_with(1, None)
+
+
+def _extract_language(locale_str: str | None) -> str:
+    """Helper that mirrors the logic in cached_common_bootstrap_data"""
+    if locale_str:
+        return locale_str.replace("-", "_").split("_")[0]
+    return "en"
+
+
[email protected](
+    "locale_str,expected_language",

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>pytest.mark.parametrize wrong type</b></div>
   <div id="fix">
   
   Change the first argument of `pytest.mark.parametrize` on line 76 from a 
string to a tuple: `("locale_str", "expected_language")` instead of 
`"locale_str,expected_language"`.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
       ("locale_str", "expected_language"),
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1ad399</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