diff --git a/tests_integration/nativeapp/test_post_deploy.py b/tests_integration/nativeapp/test_post_deploy.py index 549568a0ef..ee9fe6f817 100644 --- a/tests_integration/nativeapp/test_post_deploy.py +++ b/tests_integration/nativeapp/test_post_deploy.py @@ -1,7 +1,10 @@ # Tests that application post-deploy scripts are executed by creating a post_deploy_log table and having each post-deploy script add a record to it +from pathlib import Path import pytest +import yaml +from tests_common import IS_WINDOWS from tests_integration.test_utils import ( row_from_snowflake_session, ) @@ -108,16 +111,14 @@ def test_nativeapp_post_deploy( create_version(runner, version, project_args) run(runner, base_command, project_args + version_run_args) - # TODO Remove condition once ApplicationEntity deploy is implemented - if base_command == "app": - verify_app_post_deploy_log( - snowflake_session, - app_name, - [ - {"TEXT": "app-post-deploy-part-1"}, - {"TEXT": "app-post-deploy-part-2"}, - ], - ) + verify_app_post_deploy_log( + snowflake_session, + app_name, + [ + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + ], + ) verify_pkg_post_deploy_log( snowflake_session, @@ -133,18 +134,16 @@ def test_nativeapp_post_deploy( create_version(runner, version, project_args) run(runner, base_command, project_args + version_run_args) - # TODO Remove condition once ApplicationEntity deploy is implemented - if base_command == "app": - verify_app_post_deploy_log( - snowflake_session, - app_name, - [ - {"TEXT": "app-post-deploy-part-1"}, - {"TEXT": "app-post-deploy-part-2"}, - {"TEXT": "app-post-deploy-part-1"}, - {"TEXT": "app-post-deploy-part-2"}, - ], - ) + verify_app_post_deploy_log( + snowflake_session, + app_name, + [ + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + ], + ) verify_pkg_post_deploy_log( snowflake_session, pkg_name, @@ -158,18 +157,16 @@ def test_nativeapp_post_deploy( deploy(runner, base_command, project_args) - # TODO Remove condition once ApplicationEntity deploy is implemented - if base_command == "app": - verify_app_post_deploy_log( - snowflake_session, - app_name, - [ - {"TEXT": "app-post-deploy-part-1"}, - {"TEXT": "app-post-deploy-part-2"}, - {"TEXT": "app-post-deploy-part-1"}, - {"TEXT": "app-post-deploy-part-2"}, - ], - ) + verify_app_post_deploy_log( + snowflake_session, + app_name, + [ + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + ], + ) verify_pkg_post_deploy_log( snowflake_session, pkg_name, @@ -188,3 +185,88 @@ def test_nativeapp_post_deploy( # need to drop the version before we can teardown drop_version(runner, version, project_args) teardown(runner, project_args) + + +@pytest.mark.integration +@pytest.mark.skipif( + not IS_WINDOWS, reason="Testing windows path should only be done on Windows" +) +@pytest.mark.parametrize( + "base_command,test_project", + [ + ["app", "napp_application_post_deploy_v1"], + ["app", "napp_application_post_deploy_v2"], + ["ws", "napp_application_post_deploy_v2"], + ], +) +def test_nativeapp_post_deploy_with_windows_path( + runner, + snowflake_session, + default_username, + resource_suffix, + nativeapp_project_directory, + base_command, + test_project, +): + project_name = "myapp" + app_name = f"{project_name}_{default_username}{resource_suffix}" + pkg_name = f"{project_name}_pkg_{default_username}{resource_suffix}" + + with nativeapp_project_directory(test_project) as tmp_dir: + try: + snowflake_yml_path = tmp_dir / "snowflake.yml" + with open(snowflake_yml_path, "r", encoding="utf-8") as file: + yml = yaml.safe_load(file) + if yml["definition_version"] >= 2: + artifact = yml["entities"]["pkg"]["artifacts"][0] + pkg_scripts = yml["entities"]["pkg"]["meta"]["post_deploy"] + app_scripts = yml["entities"]["app"]["meta"]["post_deploy"] + else: + artifact = yml["native_app"]["artifacts"][0] + pkg_scripts = yml["native_app"]["package"]["post_deploy"] + app_scripts = yml["native_app"]["application"]["post_deploy"] + + # use backslashes in artifacts src + artifact["src"] = artifact["src"].replace("/", "\\") + + # use backslashes in post_deploy paths, as well as full paths with backslashes + pkg_scripts[0]["sql_script"] = pkg_scripts[0]["sql_script"].replace( + "/", "\\" + ) + pkg_scripts[1]["sql_script"] = str( + (tmp_dir / pkg_scripts[1]["sql_script"]).absolute() + ) + + # use backslashes in post_deploy paths, as well as full paths with backslashes + app_scripts[0]["sql_script"] = app_scripts[0]["sql_script"].replace( + "/", "\\" + ) + app_scripts[1]["sql_script"] = str( + (tmp_dir / app_scripts[1]["sql_script"]).absolute() + ) + + with open(snowflake_yml_path, "w", encoding="utf-8") as file: + yaml.dump(yml, file) + + run(runner, base_command, []) + + verify_app_post_deploy_log( + snowflake_session, + app_name, + [ + {"TEXT": "app-post-deploy-part-1"}, + {"TEXT": "app-post-deploy-part-2"}, + ], + ) + + verify_pkg_post_deploy_log( + snowflake_session, + pkg_name, + [ + {"TEXT": "package-post-deploy-part-1"}, + {"TEXT": "package-post-deploy-part-2"}, + ], + ) + + finally: + teardown(runner, [])