sunank200 commented on code in PR #32715:
URL: https://github.com/apache/airflow/pull/32715#discussion_r1269585073


##########
tests/providers/http/hooks/test_http.py:
##########
@@ -432,125 +439,98 @@ def test_keep_alive_disabled(self):
             http_send.assert_called()
 
 
-send_email_test = mock.Mock()
-
-
[email protected]
-def aioresponse():
-    """
-    Creates an mock async API response.
-    This comes from a mock library specific to the aiohttp package:
-    https://github.com/pnuckowski/aioresponses
-
-    """
-    with aioresponses() as async_response:
-        yield async_response
-
-
[email protected]
-async def test_do_api_call_async_non_retryable_error(aioresponse):
-    """Test api call asynchronously with non retryable error."""
-    hook = HttpAsyncHook(method="GET")
-    aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=400)
-
-    with pytest.raises(AirflowException) as exc, mock.patch.dict(
-        "os.environ",
-        AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
-    ):
-        await hook.run(endpoint="non_existent_endpoint")
-
-    assert str(exc.value) == "400:Bad Request"
+class TestHttpAsyncHook:
+    @pytest.mark.asyncio
+    async def test_do_api_call_async_non_retryable_error(self, aioresponse):
+        """Test api call asynchronously with non retryable error."""
+        hook = HttpAsyncHook(method="GET")
+        aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=400)
 
+        with pytest.raises(AirflowException) as exc, mock.patch.dict(
+            "os.environ",
+            AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
+        ):
+            await hook.run(endpoint="non_existent_endpoint")
 
[email protected]
-async def test_do_api_call_async_retryable_error(caplog, aioresponse):
-    """Test api call asynchronously with retryable error."""
-    caplog.set_level(logging.WARNING, 
logger="airflow.providers.http.hooks.http")
-    hook = HttpAsyncHook(method="GET")
-    aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=500, 
repeat=True)
-
-    with pytest.raises(AirflowException) as exc, mock.patch.dict(
-        "os.environ",
-        AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
-    ):
-        await hook.run(endpoint="non_existent_endpoint")
-
-    assert str(exc.value) == "500:Internal Server Error"
-    assert "[Try 3 of 3] Request to http://httpbin.org/non_existent_endpoint 
failed" in caplog.text
-
+        assert str(exc.value) == "400:Bad Request"
 
[email protected]
-async def test_do_api_call_async_unknown_method():
-    """Test api call asynchronously for unknown method."""
-    hook = HttpAsyncHook(method="NOPE")
-    json = {
-        "existing_cluster_id": "xxxx-xxxxxx-xxxxxx",
-    }
+    @pytest.mark.asyncio
+    async def test_do_api_call_async_retryable_error(self, caplog, 
aioresponse):
+        """Test api call asynchronously with retryable error."""
+        caplog.set_level(logging.WARNING, 
logger="airflow.providers.http.hooks.http")
+        hook = HttpAsyncHook(method="GET")
+        aioresponse.get("http://httpbin.org/non_existent_endpoint";, 
status=500, repeat=True)
 
-    with pytest.raises(AirflowException) as exc:
-        await hook.run(endpoint="non_existent_endpoint", data=json)
+        with pytest.raises(AirflowException) as exc, mock.patch.dict(
+            "os.environ",
+            AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
+        ):
+            await hook.run(endpoint="non_existent_endpoint")
 
-    assert str(exc.value) == "Unexpected HTTP Method: NOPE"
+        assert str(exc.value) == "500:Internal Server Error"
+        assert "[Try 3 of 3] Request to 
http://httpbin.org/non_existent_endpoint failed" in caplog.text
 
+    @pytest.mark.asyncio
+    async def test_do_api_call_async_unknown_method(self):
+        """Test api call asynchronously for unknown http method."""
+        hook = HttpAsyncHook(method="NOPE")
+        json = {"existing_cluster_id": "xxxx-xxxxxx-xxxxxx"}
 
[email protected]
-async def test_async_post_request(aioresponse):
-    """Test api call asynchronously for POST request."""
-    hook = HttpAsyncHook()
+        with pytest.raises(AirflowException) as exc:

Review Comment:
   nit: you can `match` in `pytest.raises()` here instead of asserting later. 
Example:
   
   ```
   def func(x):
     if x == 5:
       raise ValueError("x must be a value other than 5")
     return x
   
   def test_func():
     with pytest.raises(ValueError, match="x must be a value other than 5"):
       func(5)
   ```



##########
tests/providers/http/hooks/test_http.py:
##########
@@ -432,125 +439,98 @@ def test_keep_alive_disabled(self):
             http_send.assert_called()
 
 
-send_email_test = mock.Mock()
-
-
[email protected]
-def aioresponse():
-    """
-    Creates an mock async API response.
-    This comes from a mock library specific to the aiohttp package:
-    https://github.com/pnuckowski/aioresponses
-
-    """
-    with aioresponses() as async_response:
-        yield async_response
-
-
[email protected]
-async def test_do_api_call_async_non_retryable_error(aioresponse):
-    """Test api call asynchronously with non retryable error."""
-    hook = HttpAsyncHook(method="GET")
-    aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=400)
-
-    with pytest.raises(AirflowException) as exc, mock.patch.dict(
-        "os.environ",
-        AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
-    ):
-        await hook.run(endpoint="non_existent_endpoint")
-
-    assert str(exc.value) == "400:Bad Request"
+class TestHttpAsyncHook:
+    @pytest.mark.asyncio
+    async def test_do_api_call_async_non_retryable_error(self, aioresponse):
+        """Test api call asynchronously with non retryable error."""
+        hook = HttpAsyncHook(method="GET")
+        aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=400)
 
+        with pytest.raises(AirflowException) as exc, mock.patch.dict(
+            "os.environ",
+            AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
+        ):
+            await hook.run(endpoint="non_existent_endpoint")
 
[email protected]
-async def test_do_api_call_async_retryable_error(caplog, aioresponse):
-    """Test api call asynchronously with retryable error."""
-    caplog.set_level(logging.WARNING, 
logger="airflow.providers.http.hooks.http")
-    hook = HttpAsyncHook(method="GET")
-    aioresponse.get("http://httpbin.org/non_existent_endpoint";, status=500, 
repeat=True)
-
-    with pytest.raises(AirflowException) as exc, mock.patch.dict(
-        "os.environ",
-        AIRFLOW_CONN_HTTP_DEFAULT="http://httpbin.org/";,
-    ):
-        await hook.run(endpoint="non_existent_endpoint")
-
-    assert str(exc.value) == "500:Internal Server Error"
-    assert "[Try 3 of 3] Request to http://httpbin.org/non_existent_endpoint 
failed" in caplog.text
-
+        assert str(exc.value) == "400:Bad Request"
 
[email protected]
-async def test_do_api_call_async_unknown_method():
-    """Test api call asynchronously for unknown method."""
-    hook = HttpAsyncHook(method="NOPE")
-    json = {
-        "existing_cluster_id": "xxxx-xxxxxx-xxxxxx",
-    }
+    @pytest.mark.asyncio
+    async def test_do_api_call_async_retryable_error(self, caplog, 
aioresponse):
+        """Test api call asynchronously with retryable error."""
+        caplog.set_level(logging.WARNING, 
logger="airflow.providers.http.hooks.http")
+        hook = HttpAsyncHook(method="GET")
+        aioresponse.get("http://httpbin.org/non_existent_endpoint";, 
status=500, repeat=True)
 
-    with pytest.raises(AirflowException) as exc:
-        await hook.run(endpoint="non_existent_endpoint", data=json)
+        with pytest.raises(AirflowException) as exc, mock.patch.dict(

Review Comment:
   nit: you can `match` in `pytest.raises()` here instead of asserting later. 
Example:
   
   ```
   def func(x):
     if x == 5:
       raise ValueError("x must be a value other than 5")
     return x
   
   def test_func():
     with pytest.raises(ValueError, match="x must be a value other than 5"):
       func(5)
   ```



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