This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5e161d9f9e Resolve mysql deprecations in tests (#40418)
5e161d9f9e is described below

commit 5e161d9f9e6837d3683b2b2d825fdb8bfbfb76fc
Author: Gopal Dirisala <[email protected]>
AuthorDate: Wed Jun 26 23:18:51 2024 +0530

    Resolve mysql deprecations in tests (#40418)
    
    * Resolve mysql deprecations in tests
    
    * Resolve mysql deprecations in tests
---
 tests/deprecations_ignore.yml                 |  6 ------
 tests/providers/mysql/operators/test_mysql.py | 27 +++++++++++++--------------
 2 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/tests/deprecations_ignore.yml b/tests/deprecations_ignore.yml
index 4d451038ca..ce3226dc96 100644
--- a/tests/deprecations_ignore.yml
+++ b/tests/deprecations_ignore.yml
@@ -229,10 +229,4 @@
 - 
tests/providers/microsoft/mssql/operators/test_mssql.py::TestMsSqlOperator::test_get_hook_default
 - 
tests/providers/microsoft/mssql/operators/test_mssql.py::TestMsSqlOperator::test_get_hook_from_conn
 - 
tests/providers/microsoft/psrp/hooks/test_psrp.py::TestPsrpHook::test_invoke_cmdlet_deprecated_kwargs
-- 
tests/providers/mysql/operators/test_mysql.py::TestMySql::test_mysql_operator_openlineage
-- 
tests/providers/mysql/operators/test_mysql.py::TestMySql::test_mysql_operator_resolve_parameters_template_json_file
-- 
tests/providers/mysql/operators/test_mysql.py::TestMySql::test_mysql_operator_test
-- 
tests/providers/mysql/operators/test_mysql.py::TestMySql::test_mysql_operator_test_multi
-- 
tests/providers/mysql/operators/test_mysql.py::TestMySql::test_overwrite_schema
-- 
tests/providers/mysql/operators/test_mysql.py::test_execute_openlineage_events
 - 
tests/providers/trino/operators/test_trino.py::test_execute_openlineage_events
diff --git a/tests/providers/mysql/operators/test_mysql.py 
b/tests/providers/mysql/operators/test_mysql.py
index 14899a5812..91e909700f 100644
--- a/tests/providers/mysql/operators/test_mysql.py
+++ b/tests/providers/mysql/operators/test_mysql.py
@@ -27,8 +27,8 @@ from openlineage.client.run import Dataset
 
 from airflow.models.connection import Connection
 from airflow.models.dag import DAG
+from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
 from airflow.providers.mysql.hooks.mysql import MySqlHook
-from airflow.providers.mysql.operators.mysql import MySqlOperator
 from airflow.utils import timezone
 from tests.providers.mysql.hooks.test_mysql import MySqlContext
 
@@ -36,6 +36,7 @@ DEFAULT_DATE = timezone.datetime(2015, 1, 1)
 DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
 DEFAULT_DATE_DS = DEFAULT_DATE_ISO[:10]
 TEST_DAG_ID = "unit_test_dag"
+MYSQL_DEFAULT = "mysql_default"
 
 
 @pytest.mark.backend("mysql")
@@ -60,7 +61,7 @@ class TestMySql:
                 dummy VARCHAR(50)
             );
             """
-            op = MySqlOperator(task_id="basic_mysql", sql=sql, dag=self.dag)
+            op = SQLExecuteQueryOperator(task_id="basic_mysql", sql=sql, 
dag=self.dag, conn_id=MYSQL_DEFAULT)
             op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, 
ignore_ti_state=True)
 
     @pytest.mark.parametrize("client", ["mysqlclient", 
"mysql-connector-python"])
@@ -71,10 +72,8 @@ class TestMySql:
                 "TRUNCATE TABLE test_airflow",
                 "INSERT INTO test_airflow VALUES ('X')",
             ]
-            op = MySqlOperator(
-                task_id="mysql_operator_test_multi",
-                sql=sql,
-                dag=self.dag,
+            op = SQLExecuteQueryOperator(
+                task_id="mysql_operator_test_multi", sql=sql, dag=self.dag, 
conn_id=MYSQL_DEFAULT
             )
             op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, 
ignore_ti_state=True)
 
@@ -85,11 +84,12 @@ class TestMySql:
         """
         with MySqlContext(client):
             sql = "SELECT 1;"
-            op = MySqlOperator(
+            op = SQLExecuteQueryOperator(
                 task_id="test_mysql_operator_test_schema_overwrite",
                 sql=sql,
                 dag=self.dag,
                 database="foobar",
+                conn_id=MYSQL_DEFAULT,
             )
 
             from MySQLdb import OperationalError
@@ -102,7 +102,9 @@ class TestMySql:
         path.write_text('{\n "foo": "{{ ds }}"}')
 
         with DAG("test-dag", start_date=DEFAULT_DATE, 
template_searchpath=os.fspath(path.parent)):
-            task = MySqlOperator(task_id="op1", parameters=path.name, 
sql="SELECT 1")
+            task = SQLExecuteQueryOperator(
+                task_id="op1", parameters=path.name, sql="SELECT 1", 
conn_id=MYSQL_DEFAULT
+            )
 
         task.resolve_template_files()
 
@@ -117,7 +119,7 @@ class TestMySql:
                 dummy VARCHAR(50)
             );
             """
-            op = MySqlOperator(task_id="basic_mysql", sql=sql, dag=self.dag)
+            op = SQLExecuteQueryOperator(task_id="basic_mysql", sql=sql, 
dag=self.dag, conn_id=MYSQL_DEFAULT)
 
             lineage = op.get_openlineage_facets_on_start()
             assert len(lineage.inputs) == 0
@@ -139,17 +141,14 @@ def test_execute_openlineage_events(connection_port):
 
     dbapi_hook = MySqlHookForTests()
 
-    class SQLExecuteQueryOperatorForTest(MySqlOperator):
-        def get_db_hook(self):
-            return dbapi_hook
-
     sql = """CREATE TABLE IF NOT EXISTS popular_orders_day_of_week (
         order_day_of_week VARCHAR(64) NOT NULL,
         order_placed_on   TIMESTAMP NOT NULL,
         orders_placed     INTEGER NOT NULL
     );
 FORGOT TO COMMENT"""
-    op = SQLExecuteQueryOperatorForTest(task_id="mysql-operator", sql=sql)
+    op = SQLExecuteQueryOperator(task_id="mysql-operator", sql=sql)
+    op._hook = dbapi_hook
     DB_SCHEMA_NAME = "PUBLIC"
     rows = [
         (DB_SCHEMA_NAME, "popular_orders_day_of_week", "order_day_of_week", 1, 
"varchar"),

Reply via email to