Skip to content

Commit

Permalink
dont ask to confirm deletion of non-existent gcl (#16379)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz authored Dec 13, 2024
1 parent b1c44cf commit 1d9f3dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
14 changes: 8 additions & 6 deletions src/prefect/cli/global_concurrency_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ async def delete_global_concurrency_limit(
Arguments:
name (str): The name of the global concurrency limit to delete.
"""
if is_interactive() and not typer.confirm(
f"Are you sure you want to delete global concurrency limit with name {name!r}?",
default=False,
):
exit_with_error("Deletion aborted.")

async with get_client() as client:
try:
gcl_limit = await client.read_global_concurrency_limit_by_name(name=name)

if is_interactive() and not typer.confirm(
f"Are you sure you want to delete global concurrency limit with name {gcl_limit.name!r}?",
default=False,
):
exit_with_error("Deletion aborted.")

await client.delete_global_concurrency_limit_by_name(name=name)
except ObjectNotFound:
exit_with_error(f"Global concurrency limit {name!r} not found.")
Expand Down
21 changes: 8 additions & 13 deletions tests/cli/test_global_concurrency_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,40 +153,35 @@ def delete_global_concurrency_limit_by_name() -> Generator[mock.AsyncMock, None,
yield m


def test_deleting_gcl(
def test_deleting_gcl_succeeds(
delete_global_concurrency_limit_by_name: mock.AsyncMock,
various_global_concurrency_limits: List[GlobalConcurrencyLimit],
global_concurrency_limit: ConcurrencyLimitV2,
):
invoke_and_assert(
[
"global-concurrency-limit",
"delete",
various_global_concurrency_limits[0].name,
global_concurrency_limit.name,
],
prompts_and_responses=[
(
f"Are you sure you want to delete global concurrency limit with name '{various_global_concurrency_limits[0].name}'?",
f"Are you sure you want to delete global concurrency limit with name '{global_concurrency_limit.name}'?",
"y",
)
],
expected_output_contains=f"Deleted global concurrency limit with name '{various_global_concurrency_limits[0].name}'.",
expected_output_contains=f"Deleted global concurrency limit with name '{global_concurrency_limit.name}'.",
expected_code=0,
)
delete_global_concurrency_limit_by_name.assert_called_once_with(
name=various_global_concurrency_limits[0].name
name=global_concurrency_limit.name
)


def test_deleting_gcl_not_found():
invoke_and_assert(
["global-concurrency-limit", "delete", "not-found"],
prompts_and_responses=[
(
"Are you sure you want to delete global concurrency limit with name 'not-found'?",
"y",
)
],
"global-concurrency-limit delete not-found",
expected_output_contains="Global concurrency limit 'not-found' not found.",
expected_output_does_not_contain="Are you sure you want to delete global concurrency limit with name 'non-found'?",
expected_code=1,
)

Expand Down

0 comments on commit 1d9f3dc

Please sign in to comment.