Skip to content

Commit

Permalink
Merge branch 'main' into mchok-metrics-counter-feature-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mchok authored Sep 19, 2024
2 parents 9dccb93 + cb7bc80 commit 949edf0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/snowflake/cli/_plugins/nativeapp/application_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def action_deploy(
app_name = model.fqn.identifier
debug_mode = model.debug
if model.meta:
app_role = getattr(model.meta, "role", ctx.default_role)
app_warehouse = getattr(model.meta, "warehouse", ctx.default_warehouse)
post_deploy_hooks = getattr(model.meta, "post_deploy", None)
app_role = model.meta.role or ctx.default_role
app_warehouse = model.meta.warehouse or ctx.default_warehouse
post_deploy_hooks = model.meta.post_deploy
else:
app_role = ctx.default_role
app_warehouse = ctx.default_warehouse
Expand Down
64 changes: 34 additions & 30 deletions tests/nativeapp/test_teardown_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_drop_application_has_special_comment_and_quoted_name(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_application(auto_yes_param)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected


# Test drop_application() without special comment AND auto_yes is False AND should_drop is False
Expand Down Expand Up @@ -362,7 +362,6 @@ def test_drop_application_user_prohibits_drop(
# Test drop_application() without special comment AND auto_yes is True
@mock.patch(APP_ENTITY_GET_EXISTING_APP_INFO)
@mock.patch(APP_ENTITY_DROP_GENERIC_OBJECT, return_value=None)
@mock.patch(SQL_EXECUTOR_EXECUTE)
@mock.patch(f"{APP_ENTITY_MODULE}.{TYPER_CONFIRM}", return_value=True)
@mock.patch(APP_ENTITY_GET_OBJECTS_OWNED_BY_APPLICATION, return_value=[])
@pytest.mark.parametrize(
Expand All @@ -372,7 +371,6 @@ def test_drop_application_user_prohibits_drop(
def test_drop_application_user_allows_drop(
mock_get_objects_owned_by_application,
mock_confirm,
mock_execute,
mock_drop_generic_object,
mock_get_existing_app_info,
auto_yes_param,
Expand All @@ -388,17 +386,6 @@ def test_drop_application_user_allows_drop(
"version": "dummy",
"patch": "dummy",
}
side_effects, expected = mock_execute_helper(
[
(
mock_cursor([("old_role",)], []),
mock.call("select current_role()"),
),
(None, mock.call("use role app_role")),
(None, mock.call("use role old_role")),
]
)
mock_execute.side_effect = side_effects

current_working_directory = os.getcwd()
create_named_file(
Expand All @@ -411,7 +398,6 @@ def test_drop_application_user_allows_drop(
teardown_processor.drop_application(auto_yes_param)
mock_get_existing_app_info.assert_called_once()
mock_drop_generic_object.assert_called_once()
mock_execute.mock_calls == expected


# Test idempotent drop_application()
Expand Down Expand Up @@ -448,7 +434,7 @@ def test_drop_application_idempotent(
teardown_processor.drop_application(auto_yes_param)
teardown_processor.drop_application(auto_yes_param)

mock_get_existing_app_info.call_count == 3
assert mock_get_existing_app_info.call_count == 3
mock_drop_generic_object.assert_called_once()


Expand Down Expand Up @@ -618,7 +604,10 @@ def test_drop_package_no_mismatch_no_drop(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand All @@ -634,7 +623,7 @@ def test_drop_package_no_mismatch_no_drop(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes=False)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected


# Test drop_package when there is no distribution mismatch AND distribution = external AND auto_yes is False AND should_drop is True
Expand Down Expand Up @@ -683,7 +672,10 @@ def test_drop_package_variable_mismatch_allowed_user_allows_drop(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand All @@ -699,7 +691,7 @@ def test_drop_package_variable_mismatch_allowed_user_allows_drop(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes_param)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected
if not is_pkg_distribution_same:
mock_warning.assert_any_call(
"Dropping application package app_pkg with distribution 'external'."
Expand Down Expand Up @@ -754,7 +746,10 @@ def test_drop_package_variable_mistmatch_w_special_comment_auto_drop(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand All @@ -770,7 +765,7 @@ def test_drop_package_variable_mistmatch_w_special_comment_auto_drop(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes_param)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected
mock_drop_generic_object.assert_called_once()
if not is_pkg_distribution_same:
mock_warning.assert_any_call(
Expand Down Expand Up @@ -865,7 +860,7 @@ def test_drop_package_variable_mistmatch_w_special_comment_quoted_name_auto_drop

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes_param)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected


# Test drop_package when there is no distribution mismatch AND distribution = internal AND without special comment AND auto_yes is False AND should_drop is False
Expand Down Expand Up @@ -907,7 +902,10 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_prohibits_drop(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand All @@ -923,7 +921,7 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_prohibits_drop(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes=False)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected
if not is_pkg_distribution_same:
mock_warning.assert_any_call(
"Dropping application package app_pkg with distribution 'internal'."
Expand Down Expand Up @@ -975,7 +973,10 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_allows_drop(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand All @@ -991,7 +992,7 @@ def test_drop_package_variable_mistmatch_no_special_comment_user_allows_drop(

teardown_processor = _get_na_teardown_processor()
teardown_processor.drop_package(auto_yes_param)
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected
mock_drop_generic_object.assert_called_once()


Expand Down Expand Up @@ -1025,7 +1026,10 @@ def test_drop_package_idempotent(
(None, mock.call("use role package_role")),
(
mock_cursor([], []),
mock.call("show versions in application package app_pkg"),
mock.call(
"show versions in application package app_pkg",
cursor_class=DictCursor,
),
),
(None, mock.call("use role old_role")),
]
Expand Down Expand Up @@ -1053,9 +1057,9 @@ def test_drop_package_idempotent(
teardown_processor.drop_package(auto_yes_param)
teardown_processor.drop_package(auto_yes_param)

mock_get_existing_app_pkg_info.call_count == 3
assert mock_get_existing_app_pkg_info.call_count == 3
mock_drop_generic_object.assert_called_once()
mock_execute.mock_calls == expected
assert mock_execute.mock_calls == expected


@mock.patch(f"{APP_ENTITY_MODULE}.{TYPER_PROMPT}")
Expand Down
15 changes: 13 additions & 2 deletions tests_integration/nativeapp/test_post_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@


def run(runner, base_command, args):
# TODO Run "ws deploy --entity-id=app" once ApplicationEntity deploy is implemented
result = runner.invoke_with_connection_json(["app", "run"] + args)
if base_command == "ws":
result = runner.invoke_with_connection_json(
["ws", "deploy", "--entity-id", "app"] + args
)
else:
result = runner.invoke_with_connection_json(["app", "run"] + args)

assert result.exit_code == 0


Expand Down Expand Up @@ -92,6 +97,12 @@ def test_nativeapp_post_deploy(
is_versioned,
with_project_flag,
):

if base_command == "ws" and is_versioned:
pytest.skip(
"TODO: ws commands do not support deploying applications from versions yet"
)

version = "v1"
project_name = "myapp"
app_name = f"{project_name}_{default_username}{resource_suffix}"
Expand Down

0 comments on commit 949edf0

Please sign in to comment.