Taragolis commented on code in PR #28850:
URL: https://github.com/apache/airflow/pull/28850#discussion_r1067325568
##########
tests/providers/amazon/aws/triggers/test_redshift_cluster.py:
##########
@@ -0,0 +1,89 @@
+import asyncio
+from unittest import mock
+
+import pytest
+from airflow.triggers.base import TriggerEvent
+
+from airflow.providers.amazon.aws.triggers.redshift_cluster import (
+ RedshiftClusterTrigger,
+)
+
+TASK_ID = "redshift_trigger_check"
+POLLING_PERIOD_SECONDS = 1.0
+
+
+class TestRedshiftClusterTrigger:
+
+ def test_pause_serialization(self):
+ """
+ Asserts that the RedshiftClusterTrigger correctly serializes its
arguments
+ and classpath.
+ """
+ trigger = RedshiftClusterTrigger(
+ task_id=TASK_ID,
+ poll_interval=POLLING_PERIOD_SECONDS,
+ aws_conn_id="test_redshift_conn_id",
+ cluster_identifier="mock_cluster_identifier",
+ operation_type="pause_cluster",
+ )
+ classpath, kwargs = trigger.serialize()
+ assert classpath ==
"airflow.providers.amazon.aws.triggers.redshift_cluster.RedshiftClusterTrigger"
+ assert kwargs == {
+ "task_id": TASK_ID,
+ "poll_interval": POLLING_PERIOD_SECONDS,
+ "aws_conn_id": "test_redshift_conn_id",
+ "cluster_identifier": "mock_cluster_identifier",
+ "operation_type": "pause_cluster",
+ }
+
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize(
+ "operation_type,return_value,response",
+ [
+ (
+ "pause_cluster",
+ {"status": "error", "message": "test error"},
+ TriggerEvent({"status": "error", "message": "test error"}),
+ ),
+ (
+ "pause_cluster",
+ {"status": "success", "cluster_state": "paused"},
+ TriggerEvent({"status": "success", "cluster_state": "paused"}),
+ ),
+ ("pause_cluster", False, TriggerEvent({"status": "error",
"message": f"{TASK_ID} failed"})),
+ ],
+ )
+
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_cluster.RedshiftHookAsync.pause_cluster")
+ async def test_pause_trigger_run(
+ self, mock_pause_cluster, operation_type, return_value, response
+ ):
+ """
+ Test trigger event for the pause_cluster response
+ """
+ mock_pause_cluster.return_value = return_value
+ trigger = RedshiftClusterTrigger(
+ task_id=TASK_ID,
+ poll_interval=POLLING_PERIOD_SECONDS,
+ aws_conn_id="test_redshift_conn_id",
+ cluster_identifier="mock_cluster_identifier",
+ operation_type=operation_type,
+ )
+ generator = trigger.run()
+ actual = await generator.asend(None)
+ assert response == actual
+
+ @pytest.mark.asyncio
+
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_cluster.RedshiftHookAsync.pause_cluster")
Review Comment:
You can't use `unittests.mock.path` in Python 3.7 for asyncio tests because
it is not implementes AsyncMagicMock and AsyncMock
The way how it implemented in Google Provider tests:
https://github.com/apache/airflow/blob/877189916900c930b2c4b92101d46d2f98eb9077/tests/providers/google/cloud/utils/compat.py#L18-L37
--
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]