o-nikolas commented on code in PR #28707:
URL: https://github.com/apache/airflow/pull/28707#discussion_r1061032048


##########
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")
[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("__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:
   Yes, I misread @ferruzzi comment and muxed the two pieces of feedback, we 
can start a new thread if you like or continue here.
   
   My feedback is about how the inputs to the test are being encoded into the 
test id/name. And then parsed out with split string, and then string 
comparisons used to determine the value etc. I've never see parameterize used 
that way, the whole purpose of pytest parameterize is to parameterize the input 
and it supports multiple inputs just fine. I think it'd be much better and less 
brittle than using the string id.
   
   So instead of having this:
   `@pytest.mark.parametrize("expected",[...])`
   You'd have:
   `@pytest.mark.parametrize("expected_result, decorator, rel_key, with_conn, 
with_bucket",[...])`
   and you method signature becomes: 
   `def test_unify_and_provide_bucket_name_combination(mock_base, 
expected_result, decorator, rel_key,with_conn, with_bucket):`
   
   Then you don't need to encode any input into the test via the id/name. No 
string parsing needed or string comparisons, just put the inputs you want for 
each test case in the parameters.
   
   
   > look, what's brittle and problematic is the existing code. this is just a 
test. it does not need to be the most immaculate piece of work ever.
   
   Indeed there's no intention to offend here, just giving some feedback, I 
apologize if it felt like there was :) 
   
   



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