feluelle commented on code in PR #28710:
URL: https://github.com/apache/airflow/pull/28710#discussion_r1061466287


##########
tests/providers/amazon/aws/hooks/test_s3.py:
##########
@@ -825,3 +826,143 @@ def test_delete_bucket_tagging_with_no_tags(self):
 
         with pytest.raises(ClientError, match=r".*NoSuchTagSet.*"):
             hook.get_bucket_tagging(bucket_name="new_bucket")
+
+
+@patch("airflow.hooks.base.BaseHook.get_connection")
[email protected](
+    "expected",
+    [
+        # full key
+        # no conn - no bucket - full key
+        param(["key_bucket", "key.txt"], 
id="unify-no_conn-no_bucket-full_key"),
+        param(["key_bucket", "key.txt"], 
id="provide-no_conn-no_bucket-full_key"),
+        # no conn - with bucket - full key
+        param(["kwargs_bucket", "s3://key_bucket/key.txt"], 
id="unify-no_conn-with_bucket-full_key"),
+        param(["kwargs_bucket", "s3://key_bucket/key.txt"], 
id="provide-no_conn-with_bucket-full_key"),
+        # with conn - no bucket - full key
+        param(["conn_bucket", "s3://key_bucket/key.txt"], 
id="provide-with_conn-no_bucket-full_key"),
+        param(["key_bucket", "key.txt"], 
id="unify-with_conn-no_bucket-full_key"),
+        # with conn - with bucket - full key
+        param(["kwargs_bucket", "s3://key_bucket/key.txt"], 
id="provide-with_conn-with_bucket-full_key"),
+        param(["kwargs_bucket", "s3://key_bucket/key.txt"], 
id="unify-with_conn-with_bucket-full_key"),
+        # rel key
+        # no conn - no bucket - rel key
+        param([None, "key.txt"], id="unify-no_conn-no_bucket-rel_key"),
+        param([None, "key.txt"], id="provide-no_conn-no_bucket-rel_key"),
+        # no conn - with bucket - rel key
+        param(["kwargs_bucket", "key.txt"], 
id="unify-no_conn-with_bucket-rel_key"),
+        param(["kwargs_bucket", "key.txt"], 
id="provide-no_conn-with_bucket-rel_key"),
+        # with conn - no bucket - rel key
+        param(["conn_bucket", "key.txt"], 
id="provide-with_conn-no_bucket-rel_key"),
+        param(["conn_bucket", "key.txt"], 
id="unify-with_conn-no_bucket-rel_key"),
+        # with conn - with bucket - rel key
+        param(["kwargs_bucket", "key.txt"], 
id="provide-with_conn-with_bucket-rel_key"),
+        param(["kwargs_bucket", "key.txt"], 
id="unify-with_conn-with_bucket-rel_key"),
+    ],
+)
+def test_unify_and_provide_bucket_name_combination(mock_base, expected, 
request, caplog):
+    """
+    Verify what is the outcome when the unify_bucket_name_and_key and 
provide_bucket_name
+    decorators are combined.
+    """
+    tokens = request.node.callspec.id.split("-")
+    assert len(tokens) == 4
+    if "with_conn" in tokens:
+        c = Connection(schema="conn_bucket")
+    else:
+        c = Connection(schema=None)
+    key = "key.txt" if "rel_key" in tokens else "s3://key_bucket/key.txt"
+    if "with_bucket" in tokens:
+        kwargs = {"bucket_name": "kwargs_bucket", "key": key}
+    else:
+        kwargs = {"key": key}
+
+    mock_base.return_value = c
+    if "unify" in tokens:  # unify to be processed before provide
+
+        class MyHook(S3Hook):
+            @unify_bucket_name_and_key
+            @provide_bucket_name
+            def do_something(self, bucket_name=None, key=None):
+                return bucket_name, key
+
+    else:
+
+        with caplog.at_level("WARNING"):
+
+            class MyHook(S3Hook):
+                @provide_bucket_name
+                @unify_bucket_name_and_key
+                def do_something(self, bucket_name=None, key=None):
+                    return bucket_name, key
+
+        assert caplog.records[0].message == "`unify_bucket_name_and_key` 
should wrap `provide_bucket_name`."
+    hook = MyHook()
+    if expected == "__fail__":

Review Comment:
   Where is this defined? 🤔 



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