pierrejeambrun commented on code in PR #59643:
URL: https://github.com/apache/airflow/pull/59643#discussion_r2694477413


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -992,14 +992,85 @@ def test_connection_env_is_cleaned_after_run(self, 
test_client, body):
             {"connection_id": TEST_CONN_ID, "conn_type": "ftp"},
         ],
     )
-    def test_should_respond_403_by_default(self, test_client, body):
+    
@mock.patch("airflow.api_fastapi.core_api.routes.public.connections.conf.get")
+    def test_should_respond_403_by_default(self, mock_conf_get, test_client, 
body):
+        mock_conf_get.return_value = "Disabled"

Review Comment:
   Why is that needed. By default this is "Disabled", you shouldn't need that.
   
   Probably a local conf or something interfering with the tests, your change 
doesn't seem to impact this.



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -992,14 +992,85 @@ def test_connection_env_is_cleaned_after_run(self, 
test_client, body):
             {"connection_id": TEST_CONN_ID, "conn_type": "ftp"},
         ],
     )
-    def test_should_respond_403_by_default(self, test_client, body):
+    
@mock.patch("airflow.api_fastapi.core_api.routes.public.connections.conf.get")
+    def test_should_respond_403_by_default(self, mock_conf_get, test_client, 
body):
+        mock_conf_get.return_value = "Disabled"
         response = test_client.post("/connections/test", json=body)
         assert response.status_code == 403
         assert response.json() == {
             "detail": "Testing connections is disabled in Airflow 
configuration. "
             "Contact your deployment admin to enable it."
         }
 
+    @mock.patch.dict(os.environ, {"AIRFLOW__CORE__TEST_CONNECTION": "Enabled"})
+    def test_should_merge_password_with_existing_connection(self, test_client, 
session):
+        connection = Connection(
+            conn_id=TEST_CONN_ID,
+            conn_type="sqlite",
+            password="existing_password",
+        )
+        session.add(connection)
+        session.commit()
+
+        body = {
+            "connection_id": TEST_CONN_ID,
+            "conn_type": "sqlite",
+            "password": "***",
+        }

Review Comment:
   How does this test that the password used is actually "existing_password" 
and not "***" when performing the `conn.test_connection` ?



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -992,14 +992,85 @@ def test_connection_env_is_cleaned_after_run(self, 
test_client, body):
             {"connection_id": TEST_CONN_ID, "conn_type": "ftp"},
         ],
     )
-    def test_should_respond_403_by_default(self, test_client, body):
+    
@mock.patch("airflow.api_fastapi.core_api.routes.public.connections.conf.get")
+    def test_should_respond_403_by_default(self, mock_conf_get, test_client, 
body):
+        mock_conf_get.return_value = "Disabled"
         response = test_client.post("/connections/test", json=body)
         assert response.status_code == 403
         assert response.json() == {
             "detail": "Testing connections is disabled in Airflow 
configuration. "
             "Contact your deployment admin to enable it."
         }
 
+    @mock.patch.dict(os.environ, {"AIRFLOW__CORE__TEST_CONNECTION": "Enabled"})
+    def test_should_merge_password_with_existing_connection(self, test_client, 
session):
+        connection = Connection(
+            conn_id=TEST_CONN_ID,
+            conn_type="sqlite",
+            password="existing_password",
+        )
+        session.add(connection)
+        session.commit()
+
+        body = {
+            "connection_id": TEST_CONN_ID,
+            "conn_type": "sqlite",
+            "password": "***",
+        }
+        response = test_client.post("/connections/test", json=body)
+        assert response.status_code == 200
+        assert response.json()["status"] is True

Review Comment:
   I would also add an assertion to check that hte `TEST_CONN_ID` wasn't 
mutated into db, and that no other connection record was created. (I.e the 
merged connection is not persisted anywhere)



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -992,14 +992,85 @@ def test_connection_env_is_cleaned_after_run(self, 
test_client, body):
             {"connection_id": TEST_CONN_ID, "conn_type": "ftp"},
         ],
     )
-    def test_should_respond_403_by_default(self, test_client, body):
+    
@mock.patch("airflow.api_fastapi.core_api.routes.public.connections.conf.get")
+    def test_should_respond_403_by_default(self, mock_conf_get, test_client, 
body):
+        mock_conf_get.return_value = "Disabled"
         response = test_client.post("/connections/test", json=body)
         assert response.status_code == 403
         assert response.json() == {
             "detail": "Testing connections is disabled in Airflow 
configuration. "
             "Contact your deployment admin to enable it."
         }
 
+    @mock.patch.dict(os.environ, {"AIRFLOW__CORE__TEST_CONNECTION": "Enabled"})
+    def test_should_merge_password_with_existing_connection(self, test_client, 
session):
+        connection = Connection(
+            conn_id=TEST_CONN_ID,
+            conn_type="sqlite",
+            password="existing_password",
+        )
+        session.add(connection)
+        session.commit()
+
+        body = {
+            "connection_id": TEST_CONN_ID,
+            "conn_type": "sqlite",
+            "password": "***",
+        }
+        response = test_client.post("/connections/test", json=body)
+        assert response.status_code == 200
+        assert response.json()["status"] is True
+
+    @mock.patch.dict(os.environ, {"AIRFLOW__CORE__TEST_CONNECTION": "Enabled"})
+    def test_should_merge_extra_with_existing_connection(self, test_client, 
session):
+        connection = Connection(
+            conn_id=TEST_CONN_ID,
+            conn_type="fs",
+            extra='{"path": "/", "existing_key": "existing_value"}',
+        )
+        session.add(connection)
+        session.commit()
+
+        body = {
+            "connection_id": TEST_CONN_ID,
+            "conn_type": "fs",
+            "extra": '{"path": "/", "new_key": "new_value"}',
+        }

Review Comment:
   Same here, how do we now the "new_key" is taken into account?



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

Reply via email to