rusackas commented on code in PR #41421: URL: https://github.com/apache/superset/pull/41421#discussion_r3473550352
########## 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: Good call — added the return type annotation. Thanks! ########## 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): Review Comment: Good call — added the return type annotation. Thanks! ########## 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): Review Comment: Good call — added the return type annotation. Thanks! ########## 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: Yep — typed the fixture parameter. Thanks! ########## 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: Review Comment: Yep — typed the fixture parameter. Thanks! -- 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]
