Skip to content

Commit

Permalink
abort test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gbloom committed May 7, 2024
1 parent 7d0aff0 commit fb852d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/snowflake/cli/plugins/nativeapp/teardown_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict, Optional

import typer
from click import ClickException
from snowflake.cli.api.console import cli_console as cc
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
from snowflake.cli.plugins.nativeapp.constants import (
Expand Down Expand Up @@ -139,9 +138,10 @@ def drop_application(
else:
raise typer.Abort()
else:
raise ClickException(
f"The following application objects are owned application {self.app_name}:\n{application_objects_str}\n\nAborting, re-run teardown again with --cascade or --no-cascade to specify whether these objects should be dropped along with the application."
cc.message(
f"The following application objects are owned application {self.app_name}:\n{application_objects_str}\n\nRe-run teardown again with --cascade or --no-cascade to specify whether these objects should be dropped along with the application."
)
raise typer.Abort()
elif cascade is None:
cascade = False

Expand Down
16 changes: 9 additions & 7 deletions tests/nativeapp/test_teardown_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import mock

import pytest
from click import ClickException
from click import Abort
from snowflake.cli.api.project.definition_manager import DefinitionManager
from snowflake.cli.plugins.nativeapp.constants import (
SPECIAL_COMMENT,
Expand Down Expand Up @@ -30,6 +30,7 @@
TEARDOWN_PROCESSOR_GET_EXISTING_APP_PKG_INFO,
TEARDOWN_PROCESSOR_IS_CORRECT_OWNER,
TYPER_CONFIRM,
TYPER_PROMPT,
mock_execute_helper,
mock_snowflake_yml_file,
quoted_override_yml_file,
Expand Down Expand Up @@ -1016,7 +1017,7 @@ def test_drop_package_idempotent(
mock_execute.mock_calls == expected


@mock.patch(f"{TEARDOWN_MODULE}.{TYPER_CONFIRM}")
@mock.patch(f"{TEARDOWN_MODULE}.{TYPER_PROMPT}")
@mock.patch(TEARDOWN_PROCESSOR_GET_EXISTING_APP_INFO)
@mock.patch(TEARDOWN_PROCESSOR_IS_CORRECT_OWNER, return_value=True)
@mock.patch(TEARDOWN_PROCESSOR_DROP_GENERIC_OBJECT, return_value=None)
Expand All @@ -1034,16 +1035,17 @@ def test_drop_package_idempotent(
[None, [], None, False],
[None, [{"type": "DATABASE", "name": "db"}], None, None],
# Interactive
[None, [{"type": "DATABASE", "name": "db"}], True, True],
[None, [{"type": "DATABASE", "name": "db"}], False, False],
[None, [{"type": "DATABASE", "name": "db"}], "yes", True],
[None, [{"type": "DATABASE", "name": "db"}], "no", False],
[None, [{"type": "DATABASE", "name": "db"}], "abort", None],
],
)
def test_drop_application_cascade(
mock_get_objects_owned_by_application,
mock_drop_generic_object,
mock_is_correct_owner,
mock_get_existing_app_info,
mock_typer_confirm,
mock_typer_prompt,
cascade,
application_objects,
interactive_response,
Expand All @@ -1063,11 +1065,11 @@ def test_drop_application_cascade(
contents=[mock_snowflake_yml_file],
)
interactive = interactive_response is not None
mock_typer_confirm.return_value = interactive_response
mock_typer_prompt.return_value = interactive_response

teardown_processor = _get_na_teardown_processor()
if expected_cascade is None:
with pytest.raises(ClickException):
with pytest.raises(Abort):
teardown_processor.drop_application(False, interactive, cascade)
else:
teardown_processor.drop_application(False, interactive, cascade)
Expand Down
1 change: 1 addition & 0 deletions tests/nativeapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
NATIVEAPP_MODULE = "snowflake.cli.plugins.nativeapp.manager"
TEARDOWN_MODULE = "snowflake.cli.plugins.nativeapp.teardown_processor"
TYPER_CONFIRM = "typer.confirm"
TYPER_PROMPT = "typer.prompt"
RUN_MODULE = "snowflake.cli.plugins.nativeapp.run_processor"
VERSION_MODULE = "snowflake.cli.plugins.nativeapp.version.version_processor"

Expand Down

0 comments on commit fb852d2

Please sign in to comment.