dstandish commented on code in PR #24737:
URL: https://github.com/apache/airflow/pull/24737#discussion_r924594321


##########
tests/providers/hashicorp/hooks/test_vault.py:
##########
@@ -618,6 +618,33 @@ def test_kubernetes_dejson(self, mock_hvac, 
mock_get_connection):
         test_client.auth_kubernetes.assert_called_with(role="kube_role", 
jwt="data")
         test_client.is_authenticated.assert_called_with()
         assert 2 == test_hook.vault_client.kv_engine_version
+        
+    
@mock.patch("airflow.providers.hashicorp.hooks.vault.VaultHook.get_connection")
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_client_kwargs(self, mock_hvac, mock_get_connection):
+        mock_client = mock.MagicMock()

Review Comment:
   can you add a docstring here just to briefly explain what you're testing in 
this test



##########
tests/providers/hashicorp/hooks/test_vault.py:
##########
@@ -618,6 +618,33 @@ def test_kubernetes_dejson(self, mock_hvac, 
mock_get_connection):
         test_client.auth_kubernetes.assert_called_with(role="kube_role", 
jwt="data")
         test_client.is_authenticated.assert_called_with()
         assert 2 == test_hook.vault_client.kv_engine_version
+        
+    
@mock.patch("airflow.providers.hashicorp.hooks.vault.VaultHook.get_connection")
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_client_kwargs(self, mock_hvac, mock_get_connection):
+        mock_client = mock.MagicMock()
+        mock_hvac.Client.return_value = mock_client
+        mock_connection = self.get_mock_connection()
+        mock_get_connection.return_value = mock_connection
+
+        connection_dict = {
+            "client_kwargs": {
+                "namespace": "name",
+                "timeout": 50,
+            }
+        }
+
+        mock_connection.extra_dejson.get.side_effect = connection_dict.get
+        kwargs = {
+            "vault_conn_id": "vault_conn_id",
+        }
+        with patch("builtins.open", mock_open(read_data="data")) as mock_file:
+            test_hook = VaultHook(**kwargs)
+            test_client = test_hook.get_conn()
+        mock_get_connection.assert_called_with("vault_conn_id")
+        mock_hvac.Client.assert_called_with(url='http://localhost:8180', 
namespace="name", timeout=50)

Review Comment:
   best if you can verify the order of precedence here. not seeing that.



##########
airflow/providers/hashicorp/hooks/vault.py:
##########
@@ -135,6 +136,9 @@ def __init__(
             except ValueError:
                 raise VaultError(f"The version is not an int: {conn_version}. 
")
 
+        if not client_kwargs:
+            client_kwargs = self.connection.extra_dejson.get("client_kwargs", 
{})

Review Comment:
   here you should use `merge_dicts` from airflow.utils.helpers



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