dabla commented on code in PR #77778:
URL: https://github.com/apache/airflow/pull/77778#discussion_r4766012101
##########
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:
Applied in 22e204604a, thanks. I left out the leading `assert`:
`assert_has_calls` raises by itself and returns `None`, so `assert
mock_hook.assert_has_calls(...)` would always fail. The order is still checked,
and the test still fails without the fix.
--
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]