Skip to content
Merged
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
8 changes: 4 additions & 4 deletions providers/fab/src/airflow/providers/fab/cli/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@
epilog=(
"examples:\n"
"To see what orphaned permissions would be cleaned up:\n"
" $ airflow fab-auth-manager permissions-cleanup --dry-run\n"
" $ airflow permissions-cleanup --dry-run\n"
"To clean up all orphaned permissions:\n"
" $ airflow fab-auth-manager permissions-cleanup\n"
" $ airflow permissions-cleanup\n"
"To clean up permissions for specific DAG:\n"
" $ airflow fab-auth-manager permissions-cleanup --dag-id my_dag\n"
" $ airflow permissions-cleanup --dag-id my_dag\n"
"To clean up without confirmation:\n"
" $ airflow fab-auth-manager permissions-cleanup --yes"
" $ airflow permissions-cleanup --yes"
),
)

Expand Down
25 changes: 25 additions & 0 deletions providers/fab/tests/unit/fab/cli/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,31 @@
# under the License.
from __future__ import annotations

import shlex

import pytest

from airflow.providers.fab.cli.definition import (
PERMISSIONS_CLEANUP_COMMAND,
ROLES_COMMANDS,
SYNC_PERM_COMMAND,
USERS_COMMANDS,
get_parser,
)


def _extract_epilog_examples(command):
examples = []
for line in (command.epilog or "").splitlines():
stripped = line.strip()
if stripped.startswith("$ airflow "):
examples.append(stripped.removeprefix("$ "))
if not examples:
# An empty parametrize set is silently skipped, which would hide the loss of this guard.
raise ValueError(f"No '$ airflow ...' example found in the {command.name} epilog")
return examples


class TestCliDefinition:
def test_users_commands(self):
assert len(USERS_COMMANDS) == 8
Expand All @@ -32,3 +50,10 @@ def test_roles_commands(self):

def test_sync_perm_command(self):
assert SYNC_PERM_COMMAND.name == "sync-perm"

@pytest.mark.parametrize(
"example", _extract_epilog_examples(PERMISSIONS_CLEANUP_COMMAND), ids=lambda e: e
)
def test_permissions_cleanup_epilog_examples_are_runnable(self, example):
args = get_parser().parse_args(shlex.split(example)[1:])
assert args.subcommand == PERMISSIONS_CLEANUP_COMMAND.name