Skip to content

Commit

Permalink
Resolve common providers deprecations in tests (apache#40036)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirrao authored and romsharon98 committed Jul 26, 2024
1 parent e93926f commit 07afd54
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions airflow/providers/cncf/kubernetes/cli/kubernetes_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from airflow.providers.cncf.kubernetes import pod_generator
from airflow.providers.cncf.kubernetes.executors.kubernetes_executor import KubeConfig
from airflow.providers.cncf.kubernetes.kube_client import get_kube_client
from airflow.providers.cncf.kubernetes.kubernetes_helper_functions import create_pod_id
from airflow.providers.cncf.kubernetes.kubernetes_helper_functions import create_unique_id
from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
from airflow.utils import cli as cli_utils, yaml
from airflow.utils.cli import get_dag
Expand All @@ -52,7 +52,7 @@ def generate_pod_yaml(args):
pod = PodGenerator.construct_pod(
dag_id=args.dag_id,
task_id=ti.task_id,
pod_id=create_pod_id(args.dag_id, ti.task_id),
pod_id=create_unique_id(args.dag_id, ti.task_id),
try_number=ti.try_number,
kube_image=kube_config.kube_image,
date=ti.execution_date,
Expand Down
11 changes: 0 additions & 11 deletions tests/deprecations_ignore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,6 @@
- tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_exception
- tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_resuming_status
- tests/providers/amazon/aws/triggers/test_redshift_cluster.py::TestRedshiftClusterTrigger::test_redshift_cluster_sensor_trigger_success
- tests/providers/apache/spark/operators/test_spark_sql.py::TestSparkSqlOperator::test_execute
- tests/providers/common/sql/hooks/test_dbapi.py::TestDbApiHook::test_instance_check_works_for_legacy_db_api_hook
- tests/providers/common/sql/operators/test_sql.py::TestSQLCheckOperatorDbHook::test_get_hook
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_branch_false_with_dag_run
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_branch_list_with_dag_run
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_branch_single_value_with_dag_run
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_branch_true_with_dag_run
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_invalid_query_result_with_dag_run
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_with_skip_in_branch_downstream_dependencies
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_with_skip_in_branch_downstream_dependencies2
- tests/providers/cncf/kubernetes/cli/test_kubernetes_command.py::TestGenerateDagYamlCommand::test_generate_dag_yaml
- tests/providers/databricks/hooks/test_databricks_sql.py::test_incorrect_column_names
- tests/providers/databricks/hooks/test_databricks_sql.py::test_no_query
- tests/providers/databricks/hooks/test_databricks_sql.py::test_query
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/apache/spark/operators/test_spark_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_execute(self):
# Given / When
operator = SparkSqlOperator(task_id="spark_sql_job", dag=self.dag, **self._config)

assert self._config["sql"] == operator._sql
assert self._config["sql"] == operator.sql
assert self._config["conn_id"] == operator._conn_id
assert self._config["total_executor_cores"] == operator._total_executor_cores
assert self._config["executor_cores"] == operator._executor_cores
Expand Down
7 changes: 6 additions & 1 deletion tests/providers/common/sql/hooks/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pytest
from pyodbc import Cursor

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.hooks.base import BaseHook
from airflow.models import Connection
from airflow.providers.common.sql.hooks.sql import DbApiHook, fetch_all_handler, fetch_one_handler
Expand Down Expand Up @@ -537,7 +538,11 @@ def test_instance_check_works_for_non_db_api_hook(self):
assert not isinstance(NonDbApiHook(), DbApiHook)

def test_instance_check_works_for_legacy_db_api_hook(self):
from airflow.hooks.dbapi import DbApiHook as LegacyDbApiHook
with pytest.warns(
RemovedInAirflow3Warning,
match="This module is deprecated. Please use `airflow.providers.common.sql.hooks.sql`.",
):
from airflow.hooks.dbapi import DbApiHook as LegacyDbApiHook

assert isinstance(DbApiHookInProvider(), LegacyDbApiHook)

Expand Down
18 changes: 16 additions & 2 deletions tests/providers/common/sql/operators/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import pytest

from airflow import DAG
from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.models import Connection, DagRun, TaskInstance as TI, XCom
from airflow.operators.empty import EmptyOperator
from airflow.providers.common.sql.hooks.sql import fetch_all_handler
Expand Down Expand Up @@ -608,7 +608,14 @@ def test_get_hook(self, database):
) as mock_get_conn:
if database:
self._operator.database = database
assert isinstance(self._operator._hook, PostgresHook)
if database:
with pytest.warns(
AirflowProviderDeprecationWarning,
match='The "schema" variable has been renamed to "database" as it contained the database name.Please use "database" to set the database name.',
):
assert isinstance(self._operator._hook, PostgresHook)
else:
assert isinstance(self._operator._hook, PostgresHook)
mock_get_conn.assert_called_once_with(self.conn_id)

def test_not_allowed_conn_type(self):
Expand Down Expand Up @@ -1120,6 +1127,7 @@ def test_branch_single_value_with_dag_run(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1160,6 +1168,7 @@ def test_branch_true_with_dag_run(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1201,6 +1210,7 @@ def test_branch_false_with_dag_run(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1243,6 +1253,7 @@ def test_branch_list_with_dag_run(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1282,6 +1293,7 @@ def test_invalid_query_result_with_dag_run(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1312,6 +1324,7 @@ def test_with_skip_in_branch_downstream_dependencies(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down Expand Up @@ -1351,6 +1364,7 @@ def test_with_skip_in_branch_downstream_dependencies2(self, mock_get_db_hook):
start_date=timezone.utcnow(),
execution_date=DEFAULT_DATE,
state=State.RUNNING,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
)

mock_get_records = mock_get_db_hook.return_value.get_first
Expand Down

0 comments on commit 07afd54

Please sign in to comment.