Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell committed Jul 18, 2024
1 parent acaf3f8 commit 2c8ccc4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/nativeapp/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from snowflake.cli.plugins.nativeapp.exceptions import (
ApplicationPackageAlreadyExistsError,
ApplicationPackageDoesNotExistError,
NoEventTableForAccount,
SetupScriptFailedValidation,
UnexpectedOwnerError,
)
Expand All @@ -56,6 +57,7 @@
mock_get_app_pkg_distribution_in_sf,
)
from tests.nativeapp.utils import (
NATIVEAPP_MANAGER_ACCOUNT_EVENT_TABLE,
NATIVEAPP_MANAGER_BUILD_BUNDLE,
NATIVEAPP_MANAGER_DEPLOY,
NATIVEAPP_MANAGER_EXECUTE,
Expand Down Expand Up @@ -1297,3 +1299,87 @@ def test_validate_raw_returns_data(mock_execute, temp_dir, mock_cursor):
== failure_data
)
assert mock_execute.mock_calls == expected


@mock.patch(NATIVEAPP_MANAGER_EXECUTE)
def test_account_event_table(mock_execute, temp_dir, mock_cursor):
create_named_file(
file_name="snowflake.yml",
dir_name=temp_dir,
contents=[mock_snowflake_yml_file],
)

event_table = "db.schema.event_table"
side_effects, expected = mock_execute_helper(
[
(
mock_cursor([dict(key="EVENT_TABLE", value=event_table)], []),
mock.call(
"show parameters like 'event_table' in account",
cursor_class=DictCursor,
),
),
]
)
mock_execute.side_effect = side_effects

native_app_manager = _get_na_manager()
assert native_app_manager.account_event_table == event_table


@mock.patch(NATIVEAPP_MANAGER_EXECUTE)
def test_account_event_table_not_set_up(mock_execute, temp_dir, mock_cursor):
create_named_file(
file_name="snowflake.yml",
dir_name=temp_dir,
contents=[mock_snowflake_yml_file],
)

side_effects, expected = mock_execute_helper(
[
(
mock_cursor([], []),
mock.call(
"show parameters like 'event_table' in account",
cursor_class=DictCursor,
),
),
]
)
mock_execute.side_effect = side_effects

native_app_manager = _get_na_manager()
assert native_app_manager.account_event_table is None


@mock.patch(
NATIVEAPP_MANAGER_ACCOUNT_EVENT_TABLE,
return_value="db.schema.event_table",
new_callable=mock.PropertyMock,
)
def test_get_events(mock_account_event_table, temp_dir, mock_cursor):
create_named_file(
file_name="snowflake.yml",
dir_name=temp_dir,
contents=[mock_snowflake_yml_file],
)

native_app_manager = _get_na_manager()
assert native_app_manager.get_events() == []


@mock.patch(
NATIVEAPP_MANAGER_ACCOUNT_EVENT_TABLE,
return_value=None,
new_callable=mock.PropertyMock,
)
def test_get_events_no_event_table(mock_account_event_table, temp_dir, mock_cursor):
create_named_file(
file_name="snowflake.yml",
dir_name=temp_dir,
contents=[mock_snowflake_yml_file],
)

native_app_manager = _get_na_manager()
with pytest.raises(NoEventTableForAccount):
native_app_manager.get_events()
1 change: 1 addition & 0 deletions tests/nativeapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
NATIVEAPP_MANAGER_APP_PKG_DISTRIBUTION_IN_SF = (
f"{NATIVEAPP_MANAGER}.get_app_pkg_distribution_in_snowflake"
)
NATIVEAPP_MANAGER_ACCOUNT_EVENT_TABLE = f"{NATIVEAPP_MANAGER}.account_event_table"
NATIVEAPP_MANAGER_IS_APP_PKG_DISTRIBUTION_SAME = (
f"{NATIVEAPP_MANAGER}.verify_project_distribution"
)
Expand Down

0 comments on commit 2c8ccc4

Please sign in to comment.