Miretpl commented on code in PR #77778:
URL: https://github.com/apache/airflow/pull/77778#discussion_r4760799714


##########
providers/common/sql/tests/unit/common/sql/operators/test_sql.py:
##########
@@ -3034,6 +3034,30 @@ def test_insert_rows_operator_with_rows_processor(self, 
mock_get_db_hook):
             (5, "Norris", "Chuck", 84),
         ]
 
+    @mock.patch.object(SQLInsertRowsOperator, "get_db_hook")
+    def test_insert_rows_operator_reads_columns_after_preoperator(self, 
mock_get_db_hook):
+        mock_hook = MagicMock(spec=DbApiHook)
+        mock_hook.dialect.get_column_names.return_value = ["index", "name"]
+        mock_get_db_hook.return_value = mock_hook
+
+        operator = SQLInsertRowsOperator(
+            task_id="test_task",
+            conn_id="default_conn",
+            schema="hollywood",
+            table_name="actors",
+            preoperator="CREATE TABLE hollywood.actors (index INT, name 
VARCHAR(50))",
+            rows=[(1, "Stallone"), (2, "Statham")],
+        )
+
+        operator.execute({})
+
+        assert mock_hook.mock_calls[:2] == [
+            mock.call.run("CREATE TABLE hollywood.actors (index INT, name 
VARCHAR(50))"),
+            mock.call.dialect.get_column_names("hollywood.actors"),
+        ]

Review Comment:
   ```suggestion
           assert mock_hook.assert_has_calls([
               mock.call.run("CREATE TABLE hollywood.actors (index INT, name 
VARCHAR(50))"),
               mock.call.dialect.get_column_names("hollywood.actors"),
           ])
   ```
   Order is preserved and should be more resilient to changes. We will lose the 
indirect test that the first two calls are these two, but I think, if we do not 
test sth like that, it should be different, dedicated test.



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