diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81e24f2e8a3b3..cb6ffa3fcc235 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -413,6 +413,7 @@ repos: ^airflow-ctl.*\.py$| ^airflow-core/src/airflow/models/.*\.py$| ^airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py$| + ^airflow-core/tests/unit/cli/commands/test_team_command\.py$| ^task_sdk.*\.py$ pass_filenames: true - id: update-supported-versions diff --git a/airflow-core/tests/unit/cli/commands/test_team_command.py b/airflow-core/tests/unit/cli/commands/test_team_command.py index 046e58de18889..97ef6f325b7d7 100644 --- a/airflow-core/tests/unit/cli/commands/test_team_command.py +++ b/airflow-core/tests/unit/cli/commands/test_team_command.py @@ -20,6 +20,7 @@ from unittest.mock import patch import pytest +from sqlalchemy import select from airflow import models, settings from airflow.cli import cli_parser @@ -67,7 +68,7 @@ def test_team_create_success(self, stdout_capture): team_command.team_create(self.parser.parse_args(["teams", "create", "test-team"])) # Verify team was created in database - team = self.session.query(Team).filter(Team.name == "test-team").first() + team = self.session.execute(select(Team).where(Team.name == "test-team")).scalars().first() assert team is not None assert team.name == "test-team" @@ -139,7 +140,7 @@ def test_team_delete_success(self, stdout_capture): team_command.team_create(self.parser.parse_args(["teams", "create", "delete-me"])) # Verify team exists - team = self.session.query(Team).filter(Team.name == "delete-me").first() + team = self.session.execute(select(Team).where(Team.name == "delete-me")).scalars().first() assert team is not None # Delete team with --yes flag @@ -147,7 +148,7 @@ def test_team_delete_success(self, stdout_capture): team_command.team_delete(self.parser.parse_args(["teams", "delete", "delete-me", "--yes"])) # Verify team was deleted - team = self.session.query(Team).filter(Team.name == "delete-me").first() + team = self.session.execute(select(Team).where(Team.name == "delete-me")).scalars().first() assert team is None # Verify output message @@ -168,7 +169,7 @@ def test_team_delete_with_dag_bundle_association(self): """Test deleting team that has DAG bundle associations.""" # Create team team_command.team_create(self.parser.parse_args(["teams", "create", "bundle-team"])) - team = self.session.query(Team).filter(Team.name == "bundle-team").first() + team = self.session.execute(select(Team).where(Team.name == "bundle-team")).scalars().first() # Create a DAG bundle first dag_bundle = DagBundleModel(name="test-bundle") @@ -194,7 +195,7 @@ def test_team_delete_with_connection_association(self): """Test deleting team that has connection associations.""" # Create team team_command.team_create(self.parser.parse_args(["teams", "create", "conn-team"])) - team = self.session.query(Team).filter(Team.name == "conn-team").first() + team = self.session.execute(select(Team).where(Team.name == "conn-team")).scalars().first() # Create connection associated with team conn = Connection(conn_id="test-conn", conn_type="http", team_name=team.name) @@ -212,7 +213,7 @@ def test_team_delete_with_variable_association(self): """Test deleting team that has variable associations.""" # Create team team_command.team_create(self.parser.parse_args(["teams", "create", "var-team"])) - team = self.session.query(Team).filter(Team.name == "var-team").first() + team = self.session.execute(select(Team).where(Team.name == "var-team")).scalars().first() # Create variable associated with team var = Variable(key="test-var", val="test-value", team_name=team.name) @@ -229,7 +230,7 @@ def test_team_delete_with_pool_association(self): """Test deleting team that has pool associations.""" # Create team team_command.team_create(self.parser.parse_args(["teams", "create", "pool-team"])) - team = self.session.query(Team).filter(Team.name == "pool-team").first() + team = self.session.execute(select(Team).where(Team.name == "pool-team")).scalars().first() # Create pool associated with team pool = Pool( @@ -248,7 +249,7 @@ def test_team_delete_with_multiple_associations(self): """Test deleting team that has multiple types of associations.""" # Create team team_command.team_create(self.parser.parse_args(["teams", "create", "multi-team"])) - team = self.session.query(Team).filter(Team.name == "multi-team").first() + team = self.session.execute(select(Team).where(Team.name == "multi-team")).scalars().first() # Create a DAG bundle first dag_bundle = DagBundleModel(name="multi-bundle") @@ -292,7 +293,7 @@ def test_team_delete_with_confirmation_yes(self, mock_input, stdout_capture): team_command.team_delete(self.parser.parse_args(["teams", "delete", "confirm-yes"])) # Verify team was deleted - team = self.session.query(Team).filter(Team.name == "confirm-yes").first() + team = self.session.execute(select(Team).where(Team.name == "confirm-yes")).scalars().first() assert team is None output = stdout.getvalue() @@ -309,7 +310,7 @@ def test_team_delete_with_confirmation_no(self, mock_input, stdout_capture): team_command.team_delete(self.parser.parse_args(["teams", "delete", "confirm-no"])) # Verify team was NOT deleted - team = self.session.query(Team).filter(Team.name == "confirm-no").first() + team = self.session.execute(select(Team).where(Team.name == "confirm-no")).scalars().first() assert team is not None output = stdout.getvalue() @@ -326,7 +327,7 @@ def test_team_delete_with_confirmation_invalid(self, mock_input, stdout_capture) team_command.team_delete(self.parser.parse_args(["teams", "delete", "confirm-invalid"])) # Verify team was NOT deleted (invalid input treated as No) - team = self.session.query(Team).filter(Team.name == "confirm-invalid").first() + team = self.session.execute(select(Team).where(Team.name == "confirm-invalid")).scalars().first() assert team is not None output = stdout.getvalue() @@ -335,7 +336,7 @@ def test_team_delete_with_confirmation_invalid(self, mock_input, stdout_capture) def test_team_operations_integration(self): """Test integration of create, list, and delete operations.""" # Start with empty state - teams = self.session.query(Team).all() + teams = self.session.execute(select(Team)).scalars().all() assert len(teams) == 0 # Create multiple teams @@ -344,7 +345,7 @@ def test_team_operations_integration(self): team_command.team_create(self.parser.parse_args(["teams", "create", "integration-3"])) # Verify all teams exist - teams = self.session.query(Team).all() + teams = self.session.execute(select(Team)).scalars().all() assert len(teams) == 3 team_names = [team.name for team in teams] assert "integration-1" in team_names @@ -355,7 +356,7 @@ def test_team_operations_integration(self): team_command.team_delete(self.parser.parse_args(["teams", "delete", "integration-2", "--yes"])) # Verify correct team was deleted - teams = self.session.query(Team).all() + teams = self.session.execute(select(Team)).scalars().all() assert len(teams) == 2 team_names = [team.name for team in teams] assert "integration-1" in team_names