This is an automated email from the ASF dual-hosted git repository.
amoghdesai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new b24de014798 Migrate cloudant connection UI metadata to YAML (#62744)
b24de014798 is described below
commit b24de0147986aa8822a5f244f959f07615ba5146
Author: Ying-Fang (James) Jaw <[email protected]>
AuthorDate: Mon Mar 16 04:53:46 2026 -0500
Migrate cloudant connection UI metadata to YAML (#62744)
* Migrate cloudant connection UI metadata to YAML
* Fix cloudant hook tests failing in non-DB test environment
Defer Connection() instantiation from module-load time to
test-execution time to avoid triggering SQLAlchemy mapper
initialization before all models are registered.
- Move Connection() from @patch decorator to with-patch context manager
- Replace Connection() objects in @pytest.mark.parametrize with kwargs
dicts, instantiating Connection inside the test body
This follows the same pattern used by other provider tests (e.g.,
apache-hdfs, asana) and fixes collection errors when running with
--skip-db-tests --backend none.
---------
Co-authored-by: Amogh Desai <[email protected]>
---
providers/cloudant/provider.yaml | 8 ++++
.../providers/cloudant/get_provider_info.py | 4 ++
.../tests/unit/cloudant/hooks/test_cloudant.py | 44 +++++++++++-----------
3 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/providers/cloudant/provider.yaml b/providers/cloudant/provider.yaml
index 5f3d34e3eef..f62bf66e221 100644
--- a/providers/cloudant/provider.yaml
+++ b/providers/cloudant/provider.yaml
@@ -75,3 +75,11 @@ hooks:
connection-types:
- hook-class-name: airflow.providers.cloudant.hooks.cloudant.CloudantHook
connection-type: cloudant
+ ui-field-behaviour:
+ hidden-fields:
+ - schema
+ - port
+ - extra
+ relabeling:
+ host: Account
+ login: Username (or API Key)
diff --git
a/providers/cloudant/src/airflow/providers/cloudant/get_provider_info.py
b/providers/cloudant/src/airflow/providers/cloudant/get_provider_info.py
index bd2da86d920..e806ab26ce3 100644
--- a/providers/cloudant/src/airflow/providers/cloudant/get_provider_info.py
+++ b/providers/cloudant/src/airflow/providers/cloudant/get_provider_info.py
@@ -44,6 +44,10 @@ def get_provider_info():
{
"hook-class-name":
"airflow.providers.cloudant.hooks.cloudant.CloudantHook",
"connection-type": "cloudant",
+ "ui-field-behaviour": {
+ "hidden-fields": ["schema", "port", "extra"],
+ "relabeling": {"host": "Account", "login": "Username (or
API Key)"},
+ },
}
],
}
diff --git a/providers/cloudant/tests/unit/cloudant/hooks/test_cloudant.py
b/providers/cloudant/tests/unit/cloudant/hooks/test_cloudant.py
index e1dad2e2ec4..6fd37313f5a 100644
--- a/providers/cloudant/tests/unit/cloudant/hooks/test_cloudant.py
+++ b/providers/cloudant/tests/unit/cloudant/hooks/test_cloudant.py
@@ -32,41 +32,41 @@ class TestCloudantHook:
def setup_method(self):
self.cloudant_hook = CloudantHook()
- @patch(
-
"airflow.providers.cloudant.hooks.cloudant.CloudantHook.get_connection",
- return_value=Connection(login="the_user", password="the_password",
host="the_account"),
- )
@patch("airflow.providers.cloudant.hooks.cloudant.CouchDbSessionAuthenticator")
@patch("airflow.providers.cloudant.hooks.cloudant.CloudantV1")
def test_get_conn_passes_expected_params_and_returns_cloudant_object(
- self, mock_cloudant_v1, mock_session_authenticator, mock_get_connection
+ self, mock_cloudant_v1, mock_session_authenticator
):
- cloudant_session = self.cloudant_hook.get_conn()
+ with patch(
+
"airflow.providers.cloudant.hooks.cloudant.CloudantHook.get_connection",
+ return_value=Connection(login="the_user", password="the_password",
host="the_account"),
+ ) as mock_get_connection:
+ cloudant_session = self.cloudant_hook.get_conn()
- conn = mock_get_connection.return_value
+ conn = mock_get_connection.return_value
-
mock_session_authenticator.assert_called_once_with(username=conn.login,
password=conn.password)
-
mock_cloudant_v1.assert_called_once_with(authenticator=mock_session_authenticator.return_value)
+
mock_session_authenticator.assert_called_once_with(username=conn.login,
password=conn.password)
+
mock_cloudant_v1.assert_called_once_with(authenticator=mock_session_authenticator.return_value)
- cloudant_service = mock_cloudant_v1.return_value
-
cloudant_service.set_service_url.assert_called_once_with(f"https://{conn.host}.cloudant.com")
+ cloudant_service = mock_cloudant_v1.return_value
+
cloudant_service.set_service_url.assert_called_once_with(f"https://{conn.host}.cloudant.com")
- assert cloudant_session == cloudant_service
+ assert cloudant_session == cloudant_service
@pytest.mark.parametrize(
- "conn",
+ "conn_kwargs",
[
- Connection(),
- Connection(host="acct"),
- Connection(login="user"),
- Connection(password="pwd"),
- Connection(host="acct", login="user"),
- Connection(host="acct", password="pwd"),
- Connection(login="user", password="pwd"),
+ {},
+ {"host": "acct"},
+ {"login": "user"},
+ {"password": "pwd"},
+ {"host": "acct", "login": "user"},
+ {"host": "acct", "password": "pwd"},
+ {"login": "user", "password": "pwd"},
],
)
@patch("airflow.providers.cloudant.hooks.cloudant.CloudantHook.get_connection")
- def test_get_conn_invalid_connection(self, mock_get_connection, conn):
- mock_get_connection.return_value = conn
+ def test_get_conn_invalid_connection(self, mock_get_connection,
conn_kwargs):
+ mock_get_connection.return_value = Connection(**conn_kwargs)
with pytest.raises(AirflowException):
self.cloudant_hook.get_conn()