This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch test-ssh-tunnel-1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit cead0e67ce4e171fc53d724837410666f5ae773b
Author: Antonio Rivero <[email protected]>
AuthorDate: Tue Nov 29 16:01:58 2022 -0300

    SSH Tunnel:
    
    - Remove bind properties from schema used in TestConnection
    - Add test for SSH Tunnel failure and no DB creation
---
 superset/databases/schemas.py                  |  4 ---
 tests/integration_tests/databases/api_tests.py | 45 ++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py
index ff134eb0af..8cf6f01597 100644
--- a/superset/databases/schemas.py
+++ b/superset/databases/schemas.py
@@ -380,10 +380,6 @@ class DatabaseSSHTunnel(Schema):
     private_key = fields.String(required=False)
     private_key_password = fields.String(required=False)
 
-    # remote binding port
-    bind_host = fields.String()
-    bind_port = fields.Integer()
-
 
 class DatabasePostSchema(Schema, DatabaseParametersSchemaMixin):
     class Meta:  # pylint: disable=too-few-public-methods
diff --git a/tests/integration_tests/databases/api_tests.py 
b/tests/integration_tests/databases/api_tests.py
index 24a503ae91..4eb1f9ebd4 100644
--- a/tests/integration_tests/databases/api_tests.py
+++ b/tests/integration_tests/databases/api_tests.py
@@ -485,6 +485,51 @@ class TestDatabaseApi(SupersetTestCase):
         )
         assert model_ssh_tunnel is None
 
+    @mock.patch(
+        
"superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run",
+    )
+    def test_do_not_create_database_if_ssh_tunnel_creation_fails(
+        self, mock_test_connection_database_command_run
+    ):
+        """
+        Database API: Test create with SSH Tunnel
+        """
+        self.login(username="admin")
+        example_db = get_example_database()
+        if example_db.backend == "sqlite":
+            return
+        ssh_tunnel_properties = {
+            "server_address_failure": "123.132.123.1",
+        }
+        database_data = {
+            "database_name": "test-db-failure-ssh-tunnel",
+            "sqlalchemy_uri": example_db.sqlalchemy_uri_decrypted,
+            "ssh_tunnel": ssh_tunnel_properties,
+        }
+        fail_message = {
+            "message": {"ssh_tunnel": {"server_address_failure": ["Unknown 
field."]}}
+        }
+
+        uri = "api/v1/database/"
+        rv = self.client.post(uri, json=database_data)
+        response = json.loads(rv.data.decode("utf-8"))
+        self.assertEqual(rv.status_code, 400)
+        model_ssh_tunnel = (
+            db.session.query(SSHTunnel)
+            .filter(SSHTunnel.database_id == response.get("id"))
+            .one_or_none()
+        )
+        assert model_ssh_tunnel is None
+        self.assertEqual(response, fail_message)
+        # Cleanup
+        model = (
+            db.session.query(Database)
+            .filter(Database.database_name == "test-db-failure-ssh-tunnel")
+            .one_or_none()
+        )
+        # the DB should not be created
+        assert model is None
+
     def test_create_database_invalid_configuration_method(self):
         """
         Database API: Test create with an invalid configuration method.

Reply via email to