SameerMesiah97 commented on code in PR #76857:
URL: https://github.com/apache/airflow/pull/76857#discussion_r4529926699
##########
providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:
##########
@@ -1613,6 +1613,52 @@ def test_function(self, bucket_name=None):
"Expected provided bucket_name to take precedence over
fallback"
)
+ @pytest.mark.asyncio
+ async def test_provide_bucket_name_async(self):
+ """Async bucket resolution honors configuration and explicit
overrides."""
+
+ class FakeS3Hook(S3Hook):
+ @provide_bucket_name
+ async def test_function(self, bucket_name=None):
+ return bucket_name
+
+ hook = FakeS3Hook(aws_conn_id="aws_default")
+ connection = Connection(
+ conn_id="aws_default",
+ conn_type="aws",
+ schema="schema-bucket",
+ )
+
+ with (
+ mock.patch(
+ "airflow.providers.amazon.aws.hooks.s3.get_async_connection",
+ new_callable=AsyncMock,
+ return_value=connection,
+ ) as mock_connection,
+ mock.patch(
+ "airflow.providers.amazon.aws.hooks.s3.get_async_extra_dejson",
+ new_callable=AsyncMock,
+ return_value={"service_config": {"s3": {"bucket_name":
"configured-bucket"}}},
+ ) as mock_extras,
+ ):
+ assert await hook.test_function() == "configured-bucket"
+
+ mock_connection.reset_mock()
+ mock_extras.reset_mock()
+
+ assert await hook.test_function(bucket_name="explicit-bucket") ==
"explicit-bucket"
+ mock_connection.assert_not_awaited()
+ mock_extras.assert_not_awaited()
+
+ mock_extras.return_value = {}
+ assert await hook.test_function() == "schema-bucket"
+
+ connection.schema = None
+ assert await hook.test_function() is None
+
+ hook_without_connection = FakeS3Hook(aws_conn_id=None)
+ assert await hook_without_connection.test_function() is None
Review Comment:
Could we parameterize the configured-bucket, schema-fallback, and no-config
cases, and test the explicit-bucket and no-connection-ID paths separately?
##########
providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:
##########
@@ -1613,6 +1613,52 @@ def test_function(self, bucket_name=None):
"Expected provided bucket_name to take precedence over
fallback"
)
+ @pytest.mark.asyncio
+ async def test_provide_bucket_name_async(self):
+ """Async bucket resolution honors configuration and explicit
overrides."""
+
+ class FakeS3Hook(S3Hook):
+ @provide_bucket_name
+ async def test_function(self, bucket_name=None):
+ return bucket_name
+
+ hook = FakeS3Hook(aws_conn_id="aws_default")
+ connection = Connection(
+ conn_id="aws_default",
+ conn_type="aws",
+ schema="schema-bucket",
+ )
+
+ with (
+ mock.patch(
+ "airflow.providers.amazon.aws.hooks.s3.get_async_connection",
+ new_callable=AsyncMock,
+ return_value=connection,
+ ) as mock_connection,
+ mock.patch(
+ "airflow.providers.amazon.aws.hooks.s3.get_async_extra_dejson",
+ new_callable=AsyncMock,
+ return_value={"service_config": {"s3": {"bucket_name":
"configured-bucket"}}},
+ ) as mock_extras,
+ ):
Review Comment:
Could you move some of these patches to the top of the function? Before the
signature?
--
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]