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


##########
tests/providers/common/sql/hooks/test_dbapi.py:
##########
@@ -421,6 +421,56 @@ def test_get_uri_without_auth_and_empty_host(self):
         )
         assert self.db_hook.get_uri() == 
"conn-type://@:3306/schema?charset=utf-8"
 
+    def test_placeholder(self):
+        self.db_hook.get_connection = mock.MagicMock(
+            return_value=Connection(
+                conn_type="conn-type",
+                login=None,
+                password=None,
+                schema="schema",
+                port=3306,
+            )
+        )
+        assert self.db_hook.placeholder == "%s"
+
+        self.db_hook.log.warning.assert_not_called()
+
+    def test_placeholder_with_valid_placeholder_in_extra(self):
+        self.db_hook.get_connection = mock.MagicMock(
+            return_value=Connection(
+                conn_type="conn-type",
+                login=None,
+                password=None,
+                schema="schema",
+                port=3306,
+                extra=json.dumps({"placeholder": "?"}),
+            )
+        )
+        assert self.db_hook.placeholder == "?"
+
+        self.db_hook.log.warning.assert_not_called()
+
+    def test_placeholder_with_invalid_placeholder_in_extra(self):
+        self.db_hook.get_connection = mock.MagicMock(
+            return_value=Connection(
+                conn_type="conn-type",
+                login=None,
+                password=None,
+                schema="schema",
+                port=3306,
+                extra=json.dumps({"placeholder": "!"}),
+            )
+        )
+
+        assert self.db_hook.placeholder == "%s"
+
+        self.db_hook.log.warning.assert_called_once_with(
+            "Placeholder defined in Connection '%s' is not listed in 
'DEFAULT_SQL_PLACEHOLDERS' "
+            "and got ignored. Falling back to the default placeholder '%s'.",
+            "test_conn_id",
+            self.db_hook._placeholder,
+        )

Review Comment:
   Problem with this approach, as I already tried, is that I'm unable to 
capture the log statements.  Also previous tests where also already done that 
way, not that I don't want to do it, but I'm afraid the PR will take more time 
to try to figure this out.  Info statements get captured, and yes I already 
tried with this:
   ```
       def test_insert_rows_as_generator_supports_executemany(self, caplog):
           table = "table"
           rows = [("What's",), ("up",), ("world",)]
   
           with caplog.at_level(logging.DEBUG):
               self.db_hook.supports_executemany = True
               self.db_hook.insert_rows(table, iter(rows))
   
           assert self.conn.close.call_count == 1
           assert self.cur.close.call_count == 1
           assert self.conn.commit.call_count == 2
   
           sql = f"INSERT INTO {table}  VALUES (%s)"
   
           assert any(f"Generated sql: {sql}" in message for message in 
caplog.messages) # this one isn't captured
           assert any(f"Loaded 3 rows into {table} so far" in message for 
message in caplog.messages) # works
           assert any(
               f"Done loading. Loaded a total of 3 rows into {table}" in 
message # works
               for message in caplog.messages
           )
   
           self.cur.executemany.assert_any_call(sql, rows)
   ```



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