This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-3-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit f50ef221d8311d4f7100cdeb2c8706a9d4352859 Author: Jed Cunningham <[email protected]> AuthorDate: Fri Apr 29 04:29:02 2022 -0600 Fix connection test button (#23345) The connection test button was always disabled if any of your hooks had import errors, for example because of a missing module. This handles that scenario. (cherry picked from commit f197030cea860351da07894879f647fe76c5751e) --- airflow/www/views.py | 4 ++-- tests/www/views/test_views_connection.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index f73b8107b9..9bdd761022 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -3867,8 +3867,8 @@ class ConnectionFormWidget(FormWidget): def testable_connection_types(self): return [ connection_type - for connection_type, provider_info in ProvidersManager().hooks.items() - if provider_info.connection_testable + for connection_type, hook_info in ProvidersManager().hooks.items() + if hook_info and hook_info.connection_testable ] diff --git a/tests/www/views/test_views_connection.py b/tests/www/views/test_views_connection.py index 8c5ff0d013..d71a8a63c0 100644 --- a/tests/www/views/test_views_connection.py +++ b/tests/www/views/test_views_connection.py @@ -25,7 +25,7 @@ from pytest import param from airflow.models import Connection from airflow.utils.session import create_session from airflow.www.extensions import init_views -from airflow.www.views import ConnectionModelView +from airflow.www.views import ConnectionFormWidget, ConnectionModelView from tests.test_utils.www import check_content_in_response CONNECTION = { @@ -311,3 +311,14 @@ def test_connection_muldelete(admin_client, connection): assert resp.status_code == 200 with create_session() as session: assert session.query(Connection).filter(Connection.id == conn_id).count() == 0 + + [email protected]('airflow.providers_manager.ProvidersManager.hooks', new_callable=PropertyMock) +def test_connection_form_widgets_testable_types(mock_pm_hooks, admin_client): + mock_pm_hooks.return_value = { + "first": mock.MagicMock(connection_testable=True), + "second": mock.MagicMock(connection_testable=False), + "third": None, + } + + assert ["first"] == ConnectionFormWidget().testable_connection_types
