SameerMesiah97 commented on code in PR #77447:
URL: https://github.com/apache/airflow/pull/77447#discussion_r4654874066


##########
providers/amazon/tests/unit/amazon/aws/hooks/test_mwaa.py:
##########
@@ -205,6 +205,37 @@ def test_invoke_rest_api_using_local_session_token_failure(
         assert caught_error.value == error
         
mock_error_log.assert_called_once_with(example_responses["failure"]["RestApiResponse"])
 
+    @pytest.mark.parametrize(
+        "error_body",
+        [
+            pytest.param(b"<html><body>502 Bad Gateway</body></html>", 
id="html_body"),
+            pytest.param(b"", id="empty_body"),
+        ],
+    )
+    @mock.patch.object(MwaaHook, "_get_session_conn")
+    def test_invoke_rest_api_using_local_session_token_failure_non_json_body(
+        self, mock_get_session_conn, error_body
+    ):
+        response = requests.Response()
+        response.status_code = 502
+        response.url = f"https://{HOSTNAME}/api/v1{PATH}";
+        response._content = error_body
+
+        mock_session = mock.MagicMock(spec=requests.Session)
+        mock_session.request.return_value = response
+        mock_get_session_conn.return_value = (mock_session, HOSTNAME, None)
+
+        mock_error_log = mock.MagicMock()
+        self.hook.log.error = mock_error_log
+
+        with pytest.raises(requests.HTTPError) as caught_error:
+            self.hook.invoke_rest_api(
+                env_name=ENV_NAME, path=PATH, method=METHOD, 
generate_local_token=True, airflow_version=2
+            )
+
+        assert caught_error.value.response.status_code == 502

Review Comment:
   nit: you could add the below:
   
   `assert caught_error.value.response is response`



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