This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1a7a67f134 Resolve aws provider deprecations in tests (#40123)
1a7a67f134 is described below

commit 1a7a67f134e6ed8177a074d73168a6853c04641f
Author: Gopal Dirisala <[email protected]>
AuthorDate: Mon Jun 10 20:21:55 2024 +0530

    Resolve aws provider deprecations in tests (#40123)
---
 tests/deprecations_ignore.yml                      |  4 --
 .../amazon/aws/operators/test_base_aws.py          |  5 +-
 tests/providers/amazon/aws/operators/test_batch.py | 36 +++++++++++----
 tests/providers/amazon/aws/operators/test_eks.py   | 53 ++++++++++++++++------
 .../providers/amazon/aws/sensors/test_base_aws.py  |  5 +-
 5 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/tests/deprecations_ignore.yml b/tests/deprecations_ignore.yml
index 4eb460674c..3544bbc786 100644
--- a/tests/deprecations_ignore.yml
+++ b/tests/deprecations_ignore.yml
@@ -99,14 +99,10 @@
 - 
tests/providers/amazon/aws/deferrable/hooks/test_redshift_cluster.py::TestRedshiftAsyncHook::test_resume_cluster_exception
 - 
tests/providers/amazon/aws/operators/test_appflow.py::test_base_aws_op_attributes
 - tests/providers/amazon/aws/operators/test_appflow.py::test_run
-- 
tests/providers/amazon/aws/operators/test_base_aws.py::TestAwsBaseOperator::test_conflicting_region_name
-- 
tests/providers/amazon/aws/operators/test_batch.py::TestBatchOperator::test_override_not_sent_if_not_set
-- 
tests/providers/amazon/aws/operators/test_eks.py::TestEksPodOperator::test_on_finish_action_handler
 - 
tests/providers/amazon/aws/secrets/test_secrets_manager.py::TestSecretsManagerBackend::test_get_conn_value_broken_field_mode
 - 
tests/providers/amazon/aws/secrets/test_secrets_manager.py::TestSecretsManagerBackend::test_get_conn_value_broken_field_mode_extra_words_added
 - 
tests/providers/amazon/aws/secrets/test_secrets_manager.py::TestSecretsManagerBackend::test_get_connection_broken_field_mode_extra_allows_nested_json
 - 
tests/providers/amazon/aws/secrets/test_secrets_manager.py::TestSecretsManagerBackend::test_get_connection_broken_field_mode_url_encoding
-- 
tests/providers/amazon/aws/sensors/test_base_aws.py::TestAwsBaseSensor::test_conflicting_region_name
 - 
tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_exception
 - 
tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_resuming_status
 - 
tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_success
diff --git a/tests/providers/amazon/aws/operators/test_base_aws.py 
b/tests/providers/amazon/aws/operators/test_base_aws.py
index 687a5ba3c0..ab5f07e429 100644
--- a/tests/providers/amazon/aws/operators/test_base_aws.py
+++ b/tests/providers/amazon/aws/operators/test_base_aws.py
@@ -144,7 +144,10 @@ class TestAwsBaseOperator:
 
     def test_conflicting_region_name(self):
         error_match = r"Conflicting `region_name` provided, 
region_name='us-west-1', region='eu-west-1'"
-        with pytest.raises(ValueError, match=error_match):
+        with pytest.raises(ValueError, match=error_match), pytest.warns(
+            AirflowProviderDeprecationWarning,
+            match="`region` is deprecated and will be removed in the future. 
Please use `region_name` instead.",
+        ):
             FakeS3Operator(
                 task_id="fake-task-id",
                 aws_conn_id=TEST_CONN,
diff --git a/tests/providers/amazon/aws/operators/test_batch.py 
b/tests/providers/amazon/aws/operators/test_batch.py
index 27f86e279c..137044a212 100644
--- a/tests/providers/amazon/aws/operators/test_batch.py
+++ b/tests/providers/amazon/aws/operators/test_batch.py
@@ -307,16 +307,32 @@ class TestBatchOperator:
         in the API call (which would create a validation error from boto)
         """
         override_arg = {override: {"a": "a"}}
-        batch = BatchOperator(
-            task_id="task",
-            job_name=JOB_NAME,
-            job_queue="queue",
-            job_definition="hello-world",
-            **override_arg,
-            # setting those to bypass code that is not relevant here
-            do_xcom_push=False,
-            wait_for_completion=False,
-        )
+        if override == "overrides":
+            with pytest.warns(
+                AirflowProviderDeprecationWarning,
+                match="Parameter `overrides` is deprecated, Please use 
`container_overrides` instead.",
+            ):
+                batch = BatchOperator(
+                    task_id="task",
+                    job_name=JOB_NAME,
+                    job_queue="queue",
+                    job_definition="hello-world",
+                    **override_arg,
+                    # setting those to bypass code that is not relevant here
+                    do_xcom_push=False,
+                    wait_for_completion=False,
+                )
+        else:
+            batch = BatchOperator(
+                task_id="task",
+                job_name=JOB_NAME,
+                job_queue="queue",
+                job_definition="hello-world",
+                **override_arg,
+                # setting those to bypass code that is not relevant here
+                do_xcom_push=False,
+                wait_for_completion=False,
+            )
 
         batch.execute(None)
 
diff --git a/tests/providers/amazon/aws/operators/test_eks.py 
b/tests/providers/amazon/aws/operators/test_eks.py
index b813afe2c2..9571ca0962 100644
--- a/tests/providers/amazon/aws/operators/test_eks.py
+++ b/tests/providers/amazon/aws/operators/test_eks.py
@@ -23,7 +23,7 @@ from unittest import mock
 import pytest
 from botocore.waiter import Waiter
 
-from airflow.exceptions import TaskDeferred
+from airflow.exceptions import AirflowProviderDeprecationWarning, TaskDeferred
 from airflow.providers.amazon.aws.hooks.eks import ClusterStates, EksHook
 from airflow.providers.amazon.aws.operators.eks import (
     EksCreateClusterOperator,
@@ -687,56 +687,83 @@ class TestEksPodOperator:
         assert mock_generate_config_file.return_value.__enter__.return_value 
== op.config_file
 
     @pytest.mark.parametrize(
-        "compatible_kpo, kwargs, expected_attributes",
+        "compatible_kpo, kwargs, expected_attributes, warning, 
warning_message",
         [
             (
                 True,
                 {"on_finish_action": "delete_succeeded_pod"},
                 {"on_finish_action": OnFinishAction.DELETE_SUCCEEDED_POD},
+                False,
+                None,
             ),
             (
                 # test that priority for deprecated param
                 True,
                 {"on_finish_action": "keep_pod", "is_delete_operator_pod": 
True},
                 {"on_finish_action": OnFinishAction.DELETE_POD, 
"is_delete_operator_pod": True},
+                True,
+                "`is_delete_operator_pod` parameter is deprecated, please use 
`on_finish_action`",
             ),
             (
                 # test default
                 True,
                 {},
                 {"on_finish_action": OnFinishAction.KEEP_POD, 
"is_delete_operator_pod": False},
+                True,
+                "You have not set parameter `on_finish_action` in class 
EksPodOperator. Currently the default for this parameter is `keep_pod` but in a 
future release the default will be changed to `delete_pod`. To ensure pods are 
not deleted in the future you will need to set `on_finish_action=keep_pod` 
explicitly.",
             ),
             (
                 False,
                 {"is_delete_operator_pod": True},
                 {"is_delete_operator_pod": True},
+                True,
+                "`is_delete_operator_pod` parameter is deprecated, please use 
`on_finish_action`",
             ),
             (
                 False,
                 {"is_delete_operator_pod": False},
                 {"is_delete_operator_pod": False},
+                True,
+                "`is_delete_operator_pod` parameter is deprecated, please use 
`on_finish_action`",
             ),
             (
                 # test default
                 False,
                 {},
                 {"is_delete_operator_pod": False},
+                True,
+                "You have not set parameter `on_finish_action` in class 
EksPodOperator. Currently the default for this parameter is `keep_pod` but in a 
future release the default will be changed to `delete_pod`. To ensure pods are 
not deleted in the future you will need to set `on_finish_action=keep_pod` 
explicitly.",
             ),
         ],
     )
-    def test_on_finish_action_handler(self, compatible_kpo, kwargs, 
expected_attributes):
+    def test_on_finish_action_handler(
+        self, compatible_kpo, kwargs, expected_attributes, warning, 
warning_message
+    ):
         kpo_init_args_mock = mock.MagicMock(**{"parameters": 
["on_finish_action"] if compatible_kpo else []})
 
         with mock.patch("inspect.signature", return_value=kpo_init_args_mock):
-            op = EksPodOperator(
-                task_id="run_pod",
-                pod_name="run_pod",
-                cluster_name=CLUSTER_NAME,
-                image="amazon/aws-cli:latest",
-                cmds=["sh", "-c", "ls"],
-                labels={"demo": "hello_world"},
-                get_logs=True,
-                **kwargs,
-            )
+            if warning:
+                with pytest.warns(AirflowProviderDeprecationWarning, 
match=warning_message):
+                    op = EksPodOperator(
+                        task_id="run_pod",
+                        pod_name="run_pod",
+                        cluster_name=CLUSTER_NAME,
+                        image="amazon/aws-cli:latest",
+                        cmds=["sh", "-c", "ls"],
+                        labels={"demo": "hello_world"},
+                        get_logs=True,
+                        **kwargs,
+                    )
+            else:
+                op = EksPodOperator(
+                    task_id="run_pod",
+                    pod_name="run_pod",
+                    cluster_name=CLUSTER_NAME,
+                    image="amazon/aws-cli:latest",
+                    cmds=["sh", "-c", "ls"],
+                    labels={"demo": "hello_world"},
+                    get_logs=True,
+                    **kwargs,
+                )
             for expected_attr in expected_attributes:
                 assert op.__getattribute__(expected_attr) == 
expected_attributes[expected_attr]
diff --git a/tests/providers/amazon/aws/sensors/test_base_aws.py 
b/tests/providers/amazon/aws/sensors/test_base_aws.py
index 7b52bc24c3..a080abf005 100644
--- a/tests/providers/amazon/aws/sensors/test_base_aws.py
+++ b/tests/providers/amazon/aws/sensors/test_base_aws.py
@@ -146,7 +146,10 @@ class TestAwsBaseSensor:
 
     def test_conflicting_region_name(self):
         error_match = r"Conflicting `region_name` provided, 
region_name='us-west-1', region='eu-west-1'"
-        with pytest.raises(ValueError, match=error_match):
+        with pytest.raises(ValueError, match=error_match), pytest.warns(
+            AirflowProviderDeprecationWarning,
+            match="`region` is deprecated and will be removed in the future. 
Please use `region_name` instead.",
+        ):
             FakeDynamoDBSensor(
                 task_id="fake-task-id",
                 aws_conn_id=TEST_CONN,

Reply via email to