dabla commented on code in PR #76857:
URL: https://github.com/apache/airflow/pull/76857#discussion_r4658326881


##########
providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:
##########
@@ -1613,6 +1613,98 @@ def test_function(self, bucket_name=None):
                 "Expected provided bucket_name to take precedence over 
fallback"
             )
 
+    @pytest.mark.asyncio
+    @pytest.mark.parametrize(
+        ("extra", "schema", "expected_bucket"),
+        [
+            (
+                {"service_config": {"s3": {"bucket_name": 
"configured-bucket"}}},
+                "schema-bucket",
+                "configured-bucket",
+            ),
+            ({}, "schema-bucket", "schema-bucket"),
+            ({}, None, None),
+        ],
+        ids=["configured-bucket", "schema-fallback", "no-config"],
+    )
+    @mock.patch(
+        "airflow.providers.amazon.aws.hooks.s3.get_async_extra_dejson",
+        new_callable=AsyncMock,

Review Comment:
   **[warning]** The patches have no spec, and patching 
`get_async_extra_dejson` keeps the test away from the path the fix is about.
   
   Two things on the six `mock.patch(..., new_callable=AsyncMock)` decorators 
in these three tests:
   
   1. `AGENTS.md` asks for `spec`/`autospec` when mocking. Both targets are 
plain `async def` functions, so `autospec=True` works and stays awaitable 
(`assert_awaited_once_with` still works on it).
   2. With `get_async_extra_dejson` replaced by a mock that returns a 
ready-made dict, the test never reads the extra of a connection. It would still 
pass if the hook looked in the wrong place of a real extra. The sync test just 
above (`test_provide_bucket_name`) builds `Connection(extra={"service_config": 
{"s3": {"bucket_name": ...}}})` and lets the real code read it; the async test 
can do the same and patch only the connection lookup:
   
   ```python
   @pytest.mark.asyncio
   @pytest.mark.parametrize(
       ("extra", "schema", "expected_bucket"),
       [...],
   )
   @mock.patch("airflow.providers.amazon.aws.hooks.s3.get_async_connection", 
autospec=True)
   async def test_provide_bucket_name_async(self, mock_connection, extra, 
schema, expected_bucket):
       mock_connection.return_value = Connection(
           conn_id="aws_default", conn_type="aws", schema=schema, extra=extra
       )
       ...
       assert await hook.test_function() == expected_bucket
       mock_connection.assert_awaited_once_with("aws_default")
   ```
   
   I ran this shape against this head and the three cases pass. The 
explicit-bucket and no-connection-ID tests then need only the 
`get_async_connection` patch as well (with `autospec=True`), since "no 
connection lookup" already implies the extra is never read.



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