ferruzzi commented on code in PR #46579:
URL: https://github.com/apache/airflow/pull/46579#discussion_r1951768225


##########
providers/tests/amazon/aws/hooks/test_mwaa.py:
##########
@@ -0,0 +1,130 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from unittest import mock
+
+import pytest
+from botocore.exceptions import ClientError
+from moto import mock_aws
+
+from airflow.providers.amazon.aws.hooks.mwaa import MwaaHook
+
+ENV_NAME = "test_env"
+PATH = "/dags/test_dag/dagRuns"
+METHOD = "POST"
+QUERY_PARAMS = {"limit": 30}
+
+
+class TestMwaaHook:
+    def setup_method(self):
+        self.hook = MwaaHook()
+
+        # these examples responses are included here instead of as a constant 
because the hook will mutate
+        # responses causing subsequent tests to fail
+        self.example_responses = {
+            "success": {
+                "ResponseMetadata": {
+                    "RequestId": "some ID",
+                    "HTTPStatusCode": 200,
+                    "HTTPHeaders": {"header1": "value1"},
+                    "RetryAttempts": 0,
+                },
+                "RestApiStatusCode": 200,
+                "RestApiResponse": {
+                    "conf": {},
+                    "dag_id": "hello_world",
+                    "dag_run_id": "manual__2025-02-08T00:33:09.457198+00:00",
+                    "data_interval_end": "2025-02-08T00:33:09.457198+00:00",
+                    "data_interval_start": "2025-02-08T00:33:09.457198+00:00",
+                    "execution_date": "2025-02-08T00:33:09.457198+00:00",
+                    "external_trigger": True,
+                    "logical_date": "2025-02-08T00:33:09.457198+00:00",
+                    "run_type": "manual",
+                    "state": "queued",
+                },
+            },
+            "failure": {
+                "Error": {"Message": "", "Code": "RestApiClientException"},
+                "ResponseMetadata": {
+                    "RequestId": "some ID",
+                    "HTTPStatusCode": 400,
+                    "HTTPHeaders": {"header1": "value1"},
+                    "RetryAttempts": 0,
+                },
+                "RestApiStatusCode": 404,
+                "RestApiResponse": {
+                    "detail": "DAG with dag_id: 'hello_world1' not found",
+                    "status": 404,
+                    "title": "DAG not found",
+                    "type": 
"https://airflow.apache.org/docs/apache-airflow/2.10.3/stable-rest-api-ref.html#section/Errors/NotFound";,
+                },
+            },
+        }
+
+    def test_init(self):
+        assert self.hook.client_type == "mwaa"
+
+    @mock_aws
+    def test_get_conn(self):
+        assert self.hook.get_conn() is not None
+
+    @pytest.mark.parametrize(
+        "body",
+        [
+            None,  # test case: empty body
+            {"conf": {}},  # test case: non-empty body
+        ],
+    )
+    @mock.patch.object(MwaaHook, "get_conn")
+    def test_invoke_rest_api_success(self, mock_conn, body) -> None:
+        boto_invoke_mock = 
mock.MagicMock(return_value=self.example_responses["success"])
+        mock_conn.return_value.invoke_rest_api = boto_invoke_mock
+
+        retval = self.hook.invoke_rest_api(ENV_NAME, PATH, METHOD, body, 
QUERY_PARAMS)
+        kwargs_to_assert = {
+            "Name": ENV_NAME,
+            "Path": PATH,
+            "Method": METHOD,
+            "Body": body if body else {},
+            "QueryParameters": QUERY_PARAMS,
+        }
+        boto_invoke_mock.assert_called_once_with(**kwargs_to_assert)
+        assert retval == {
+            k: v for k, v in self.example_responses["success"].items() if k != 
"ResponseMetadata"
+        }
+
+    @mock.patch.object(MwaaHook, "get_conn")

Review Comment:
   IF you end up changing get_conn for conn, remember to make the same changes 
to the tests down here.  If not, just resolve this comment.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to