diff --git a/tests_integration/nativeapp/__snapshots__/test_version.ambr b/tests_integration/nativeapp/__snapshots__/test_version.ambr index 104bfefae5..1c36118341 100644 --- a/tests_integration/nativeapp/__snapshots__/test_version.ambr +++ b/tests_integration/nativeapp/__snapshots__/test_version.ambr @@ -1,52 +1,78 @@ # serializer version: 1 -# name: test_nativeapp_version_create_package_no_magic_comment[integration] +# name: test_nativeapp_version_create_package_no_magic_comment[app version list-napp_init_v1] list([ dict({ - 'comment': 'Default version used for development. Override for actual deployment.', + 'comment': None, 'dropped_on': None, - 'label': 'Dev Version', - 'log_level': 'INFO', + 'label': None, + 'log_level': 'OFF', 'patch': 0, 'review_status': 'NOT_REVIEWED', 'state': 'READY', - 'trace_level': 'ALWAYS', + 'trace_level': 'OFF', 'version': 'V1', }), dict({ - 'comment': 'Default version used for development. Override for actual deployment.', + 'comment': None, 'dropped_on': None, - 'label': 'Dev Version', - 'log_level': 'INFO', + 'label': None, + 'log_level': 'OFF', 'patch': 1, 'review_status': 'NOT_REVIEWED', 'state': 'READY', - 'trace_level': 'ALWAYS', + 'trace_level': 'OFF', 'version': 'V1', }), ]) # --- -# name: test_nativeapp_version_create_package_no_magic_comment[integration_v2] +# name: test_nativeapp_version_create_package_no_magic_comment[app version list-napp_init_v2] list([ dict({ - 'comment': 'Default version used for development. Override for actual deployment.', + 'comment': None, 'dropped_on': None, - 'label': 'Dev Version', - 'log_level': 'INFO', + 'label': None, + 'log_level': 'OFF', 'patch': 0, 'review_status': 'NOT_REVIEWED', 'state': 'READY', - 'trace_level': 'ALWAYS', + 'trace_level': 'OFF', 'version': 'V1', }), dict({ - 'comment': 'Default version used for development. Override for actual deployment.', + 'comment': None, 'dropped_on': None, - 'label': 'Dev Version', - 'log_level': 'INFO', + 'label': None, + 'log_level': 'OFF', 'patch': 1, 'review_status': 'NOT_REVIEWED', 'state': 'READY', - 'trace_level': 'ALWAYS', + 'trace_level': 'OFF', + 'version': 'V1', + }), + ]) +# --- +# name: test_nativeapp_version_create_package_no_magic_comment[ws version list --entity-id=pkg-napp_init_v2] + list([ + dict({ + 'comment': None, + 'dropped_on': None, + 'label': None, + 'log_level': 'OFF', + 'patch': 0, + 'review_status': 'NOT_REVIEWED', + 'state': 'READY', + 'trace_level': 'OFF', + 'version': 'V1', + }), + dict({ + 'comment': None, + 'dropped_on': None, + 'label': None, + 'log_level': 'OFF', + 'patch': 1, + 'review_status': 'NOT_REVIEWED', + 'state': 'READY', + 'trace_level': 'OFF', 'version': 'V1', }), ]) diff --git a/tests_integration/nativeapp/test_version.py b/tests_integration/nativeapp/test_version.py index aa198cf50d..47ebad2916 100644 --- a/tests_integration/nativeapp/test_version.py +++ b/tests_integration/nativeapp/test_version.py @@ -11,166 +11,172 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from shlex import split from tests.project.fixtures import * -from tests_integration.test_utils import ( - pushd, - contains_row_with, - not_contains_row_with, - row_from_snowflake_session, -) +from tests_integration.test_utils import contains_row_with, row_from_snowflake_session # Tests a simple flow of an existing project, executing snow app version create, drop and teardown, all with distribution=internal @pytest.mark.integration @pytest.mark.parametrize( - "project_definition_files", ["integration", "integration_v2"], indirect=True + "list_command,test_project", + [ + ["app version list", "napp_init_v1"], + ["app version list", "napp_init_v2"], + ["ws version list --entity-id=pkg", "napp_init_v2"], + ], ) def test_nativeapp_version_create_and_drop( runner, snowflake_session, default_username, resource_suffix, - nativeapp_teardown, - project_definition_files: List[Path], + nativeapp_project_directory, + list_command, + test_project, ): - project_name = "integration" - project_dir = project_definition_files[0].parent - with pushd(project_dir): + project_name = "myapp" + with nativeapp_project_directory(test_project): result_create = runner.invoke_with_connection_json( ["app", "version", "create", "v1", "--force", "--skip-git-check"] ) assert result_create.exit_code == 0 - with nativeapp_teardown(): - # package exist - package_name = ( - f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - ) - assert contains_row_with( - row_from_snowflake_session( - snowflake_session.execute_string( - f"show application packages like '{package_name}'", - ) - ), - dict(name=package_name), - ) + # package exist + package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper() + assert contains_row_with( + row_from_snowflake_session( + snowflake_session.execute_string( + f"show application packages like '{package_name}'", + ) + ), + dict(name=package_name), + ) - # app package contains version v1 - expect = snowflake_session.execute_string( - f"show versions in application package {package_name}" - ) - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - assert actual.json == row_from_snowflake_session(expect) + # app package contains version v1 + expect = snowflake_session.execute_string( + f"show versions in application package {package_name}" + ) + actual = runner.invoke_with_connection_json(split(list_command)) + assert actual.json == row_from_snowflake_session(expect) - result_drop = runner.invoke_with_connection_json( - ["app", "version", "drop", "v1", "--force"] - ) - assert result_drop.exit_code == 0 - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - assert len(actual.json) == 0 + result_drop = runner.invoke_with_connection_json( + ["app", "version", "drop", "v1", "--force"] + ) + assert result_drop.exit_code == 0 + actual = runner.invoke_with_connection_json(split(list_command)) + assert len(actual.json) == 0 # Tests upgrading an app from an existing loose files installation to versioned installation. @pytest.mark.integration @pytest.mark.parametrize( - "project_definition_files", ["integration", "integration_v2"], indirect=True + "list_command,test_project", + [ + ["app version list", "napp_init_v1"], + ["app version list", "napp_init_v2"], + ["ws version list --entity-id=pkg", "napp_init_v2"], + ], ) def test_nativeapp_upgrade( runner, snowflake_session, default_username, resource_suffix, - nativeapp_teardown, - project_definition_files: List[Path], + nativeapp_project_directory, + list_command, + test_project, ): - project_name = "integration" - project_dir = project_definition_files[0].parent - with pushd(project_dir): + project_name = "myapp" + with nativeapp_project_directory(test_project): runner.invoke_with_connection_json(["app", "run"]) runner.invoke_with_connection_json( ["app", "version", "create", "v1", "--force", "--skip-git-check"] ) - with nativeapp_teardown(): - # package exist - package_name = ( - f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - ) - app_name = f"{project_name}_{default_username}{resource_suffix}".upper() - # app package contains version v1 - expect = snowflake_session.execute_string( - f"show versions in application package {package_name}" - ) - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - assert actual.json == row_from_snowflake_session(expect) + # package exist + package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper() + app_name = f"{project_name}_{default_username}{resource_suffix}".upper() + # app package contains version v1 + expect = snowflake_session.execute_string( + f"show versions in application package {package_name}" + ) + actual = runner.invoke_with_connection_json(split(list_command)) + assert actual.json == row_from_snowflake_session(expect) - runner.invoke_with_connection_json( - ["app", "run", "--version", "v1", "--force"] - ) + runner.invoke_with_connection_json(["app", "run", "--version", "v1", "--force"]) - expect = row_from_snowflake_session( - snowflake_session.execute_string(f"desc application {app_name}") - ) - assert contains_row_with(expect, {"property": "name", "value": app_name}) - assert contains_row_with(expect, {"property": "version", "value": "V1"}) - assert contains_row_with(expect, {"property": "patch", "value": "0"}) + expect = row_from_snowflake_session( + snowflake_session.execute_string(f"desc application {app_name}") + ) + assert contains_row_with(expect, {"property": "name", "value": app_name}) + assert contains_row_with(expect, {"property": "version", "value": "V1"}) + assert contains_row_with(expect, {"property": "patch", "value": "0"}) - runner.invoke_with_connection_json( - ["app", "version", "drop", "v1", "--force"] - ) + runner.invoke_with_connection_json(["app", "version", "drop", "v1", "--force"]) # Make sure we can create 3+ patches on the same version @pytest.mark.integration -@pytest.mark.parametrize("project_definition_files", ["integration"], indirect=True) +@pytest.mark.parametrize( + "list_command,test_project", + [ + ["app version list", "napp_init_v1"], + ["app version list", "napp_init_v2"], + ["ws version list --entity-id=pkg", "napp_init_v2"], + ], +) def test_nativeapp_version_create_3_patches( runner, snowflake_session, default_username, resource_suffix, nativeapp_teardown, - project_definition_files: List[Path], + nativeapp_project_directory, + list_command, + test_project, ): - project_name = "integration" - project_dir = project_definition_files[0].parent - with pushd(project_dir): - with nativeapp_teardown(): - package_name = ( - f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - ) - - # create three patches (deploys too) - for _ in range(3): - result = runner.invoke_with_connection_json( - ["app", "version", "create", "v1", "--force", "--skip-git-check"] - ) - assert result.exit_code == 0 + project_name = "myapp" + with nativeapp_project_directory(test_project): + package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - # app package contains 3 patches for version v1 - expect = row_from_snowflake_session( - snowflake_session.execute_string( - f"show versions in application package {package_name}" - ) + # create three patches (deploys too) + for _ in range(3): + result = runner.invoke_with_connection_json( + ["app", "version", "create", "v1", "--force", "--skip-git-check"] ) - assert contains_row_with(expect, {"version": "V1", "patch": 0}) - assert contains_row_with(expect, {"version": "V1", "patch": 1}) - assert contains_row_with(expect, {"version": "V1", "patch": 2}) + assert result.exit_code == 0 - # drop the version - result_drop = runner.invoke_with_connection_json( - ["app", "version", "drop", "v1", "--force"] + # app package contains 3 patches for version v1 + expect = row_from_snowflake_session( + snowflake_session.execute_string( + f"show versions in application package {package_name}" ) - assert result_drop.exit_code == 0 + ) + assert contains_row_with(expect, {"version": "V1", "patch": 0}) + assert contains_row_with(expect, {"version": "V1", "patch": 1}) + assert contains_row_with(expect, {"version": "V1", "patch": 2}) + + # drop the version + result_drop = runner.invoke_with_connection_json( + ["app", "version", "drop", "v1", "--force"] + ) + assert result_drop.exit_code == 0 - # ensure there are no versions now - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - assert len(actual.json) == 0 + # ensure there are no versions now + actual = runner.invoke_with_connection_json(split(list_command)) + assert len(actual.json) == 0 @pytest.mark.integration @pytest.mark.parametrize( - "project_definition_files", ["integration", "integration_v2"], indirect=True + "list_command,test_project", + [ + ["app version list", "napp_init_v1"], + ["app version list", "napp_init_v2"], + ["ws version list --entity-id=pkg", "napp_init_v2"], + ], ) def test_nativeapp_version_create_patch_is_integer( runner, @@ -178,72 +184,72 @@ def test_nativeapp_version_create_patch_is_integer( default_username, resource_suffix, nativeapp_teardown, - project_definition_files: List[Path], + nativeapp_project_directory, + list_command, + test_project, ): - project_name = "integration" - project_dir = project_definition_files[0].parent - with pushd(project_dir): - with nativeapp_teardown(): - package_name = ( - f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - ) - - # create initial version - result = runner.invoke_with_connection_json( - ["app", "version", "create", "v1", "--force", "--skip-git-check"] - ) - assert result.exit_code == 0 - - # create non-integer patch - result = runner.invoke_with_connection_json( - [ - "app", - "version", - "create", - "v1", - "--force", - "--skip-git-check", - "--patch", - "foo", - ], - ) - assert result.exit_code == 2 - assert ( - "Invalid value for '--patch': 'foo' is not a valid integer." - in result.output - ) + with nativeapp_project_directory(test_project): + # create initial version + result = runner.invoke_with_connection_json( + ["app", "version", "create", "v1", "--force", "--skip-git-check"] + ) + assert result.exit_code == 0 + + # create non-integer patch + result = runner.invoke_with_connection_json( + [ + "app", + "version", + "create", + "v1", + "--force", + "--skip-git-check", + "--patch", + "foo", + ], + ) + assert result.exit_code == 2 + assert ( + "Invalid value for '--patch': 'foo' is not a valid integer." + in result.output + ) - # create integer patch - result = runner.invoke_with_connection_json( - [ - "app", - "version", - "create", - "v1", - "--force", - "--skip-git-check", - "--patch", - "1", - ], - ) - assert result.exit_code == 0 + # create integer patch + result = runner.invoke_with_connection_json( + [ + "app", + "version", + "create", + "v1", + "--force", + "--skip-git-check", + "--patch", + "1", + ], + ) + assert result.exit_code == 0 - # drop the version - result_drop = runner.invoke_with_connection_json( - ["app", "version", "drop", "v1", "--force"] - ) - assert result_drop.exit_code == 0 + # drop the version + result_drop = runner.invoke_with_connection_json( + ["app", "version", "drop", "v1", "--force"] + ) + assert result_drop.exit_code == 0 - # ensure there are no versions now - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - assert len(actual.json) == 0 + # ensure there are no versions now + actual = runner.invoke_with_connection_json(split(list_command)) + assert len(actual.json) == 0 # Tests creating a version for a package that was not created by the CLI # (doesn't have the magic CLI comment) @pytest.mark.integration @pytest.mark.parametrize( - "project_definition_files", ["integration", "integration_v2"], indirect=True + "list_command,test_project", + [ + ["app version list", "napp_init_v1"], + ["app version list", "napp_init_v2"], + ["ws version list --entity-id=pkg", "napp_init_v2"], + ], ) def test_nativeapp_version_create_package_no_magic_comment( runner, @@ -252,76 +258,74 @@ def test_nativeapp_version_create_package_no_magic_comment( resource_suffix, nativeapp_teardown, snapshot, - project_definition_files: List[Path], + nativeapp_project_directory, + list_command, + test_project, ): - project_name = "integration" - project_dir = project_definition_files[0].parent - with pushd(project_dir): + project_name = "myapp" + with nativeapp_project_directory(test_project): result_create_abort = runner.invoke_with_connection_json(["app", "deploy"]) assert result_create_abort.exit_code == 0 - with nativeapp_teardown(): - # package exist - package_name = ( - f"{project_name}_pkg_{default_username}{resource_suffix}".upper() - ) - assert contains_row_with( - row_from_snowflake_session( - snowflake_session.execute_string( - f"show application packages like '{package_name}'", - ) - ), - dict(name=package_name), - ) + # package exist + package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper() + assert contains_row_with( + row_from_snowflake_session( + snowflake_session.execute_string( + f"show application packages like '{package_name}'", + ) + ), + dict(name=package_name), + ) - assert contains_row_with( - row_from_snowflake_session( - snowflake_session.execute_string( - f"alter application package {package_name} set comment = 'not the magic comment'" - ) - ), - dict(status="Statement executed successfully."), - ) + assert contains_row_with( + row_from_snowflake_session( + snowflake_session.execute_string( + f"alter application package {package_name} set comment = 'not the magic comment'" + ) + ), + dict(status="Statement executed successfully."), + ) - # say no - result_create_abort = runner.invoke_with_connection( - ["app", "version", "create", "v1", "--skip-git-check", "--interactive"], - input="n\n", - ) - assert result_create_abort.exit_code == 1 - assert ( - f"An Application Package {package_name} already exists in account " - "that may have been created without Snowflake CLI.".upper() - in result_create_abort.output.upper() - ) - assert "Aborted." in result_create_abort.output + # say no + result_create_abort = runner.invoke_with_connection( + ["app", "version", "create", "v1", "--skip-git-check", "--interactive"], + input="n\n", + ) + assert result_create_abort.exit_code == 1 + assert ( + f"An Application Package {package_name} already exists in account " + "that may have been created without Snowflake CLI.".upper() + in result_create_abort.output.upper() + ) + assert "Aborted." in result_create_abort.output - # say yes - result_create_yes = runner.invoke_with_connection( - ["app", "version", "create", "v1", "--skip-git-check", "--interactive"], - input="y\n", - ) - assert result_create_yes.exit_code == 0 - assert ( - f"An Application Package {package_name} already exists in account " - "that may have been created without Snowflake CLI.".upper() - in result_create_yes.output.upper() - ) + # say yes + result_create_yes = runner.invoke_with_connection( + ["app", "version", "create", "v1", "--skip-git-check", "--interactive"], + input="y\n", + ) + assert result_create_yes.exit_code == 0 + assert ( + f"An Application Package {package_name} already exists in account " + "that may have been created without Snowflake CLI.".upper() + in result_create_yes.output.upper() + ) - # force - result_create_force = runner.invoke_with_connection( - ["app", "version", "create", "v1", "--force", "--skip-git-check"] - ) - assert result_create_force.exit_code == 0 - assert ( - f"An Application Package {package_name} already exists in account " - "that may have been created without Snowflake CLI.".upper() - in result_create_force.output.upper() - ) + # force + result_create_force = runner.invoke_with_connection( + ["app", "version", "create", "v1", "--force", "--skip-git-check"] + ) + assert result_create_force.exit_code == 0 + assert ( + f"An Application Package {package_name} already exists in account " + "that may have been created without Snowflake CLI.".upper() + in result_create_force.output.upper() + ) - # app package contains version v1 with 2 patches - actual = runner.invoke_with_connection_json(["app", "version", "list"]) - for row in actual.json: - # Remove date field - row.pop("created_on", None) - assert actual.json == snapshot + # app package contains version v1 with 2 patches + actual = runner.invoke_with_connection_json(split(list_command)) + for row in actual.json: + # Remove date field + row.pop("created_on", None) + assert actual.json == snapshot