Skip to content

Commit

Permalink
add unit test + update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gbloom committed Mar 18, 2024
1 parent 4198548 commit 12b6bf6
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/__snapshots__/test_help_messages.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,74 @@
╰──────────────────────────────────────────────────────────────────────────────╯


'''
# ---
# name: test_help_messages[app.deploy]
'''

Usage: default app deploy [OPTIONS]

Syncs the local changes to the stage without creating or updating the
application.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --project -p TEXT Path where the Snowflake Native App project │
│ resides. Defaults to current working directory. │
│ --help -h Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Connection configuration ───────────────────────────────────────────────────╮
│ --connection,--environment -c TEXT Name of the connection, as defined │
│ in your `config.toml`. Default: │
│ `default`. │
│ --account,--accountname TEXT Name assigned to your Snowflake │
│ account. Overrides the value │
│ specified for the connection. │
│ --user,--username TEXT Username to connect to Snowflake. │
│ Overrides the value specified for │
│ the connection. │
│ --password TEXT Snowflake password. Overrides the │
│ value specified for the │
│ connection. │
│ --authenticator TEXT Snowflake authenticator. Overrides │
│ the value specified for the │
│ connection. │
│ --private-key-path TEXT Snowflake private key path. │
│ Overrides the value specified for │
│ the connection. │
│ --database,--dbname TEXT Database to use. Overrides the │
│ value specified for the │
│ connection. │
│ --schema,--schemaname TEXT Database schema to use. Overrides │
│ the value specified for the │
│ connection. │
│ --role,--rolename TEXT Role to use. Overrides the value │
│ specified for the connection. │
│ --warehouse TEXT Warehouse to use. Overrides the │
│ value specified for the │
│ connection. │
│ --temporary-connection -x Uses connection defined with │
│ command line parameters, instead │
│ of one defined in config │
│ --mfa-passcode TEXT Token to use for multi-factor │
│ authentication (MFA) │
│ --enable-diag Run python connector diagnostic │
│ test │
│ --diag-log-path TEXT Diagnostic report path │
│ --diag-allowlist-path TEXT Diagnostic report path to optional │
│ allowlist │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Global configuration ───────────────────────────────────────────────────────╮
│ --format [TABLE|JSON] Specifies the output format. │
│ [default: TABLE] │
│ --verbose -v Displays log entries for log levels `info` │
│ and higher. │
│ --debug Displays log entries for log levels `debug` │
│ and higher; debug logs contains additional │
│ information. │
│ --silent Turns off intermediate output to console. │
╰──────────────────────────────────────────────────────────────────────────────╯


'''
# ---
# name: test_help_messages[app.init]
Expand Down Expand Up @@ -670,6 +738,8 @@
│ --help -h Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ deploy Syncs the local changes to the stage without creating or updating │
│ the application. │
│ init Initializes a Snowflake Native App project. │
│ open Opens the Snowflake Native App inside of your browser, once it has │
│ been installed in your account. │
Expand Down
47 changes: 47 additions & 0 deletions tests/nativeapp/test_run_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
NATIVEAPP_MANAGER_EXECUTE_QUERIES,
NATIVEAPP_MANAGER_IS_APP_PKG_DISTRIBUTION_SAME,
RUN_MODULE,
RUN_PROCESSOR_APPLY_PACKAGE_SCRIPTS,
RUN_PROCESSOR_CREATE_APP_PACKAGE,
RUN_PROCESSOR_CREATE_DEV_APP,
RUN_PROCESSOR_GET_EXISTING_APP_INFO,
RUN_PROCESSOR_GET_EXISTING_APP_PKG_INFO,
RUN_PROCESSOR_SYNC_DEPLOY_ROOT_WITH_STAGE,
TYPER_CONFIRM,
mock_execute_helper,
mock_snowflake_yml_file,
Expand Down Expand Up @@ -1462,3 +1466,46 @@ def test_get_existing_version_info(mock_execute, temp_dir, mock_cursor):
result = processor.get_existing_version_info(version)
assert mock_execute.mock_calls == expected
assert result["version"] == version


# Test process doesn't invoke create_dev_app when skip_app_update=true
@mock.patch(NATIVEAPP_MANAGER_EXECUTE)
@mock.patch(RUN_PROCESSOR_CREATE_APP_PACKAGE)
@mock.patch(RUN_PROCESSOR_APPLY_PACKAGE_SCRIPTS)
@mock.patch(RUN_PROCESSOR_SYNC_DEPLOY_ROOT_WITH_STAGE)
@mock.patch(RUN_PROCESSOR_CREATE_DEV_APP)
def test_process_no_skip_app_update(
mock_create_dev_app,
mock_sync_deploy_root_with_stage,
mock_apply_package_scripts,
mock_create_app_package,
mock_execute,
mock_cursor,
):
side_effects, expected = mock_execute_helper(
[
(
mock_cursor([{"CURRENT_ROLE()": "old_role"}], []),
mock.call("select current_role()", cursor_class=DictCursor),
),
(None, mock.call("use role package_role")),
(None, mock.call("use role old_role")),
]
)
mock_execute.side_effect = side_effects

current_working_directory = os.getcwd()
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
)

run_processor = _get_na_run_processor()
run_processor.process(policy=deny_always_policy, skip_app_update=True)

assert mock_execute.mock_calls == expected
mock_create_app_package.assert_called()
mock_apply_package_scripts.assert_called()
mock_sync_deploy_root_with_stage.assert_called()
mock_create_dev_app.assert_not_called()
6 changes: 6 additions & 0 deletions tests/nativeapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

RUN_PROCESSOR_GET_EXISTING_APP_INFO = f"{RUN_PROCESSOR}.get_existing_app_info"
RUN_PROCESSOR_GET_EXISTING_APP_PKG_INFO = f"{RUN_PROCESSOR}.get_existing_app_pkg_info"
RUN_PROCESSOR_CREATE_APP_PACKAGE = f"{RUN_PROCESSOR}.create_app_package"
RUN_PROCESSOR_APPLY_PACKAGE_SCRIPTS = f"{RUN_PROCESSOR}._apply_package_scripts"
RUN_PROCESSOR_SYNC_DEPLOY_ROOT_WITH_STAGE = (
f"{RUN_PROCESSOR}.sync_deploy_root_with_stage"
)
RUN_PROCESSOR_CREATE_DEV_APP = f"{RUN_PROCESSOR}._create_dev_app"

FIND_VERSION_FROM_MANIFEST = f"{VERSION_MODULE}.find_version_info_in_manifest_file"

Expand Down

0 comments on commit 12b6bf6

Please sign in to comment.