vincbeck commented on code in PR #42218:
URL: https://github.com/apache/airflow/pull/42218#discussion_r1773565005


##########
tests/providers/amazon/aws/operators/test_redshift_data.py:
##########
@@ -163,6 +173,58 @@ def test_execute_with_workgroup_name(self, 
mock_exec_query):
             with_event=False,
             wait_for_completion=wait_for_completion,
             poll_interval=poll_interval,
+            session_id=None,
+            session_keep_alive_seconds=None,
+        )
+
+    
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.execute_query")
+    def test_execute_new_session(self, mock_exec_query):
+        cluster_identifier = "cluster_identifier"
+        workgroup_name = None
+        db_user = "db_user"
+        secret_arn = "secret_arn"
+        statement_name = "statement_name"
+        parameters = [{"name": "id", "value": "1"}]
+        poll_interval = 5
+        wait_for_completion = True
+
+        mock_exec_query.return_value = 
QueryExecutionOutput(statement_id=STATEMENT_ID, session_id=SESSION_ID)
+
+        operator = RedshiftDataOperator(
+            aws_conn_id=CONN_ID,
+            task_id=TASK_ID,
+            sql=SQL,
+            database=DATABASE,
+            cluster_identifier=cluster_identifier,
+            db_user=db_user,
+            secret_arn=secret_arn,
+            statement_name=statement_name,
+            parameters=parameters,
+            wait_for_completion=True,
+            poll_interval=poll_interval,
+            session_keep_alive_seconds=123,
+        )
+
+        mock_ti = mock.MagicMock(name="MockedTaskInstance")
+        operator.execute({"ti": mock_ti})
+        mock_exec_query.assert_called_once_with(
+            sql=SQL,
+            database=DATABASE,
+            cluster_identifier=cluster_identifier,
+            workgroup_name=workgroup_name,
+            db_user=db_user,
+            secret_arn=secret_arn,
+            statement_name=statement_name,
+            parameters=parameters,
+            with_event=False,
+            wait_for_completion=wait_for_completion,
+            poll_interval=poll_interval,
+            session_id=None,
+            session_keep_alive_seconds=123,
+        )
+        mock_ti.xcom_push.assert_called_once_with(
+            key="session_id",
+            value=SESSION_ID,
         )

Review Comment:
   This one should work in non-db tests and compat tests
   
   ```suggestion
           assert mock_ti.xcom_push.call_args.kwargs["key"] == "session_id"
           assert mock_ti.xcom_push.call_args.kwargs["value"] == SESSION_ID
   ```



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