You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2023/01/03 21:58:59 UTC

[GitHub] [airflow] ferruzzi commented on a diff in pull request #28707: Add tests to document current s3 hook decorator behavior

ferruzzi commented on code in PR #28707:
URL: https://github.com/apache/airflow/pull/28707#discussion_r1060988846


##########
tests/providers/amazon/aws/hooks/test_s3.py:
##########
@@ -825,3 +826,122 @@ 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")
+@pytest.mark.parametrize(
+    "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("__fail__", id="unify-no_conn-no_bucket-rel_key"),
+        param("__fail__", 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("__fail__", 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_dec_no_get_connection_call(mock_base, expected, request):
+    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"

Review Comment:
   Tiny nitpick: Seems worth moving "key_bucket", "key.txt", and "s3://key_bucket/key.txt" into variables here and in the parameterize groups above in case someone accidentally changes one, but up to you.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org