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


##########
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
+        ],
+    )

Review Comment:
   Since you added the comments there, I'll leave a nit/suggestion:  you can 
use pytest.param, here if you'd like:
   ```suggestion
       @pytest.mark.parametrize(
           "body",
           [
               pytest.param(None, id="empty_body"),
               pytest.param({"conf": {}},  id="non_empty_body"),
           ],
       )
   ```
   
   When you run the tests with this change, the `id` gets added to the end of 
the test name so it'll show as `test_invoke_rest_api_success_empty_body` and 
`test_invoke_rest_api_success_non_empty_body` when you run the test in pytest 
instead of `test_invoke_rest_api_success_0` and 
`test_invoke_rest_api_success_0`.   It's a littttle more useful.  If you are 
adding the comments anyway, and I agree with that addition, you may as well 
make it part of the useful code too.



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