jedcunningham commented on code in PR #46273:
URL: https://github.com/apache/airflow/pull/46273#discussion_r1934908594
##########
providers/tests/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -976,28 +976,35 @@ async def test_delete_pod(self, lib_method,
kube_config_loader):
@pytest.mark.asyncio
@mock.patch(KUBE_API.format("read_namespaced_pod_log"))
- async def test_read_logs(self, lib_method, kube_config_loader, caplog):
+ async def test_read_logs(self, lib_method, kube_config_loader):
lib_method.return_value = self.mock_await_result("2023-01-11 Some
string logs...")
-
hook = AsyncKubernetesHook(
conn_id=None,
in_cluster=False,
config_file=None,
cluster_context=None,
)
- await hook.read_logs(
- name=POD_NAME,
- namespace=NAMESPACE,
- )
+ with mock.patch(
+
"airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook.log",
+ new_callable=PropertyMock,
+ ) as log:
+ mock_log = mock.MagicMock()
+ log.return_value = mock_log
+ info_method = mock.MagicMock()
+ mock_log.info = info_method
Review Comment:
```suggestion
```
These I mean, since MagicMocks are created by default on first use.
##########
providers/tests/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -976,28 +976,35 @@ async def test_delete_pod(self, lib_method,
kube_config_loader):
@pytest.mark.asyncio
@mock.patch(KUBE_API.format("read_namespaced_pod_log"))
- async def test_read_logs(self, lib_method, kube_config_loader, caplog):
+ async def test_read_logs(self, lib_method, kube_config_loader):
lib_method.return_value = self.mock_await_result("2023-01-11 Some
string logs...")
-
hook = AsyncKubernetesHook(
conn_id=None,
in_cluster=False,
config_file=None,
cluster_context=None,
)
- await hook.read_logs(
- name=POD_NAME,
- namespace=NAMESPACE,
- )
+ with mock.patch(
+
"airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook.log",
+ new_callable=PropertyMock,
+ ) as log:
+ mock_log = mock.MagicMock()
+ log.return_value = mock_log
+ info_method = mock.MagicMock()
+ mock_log.info = info_method
+ await hook.read_logs(
+ name=POD_NAME,
+ namespace=NAMESPACE,
+ )
- lib_method.assert_called_once()
- lib_method.assert_called_with(
- name=POD_NAME,
- namespace=NAMESPACE,
- follow=False,
- timestamps=True,
- )
- assert "Container logs from 2023-01-11 Some string logs..." in
caplog.text
+ lib_method.assert_called_once()
+ lib_method.assert_called_with(
+ name=POD_NAME,
+ namespace=NAMESPACE,
+ follow=False,
+ timestamps=True,
+ )
+ info_method.assert_called_with("Container logs from %s",
"2023-01-11 Some string logs...")
Review Comment:
```suggestion
log.return_value.info.assert_called_with("Container logs from
%s", "2023-01-11 Some string logs...")
```
If you do this, they you can get rid of all of the setup above I believe.
--
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]