Lee-W commented on code in PR #59224:
URL: https://github.com/apache/airflow/pull/59224#discussion_r2660835600
##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -263,6 +263,65 @@ def test_get_variable_value_non_existent_key(self,
mock_hvac):
)
assert test_client.get_variable("hello") is None
+
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+ @mock.patch("airflow.utils.log.logging_mixin.structlog.get_logger")
+ def test_get_variable_does_not_contain_value_key(self, mock_hvac,
mock_get_logger):
+ """
+ Test that if the 'value' key is not present in Vault,
_VaultClient.get_variable
+ should log a warning and return None
+ """
+ mock_client = mock.MagicMock()
+ mock_hvac.Client.return_value = mock_client
+ mock_logger = mock.MagicMock()
+ mock_get_logger.return_value = mock_logger
+
+ kwargs = {
+ "variables_path": "variables",
+ "mount_point": "airflow",
+ "auth_type": "token",
+ "url": "http://127.0.0.1:8200",
+ "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+ }
+ test_client = VaultBackend(**kwargs)
+ test_client._log = mock_logger
+ response = {"test_key": "data"}
+ test_client.vault_client.get_secret =
mock.MagicMock(return_value=response)
Review Comment:
```suggestion
test_client = VaultBackend(
**{
"variables_path": "variables",
"mount_point": "airflow",
"auth_type": "token",
"url": "http://127.0.0.1:8200",
"token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
}
)
test_client._log = mock_logger
test_client.vault_client.get_secret =
mock.MagicMock(return_value={"test_key": "data"})
```
##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -263,6 +263,65 @@ def test_get_variable_value_non_existent_key(self,
mock_hvac):
)
assert test_client.get_variable("hello") is None
+
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+ @mock.patch("airflow.utils.log.logging_mixin.structlog.get_logger")
+ def test_get_variable_does_not_contain_value_key(self, mock_hvac,
mock_get_logger):
+ """
+ Test that if the 'value' key is not present in Vault,
_VaultClient.get_variable
+ should log a warning and return None
+ """
+ mock_client = mock.MagicMock()
+ mock_hvac.Client.return_value = mock_client
+ mock_logger = mock.MagicMock()
+ mock_get_logger.return_value = mock_logger
+
+ kwargs = {
+ "variables_path": "variables",
+ "mount_point": "airflow",
+ "auth_type": "token",
+ "url": "http://127.0.0.1:8200",
+ "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+ }
+ test_client = VaultBackend(**kwargs)
+ test_client._log = mock_logger
+ response = {"test_key": "data"}
+ test_client.vault_client.get_secret =
mock.MagicMock(return_value=response)
Review Comment:
some variable are not re-used and thus might not be needed
##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -263,6 +263,65 @@ def test_get_variable_value_non_existent_key(self,
mock_hvac):
)
assert test_client.get_variable("hello") is None
+
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+ @mock.patch("airflow.utils.log.logging_mixin.structlog.get_logger")
+ def test_get_variable_does_not_contain_value_key(self, mock_hvac,
mock_get_logger):
+ """
+ Test that if the 'value' key is not present in Vault,
_VaultClient.get_variable
+ should log a warning and return None
+ """
+ mock_client = mock.MagicMock()
+ mock_hvac.Client.return_value = mock_client
Review Comment:
```suggestion
mock_hvac.Client.return_value = mock.MagicMock()
```
--
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]