Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions airflow-core/tests/unit/cli/commands/test_team_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -139,15 +140,15 @@ 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
with stdout_capture as stdout:
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
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down