eladkal commented on code in PR #28009: URL: https://github.com/apache/airflow/pull/28009#discussion_r1036111127
########## tests/providers/exasol/operators/test_exasol_sql.py: ########## @@ -0,0 +1,150 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from typing import NamedTuple +from unittest.mock import MagicMock, patch + +import pytest + +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.snowflake.operators.snowflake import SnowflakeOperator Review Comment: should import exasol ########## tests/providers/exasol/operators/test_exasol_sql.py: ########## @@ -0,0 +1,150 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from typing import NamedTuple +from unittest.mock import MagicMock, patch + +import pytest + +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.snowflake.operators.snowflake import SnowflakeOperator + +DATE = "2017-04-20" +TASK_ID = "exasol-sql-operator" +DEFAULT_CONN_ID = "exasol_default" + + +class Row(NamedTuple): + id: str + value: str + + +class Row2(NamedTuple): + id2: str + value2: str + + [email protected]( + "sql, return_last, split_statement, hook_results, hook_descriptions, expected_results", + [ + pytest.param( + "select * from dummy", + True, + True, + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [[("id",), ("value",)]], + [Row(id=1, value="value1"), Row(id=2, value="value2")], + id="Scalar: Single SQL statement, return_last, split statement", + ), + pytest.param( + "select * from dummy;select * from dummy2", + True, + True, + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [[("id",), ("value",)]], + [Row(id=1, value="value1"), Row(id=2, value="value2")], + id="Scalar: Multiple SQL statements, return_last, split statement", + ), + pytest.param( + "select * from dummy", + False, + False, + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [[("id",), ("value",)]], + [Row(id=1, value="value1"), Row(id=2, value="value2")], + id="Scalar: Single SQL statements, no return_last (doesn't matter), no split statement", + ), + pytest.param( + "select * from dummy", + True, + False, + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [[("id",), ("value",)]], + [Row(id=1, value="value1"), Row(id=2, value="value2")], + id="Scalar: Single SQL statements, return_last (doesn't matter), no split statement", + ), + pytest.param( + ["select * from dummy"], + False, + False, + [[Row(id=1, value="value1"), Row(id=2, value="value2")]], + [[("id",), ("value",)]], + [[Row(id=1, value="value1"), Row(id=2, value="value2")]], + id="Non-Scalar: Single SQL statements in list, no return_last, no split statement", + ), + pytest.param( + ["select * from dummy", "select * from dummy2"], + False, + False, + [ + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [Row2(id2=1, value2="value1"), Row2(id2=2, value2="value2")], + ], + [[("id",), ("value",)], [("id2",), ("value2",)]], + [ + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [Row2(id2=1, value2="value1"), Row2(id2=2, value2="value2")], + ], + id="Non-Scalar: Multiple SQL statements in list, no return_last (no matter), no split statement", + ), + pytest.param( + ["select * from dummy", "select * from dummy2"], + True, + False, + [ + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [Row2(id2=1, value2="value1"), Row2(id2=2, value2="value2")], + ], + [[("id",), ("value",)], [("id2",), ("value2",)]], + [ + [Row(id=1, value="value1"), Row(id=2, value="value2")], + [Row2(id2=1, value2="value1"), Row2(id2=2, value2="value2")], + ], + id="Non-Scalar: Multiple SQL statements in list, return_last (no matter), no split statement", + ), + ], +) +def test_exec_success(sql, return_last, split_statement, hook_results, hook_descriptions, expected_results): + """ + Test the execute function in case where SQL query was successful. + """ + with patch("airflow.providers.common.sql.operators.sql.BaseSQLOperator.get_db_hook") as get_db_hook_mock: + op = SnowflakeOperator( Review Comment: ```suggestion op = ExasolOperator( ``` ########## tests/providers/exasol/hooks/test_sql.py: ########## @@ -0,0 +1,228 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# +from __future__ import annotations + +from unittest import mock +from unittest.mock import MagicMock, patch + +import pytest + +from airflow.models import Connection +from airflow.providers.common.sql.hooks.sql import fetch_all_handler +from airflow.providers.exasol.hooks.exasol import ExasolHook +from airflow.utils.session import provide_session + +TASK_ID = "sql-operator" +HOST = "host" +DEFAULT_CONN_ID = "exasol_default" +PASSWORD = "password" + + +class ExasolHookForTests(ExasolHook): + conn_name_attr = "snowflake_conn_id" Review Comment: ```suggestion conn_name_attr = "exasol_conn_id" ``` -- 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]
