codeant-ai-for-open-source[bot] commented on code in PR #34619:
URL: https://github.com/apache/superset/pull/34619#discussion_r3464413711


##########
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py:
##########
@@ -0,0 +1,263 @@
+# 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.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.db_engine_specs.databricks import (
+    DatabricksNativeEngineSpec,
+    DatabricksPythonConnectorEngineSpec,
+)
+from superset.superset_typing import OAuth2ClientConfig
+from superset.utils.oauth2 import decode_oauth2_state
+
+# Multi-Cloud Provider Tests
+
+
[email protected]
+def mock_database_aws(mocker: MockerFixture):

Review Comment:
   **Suggestion:** Add an explicit return type annotation to this fixture so 
the new function is fully typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly added Python fixture function and it lacks a return type 
annotation.
   The rule requires new Python functions to be fully typed, including return 
values.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3ea462cc65e04b64b0e673c154512ef0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3ea462cc65e04b64b0e673c154512ef0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
   **Line:** 35:35
   **Comment:**
        *Custom Rule: Add an explicit return type annotation to this fixture so 
the new function is fully typed.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=c7b29c101b3e33855709b6727a0c4b20a104a736f10fd5595672b4180a1139a5&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=c7b29c101b3e33855709b6727a0c4b20a104a736f10fd5595672b4180a1139a5&reaction=dislike'>👎</a>



##########
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py:
##########
@@ -0,0 +1,263 @@
+# 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.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.db_engine_specs.databricks import (
+    DatabricksNativeEngineSpec,
+    DatabricksPythonConnectorEngineSpec,
+)
+from superset.superset_typing import OAuth2ClientConfig
+from superset.utils.oauth2 import decode_oauth2_state
+
+# Multi-Cloud Provider Tests
+
+
[email protected]
+def mock_database_aws(mocker: MockerFixture):
+    """
+    Mock database with AWS hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "my-cluster.cloud.databricks.com"
+    database.extra = "{}"
+    database.id = 1
+    return database
+
+
[email protected]
+def mock_database_azure(mocker: MockerFixture):
+    """
+    Mock database with Azure hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "adb-123456789.12.azuredatabricks.net"
+    database.extra = "{}"
+    database.id = 2
+    return database
+
+
[email protected]
+def mock_database_gcp(mocker: MockerFixture):
+    """
+    Mock database with GCP hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "123456789.gcp.databricks.com"
+    database.extra = "{}"
+    database.id = 3
+    return database
+
+
[email protected]
+def oauth2_config() -> OAuth2ClientConfig:
+    """
+    Config for Databricks OAuth2.
+    """
+    return {
+        "id": "databricks-client-id",
+        "secret": "databricks-client-secret",
+        "scope": "sql",
+        "redirect_uri": "http://localhost:8088/api/v1/database/oauth2/";,
+        "authorization_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/authorize";,
+        "token_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/token";,
+        "request_content_type": "json",
+    }
+
+
+def test_cloud_provider_detection_aws(mock_database_aws) -> None:

Review Comment:
   **Suggestion:** Add a concrete type hint for the fixture argument used by 
this test function. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This new test function has an untyped parameter, `mock_database_aws`.
   The custom rule requires newly added Python functions to be fully typed, so 
this is a real violation.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=bc0ce926b9254f73b7b503e891e1446e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=bc0ce926b9254f73b7b503e891e1446e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
   **Line:** 86:86
   **Comment:**
        *Custom Rule: Add a concrete type hint for the fixture argument used by 
this test function.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=f01744d6ce6a78d5c76d0ec9d4dc2e93bf8fba3879be49f5a54e3bfabedd4f59&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=f01744d6ce6a78d5c76d0ec9d4dc2e93bf8fba3879be49f5a54e3bfabedd4f59&reaction=dislike'>👎</a>



##########
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py:
##########
@@ -0,0 +1,263 @@
+# 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.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.db_engine_specs.databricks import (
+    DatabricksNativeEngineSpec,
+    DatabricksPythonConnectorEngineSpec,
+)
+from superset.superset_typing import OAuth2ClientConfig
+from superset.utils.oauth2 import decode_oauth2_state
+
+# Multi-Cloud Provider Tests
+
+
[email protected]
+def mock_database_aws(mocker: MockerFixture):
+    """
+    Mock database with AWS hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "my-cluster.cloud.databricks.com"
+    database.extra = "{}"
+    database.id = 1
+    return database
+
+
[email protected]
+def mock_database_azure(mocker: MockerFixture):
+    """
+    Mock database with Azure hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "adb-123456789.12.azuredatabricks.net"
+    database.extra = "{}"
+    database.id = 2
+    return database
+
+
[email protected]
+def mock_database_gcp(mocker: MockerFixture):
+    """
+    Mock database with GCP hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "123456789.gcp.databricks.com"
+    database.extra = "{}"
+    database.id = 3
+    return database
+
+
[email protected]
+def oauth2_config() -> OAuth2ClientConfig:
+    """
+    Config for Databricks OAuth2.
+    """
+    return {
+        "id": "databricks-client-id",
+        "secret": "databricks-client-secret",
+        "scope": "sql",
+        "redirect_uri": "http://localhost:8088/api/v1/database/oauth2/";,
+        "authorization_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/authorize";,
+        "token_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/token";,
+        "request_content_type": "json",
+    }
+
+
+def test_cloud_provider_detection_aws(mock_database_aws) -> None:
+    """
+    Test cloud provider detection for AWS.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_aws)
+    assert provider == "aws"
+
+
+def test_cloud_provider_detection_azure(mock_database_azure) -> None:
+    """
+    Test cloud provider detection for Azure.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_azure)
+    assert provider == "azure"
+
+
+def test_cloud_provider_detection_gcp(mock_database_gcp) -> None:
+    """
+    Test cloud provider detection for GCP.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_gcp)
+    assert provider == "gcp"
+
+
+def test_cloud_provider_detection_explicit_config(mocker: MockerFixture) -> 
None:
+    """
+    Test cloud provider detection with explicit configuration.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "generic-host.com"
+
+    # Mock get_extra_params to return explicit cloud provider
+    mocker.patch.object(
+        DatabricksNativeEngineSpec,
+        "get_extra_params",
+        return_value={"cloud_provider": "azure"},
+    )
+
+    provider = DatabricksNativeEngineSpec._detect_cloud_provider(database)
+    assert provider == "azure"
+
+
+def test_get_oauth2_authorization_uri_aws(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_aws,
+) -> None:
+    """
+    Test OAuth2 authorization URI generation for AWS provider.
+    """
+    from superset.db_engine_specs.base import OAuth2State
+
+    # Mock the database query
+    mocker.patch("superset.extensions.db.session.get", 
return_value=mock_database_aws)
+
+    state: OAuth2State = {
+        "database_id": 1,
+        "user_id": 1,
+        "default_redirect_uri": 
"http://localhost:8088/api/v1/database/oauth2/";,
+        "tab_id": "1234",
+    }
+
+    url = 
DatabricksNativeEngineSpec.get_oauth2_authorization_uri(oauth2_config, state)
+    parsed = urlparse(url)
+    assert parsed.netloc == "accounts.cloud.databricks.com"
+    assert "/oidc/accounts/" in parsed.path
+    assert "/v1/authorize" in parsed.path
+
+    query = parse_qs(parsed.query)
+    assert query["scope"][0] == "sql"
+    encoded_state = query["state"][0].replace("%2E", ".")
+    assert decode_oauth2_state(encoded_state) == state
+
+
+def test_get_oauth2_authorization_uri_azure(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_azure,
+) -> None:

Review Comment:
   **Suggestion:** Add a type annotation for the untyped fixture parameter in 
this function signature. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a new function and it includes an untyped parameter, 
`mock_database_azure`.
   The rule explicitly requires full type hints for new Python functions, so 
the suggestion is valid.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c7c4735b7b0a4f7bb6c77d2ca0ca43b5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c7c4735b7b0a4f7bb6c77d2ca0ca43b5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
   **Line:** 160:164
   **Comment:**
        *Custom Rule: Add a type annotation for the untyped fixture parameter 
in this function signature.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=a978e81fdf6e5fdccedde7b4baabdbe220f40a0fabe469c681c761d361cbdeed&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=a978e81fdf6e5fdccedde7b4baabdbe220f40a0fabe469c681c761d361cbdeed&reaction=dislike'>👎</a>



##########
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py:
##########
@@ -0,0 +1,263 @@
+# 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.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.db_engine_specs.databricks import (
+    DatabricksNativeEngineSpec,
+    DatabricksPythonConnectorEngineSpec,
+)
+from superset.superset_typing import OAuth2ClientConfig
+from superset.utils.oauth2 import decode_oauth2_state
+
+# Multi-Cloud Provider Tests
+
+
[email protected]
+def mock_database_aws(mocker: MockerFixture):
+    """
+    Mock database with AWS hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "my-cluster.cloud.databricks.com"
+    database.extra = "{}"
+    database.id = 1
+    return database
+
+
[email protected]
+def mock_database_azure(mocker: MockerFixture):
+    """
+    Mock database with Azure hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "adb-123456789.12.azuredatabricks.net"
+    database.extra = "{}"
+    database.id = 2
+    return database
+
+
[email protected]
+def mock_database_gcp(mocker: MockerFixture):
+    """
+    Mock database with GCP hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "123456789.gcp.databricks.com"
+    database.extra = "{}"
+    database.id = 3
+    return database
+
+
[email protected]
+def oauth2_config() -> OAuth2ClientConfig:
+    """
+    Config for Databricks OAuth2.
+    """
+    return {
+        "id": "databricks-client-id",
+        "secret": "databricks-client-secret",
+        "scope": "sql",
+        "redirect_uri": "http://localhost:8088/api/v1/database/oauth2/";,
+        "authorization_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/authorize";,
+        "token_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/token";,
+        "request_content_type": "json",
+    }
+
+
+def test_cloud_provider_detection_aws(mock_database_aws) -> None:
+    """
+    Test cloud provider detection for AWS.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_aws)
+    assert provider == "aws"
+
+
+def test_cloud_provider_detection_azure(mock_database_azure) -> None:
+    """
+    Test cloud provider detection for Azure.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_azure)
+    assert provider == "azure"
+
+
+def test_cloud_provider_detection_gcp(mock_database_gcp) -> None:
+    """
+    Test cloud provider detection for GCP.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_gcp)
+    assert provider == "gcp"
+
+
+def test_cloud_provider_detection_explicit_config(mocker: MockerFixture) -> 
None:
+    """
+    Test cloud provider detection with explicit configuration.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "generic-host.com"
+
+    # Mock get_extra_params to return explicit cloud provider
+    mocker.patch.object(
+        DatabricksNativeEngineSpec,
+        "get_extra_params",
+        return_value={"cloud_provider": "azure"},
+    )
+
+    provider = DatabricksNativeEngineSpec._detect_cloud_provider(database)
+    assert provider == "azure"
+
+
+def test_get_oauth2_authorization_uri_aws(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_aws,
+) -> None:

Review Comment:
   **Suggestion:** Add a type annotation for the `mock_database_aws` parameter 
in this new test function signature. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The function is newly added and one of its parameters, `mock_database_aws`, 
has no type annotation.
   That violates the rule requiring new Python functions to be fully typed.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8c9d245f436443e3b09ad5d7e1051b7f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8c9d245f436443e3b09ad5d7e1051b7f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
   **Line:** 128:132
   **Comment:**
        *Custom Rule: Add a type annotation for the `mock_database_aws` 
parameter in this new test function signature.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=682e126a0d16ce478a426a5c211e87b366e87422023b8846e32ae34788ff0660&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=682e126a0d16ce478a426a5c211e87b366e87422023b8846e32ae34788ff0660&reaction=dislike'>👎</a>



##########
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py:
##########
@@ -0,0 +1,263 @@
+# 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.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.db_engine_specs.databricks import (
+    DatabricksNativeEngineSpec,
+    DatabricksPythonConnectorEngineSpec,
+)
+from superset.superset_typing import OAuth2ClientConfig
+from superset.utils.oauth2 import decode_oauth2_state
+
+# Multi-Cloud Provider Tests
+
+
[email protected]
+def mock_database_aws(mocker: MockerFixture):
+    """
+    Mock database with AWS hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "my-cluster.cloud.databricks.com"
+    database.extra = "{}"
+    database.id = 1
+    return database
+
+
[email protected]
+def mock_database_azure(mocker: MockerFixture):
+    """
+    Mock database with Azure hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "adb-123456789.12.azuredatabricks.net"
+    database.extra = "{}"
+    database.id = 2
+    return database
+
+
[email protected]
+def mock_database_gcp(mocker: MockerFixture):
+    """
+    Mock database with GCP hostname.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "123456789.gcp.databricks.com"
+    database.extra = "{}"
+    database.id = 3
+    return database
+
+
[email protected]
+def oauth2_config() -> OAuth2ClientConfig:
+    """
+    Config for Databricks OAuth2.
+    """
+    return {
+        "id": "databricks-client-id",
+        "secret": "databricks-client-secret",
+        "scope": "sql",
+        "redirect_uri": "http://localhost:8088/api/v1/database/oauth2/";,
+        "authorization_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/authorize";,
+        "token_request_uri": 
"https://accounts.cloud.databricks.com/oidc/accounts/12345/v1/token";,
+        "request_content_type": "json",
+    }
+
+
+def test_cloud_provider_detection_aws(mock_database_aws) -> None:
+    """
+    Test cloud provider detection for AWS.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_aws)
+    assert provider == "aws"
+
+
+def test_cloud_provider_detection_azure(mock_database_azure) -> None:
+    """
+    Test cloud provider detection for Azure.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_azure)
+    assert provider == "azure"
+
+
+def test_cloud_provider_detection_gcp(mock_database_gcp) -> None:
+    """
+    Test cloud provider detection for GCP.
+    """
+    provider = 
DatabricksNativeEngineSpec._detect_cloud_provider(mock_database_gcp)
+    assert provider == "gcp"
+
+
+def test_cloud_provider_detection_explicit_config(mocker: MockerFixture) -> 
None:
+    """
+    Test cloud provider detection with explicit configuration.
+    """
+    database = mocker.MagicMock()
+    database.url_object.host = "generic-host.com"
+
+    # Mock get_extra_params to return explicit cloud provider
+    mocker.patch.object(
+        DatabricksNativeEngineSpec,
+        "get_extra_params",
+        return_value={"cloud_provider": "azure"},
+    )
+
+    provider = DatabricksNativeEngineSpec._detect_cloud_provider(database)
+    assert provider == "azure"
+
+
+def test_get_oauth2_authorization_uri_aws(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_aws,
+) -> None:
+    """
+    Test OAuth2 authorization URI generation for AWS provider.
+    """
+    from superset.db_engine_specs.base import OAuth2State
+
+    # Mock the database query
+    mocker.patch("superset.extensions.db.session.get", 
return_value=mock_database_aws)
+
+    state: OAuth2State = {
+        "database_id": 1,
+        "user_id": 1,
+        "default_redirect_uri": 
"http://localhost:8088/api/v1/database/oauth2/";,
+        "tab_id": "1234",
+    }
+
+    url = 
DatabricksNativeEngineSpec.get_oauth2_authorization_uri(oauth2_config, state)
+    parsed = urlparse(url)
+    assert parsed.netloc == "accounts.cloud.databricks.com"
+    assert "/oidc/accounts/" in parsed.path
+    assert "/v1/authorize" in parsed.path
+
+    query = parse_qs(parsed.query)
+    assert query["scope"][0] == "sql"
+    encoded_state = query["state"][0].replace("%2E", ".")
+    assert decode_oauth2_state(encoded_state) == state
+
+
+def test_get_oauth2_authorization_uri_azure(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_azure,
+) -> None:
+    """
+    Test OAuth2 authorization URI generation for Azure provider.
+    """
+    from superset.db_engine_specs.base import OAuth2State
+
+    # Mock the database query
+    mocker.patch("superset.extensions.db.session.get", 
return_value=mock_database_azure)
+
+    state: OAuth2State = {
+        "database_id": 2,
+        "user_id": 1,
+        "default_redirect_uri": 
"http://localhost:8088/api/v1/database/oauth2/";,
+        "tab_id": "1234",
+    }
+
+    url = 
DatabricksNativeEngineSpec.get_oauth2_authorization_uri(oauth2_config, state)
+    parsed = urlparse(url)
+    assert parsed.netloc == "login.microsoftonline.com"
+    assert "/oauth2/v2.0/authorize" in parsed.path
+
+    query = parse_qs(parsed.query)
+    assert query["scope"][0] == "sql"
+    encoded_state = query["state"][0].replace("%2E", ".")
+    assert decode_oauth2_state(encoded_state) == state
+
+
+def test_get_oauth2_authorization_uri_gcp(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_gcp,
+) -> None:
+    """
+    Test OAuth2 authorization URI generation for GCP provider.
+    """
+    from superset.db_engine_specs.base import OAuth2State
+
+    # Mock the database query
+    mocker.patch("superset.extensions.db.session.get", 
return_value=mock_database_gcp)
+
+    state: OAuth2State = {
+        "database_id": 3,
+        "user_id": 1,
+        "default_redirect_uri": 
"http://localhost:8088/api/v1/database/oauth2/";,
+        "tab_id": "1234",
+    }
+
+    url = 
DatabricksNativeEngineSpec.get_oauth2_authorization_uri(oauth2_config, state)
+    parsed = urlparse(url)
+    assert parsed.netloc == "accounts.gcp.databricks.com"
+    assert "/oidc/accounts/" in parsed.path
+    assert "/v1/authorize" in parsed.path
+
+    query = parse_qs(parsed.query)
+    assert query["scope"][0] == "sql"
+    encoded_state = query["state"][0].replace("%2E", ".")
+    assert decode_oauth2_state(encoded_state) == state
+
+
+def test_python_connector_cloud_provider_detection_azure(mock_database_azure) 
-> None:
+    """
+    Test cloud provider detection for Python Connector with Azure.
+    """
+    provider = DatabricksPythonConnectorEngineSpec._detect_cloud_provider(
+        mock_database_azure
+    )
+    assert provider == "azure"
+
+
+def test_python_connector_oauth2_authorization_uri_azure(
+    mocker: MockerFixture,
+    oauth2_config: OAuth2ClientConfig,
+    mock_database_azure,
+) -> None:

Review Comment:
   **Suggestion:** Add a type hint for the `mock_database_azure` argument so 
all parameters in this new function are typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The new test function has an untyped parameter, `mock_database_azure`.
   This matches the custom rule that newly added Python functions must be fully 
typed.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dc4defd44ae0461a9618188f74365fb2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=dc4defd44ae0461a9618188f74365fb2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
   **Line:** 233:237
   **Comment:**
        *Custom Rule: Add a type hint for the `mock_database_azure` argument so 
all parameters in this new function are typed.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=153939747572a4f5d67a7a72eba8908fa4faae6c334891d1de9a040f27b4ca19&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34619&comment_hash=153939747572a4f5d67a7a72eba8908fa4faae6c334891d1de9a040f27b4ca19&reaction=dislike'>👎</a>



-- 
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