Skip to content

Commit

Permalink
replace test data with factory
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pjafari committed Dec 17, 2024
1 parent dfb4373 commit aa80ac4
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 201 deletions.
15 changes: 11 additions & 4 deletions tests_integration/nativeapp/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from tests_integration.testing_utils import (
assert_that_result_failed_with_message_containing,
)
from tests_integration.testing_utils.project_fixtures import *


@pytest.fixture
Expand Down Expand Up @@ -323,10 +324,13 @@ def test_nativeapp_bundle_deletes_existing_deploy_root(template_setup):


@pytest.mark.integration
def test_nativeapp_can_bundle_with_subdirs(runner, nativeapp_project_directory):
def test_nativeapp_can_bundle_with_subdirs(
runner, nativeapp_teardown, setup_v2_project_w_subdir
):
command = "app bundle --package-entity-id=pkg_v1"
subdir = "v1"
with nativeapp_project_directory("napp_stage_subdirs") as project_root:
project_name, project_root = setup_v2_project_w_subdir()
with nativeapp_teardown():
result = runner.invoke_json(split(command))
assert result.exit_code == 0

Expand All @@ -337,9 +341,12 @@ def test_nativeapp_can_bundle_with_subdirs(runner, nativeapp_project_directory):


@pytest.mark.integration
def test_nativeapp_bundle_subdirs_dont_overwrite(runner, nativeapp_project_directory):
def test_nativeapp_bundle_subdirs_dont_overwrite(
runner, nativeapp_teardown, setup_v2_project_w_subdir_w_snowpark
):
project_name, project_root = setup_v2_project_w_subdir_w_snowpark()

with nativeapp_project_directory("napp_stage_subdirs_w_snowpark") as project_root:
with nativeapp_teardown():
result_1 = runner.invoke_json(split("app bundle --package-entity-id=pkg_v1"))
assert result_1.exit_code == 0

Expand Down
39 changes: 23 additions & 16 deletions tests_integration/nativeapp/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

from snowflake.cli.api.project.util import TEST_RESOURCE_SUFFIX_VAR
from tests.nativeapp.utils import touch

from tests_integration.testing_utils.project_fixtures import *
from tests.project.fixtures import *
from tests_integration.test_utils import (
contains_row_with,
not_contains_row_with,
row_from_snowflake_session,
row_from_cursor,
)
from tests_integration.testing_utils import (
assert_that_result_failed_with_message_containing,
Expand Down Expand Up @@ -108,17 +109,21 @@ def test_nativeapp_deploy(

@pytest.mark.integration
def test_nativeapp_deploy_w_stage_subdir(
nativeapp_project_directory,
nativeapp_teardown,
runner,
snowflake_session,
default_username,
resource_suffix,
sanitize_deploy_output,
snapshot,
print_paths_as_posix,
setup_v2_project_w_subdir,
):
project_name = "stage_w_subdirs_pkg"
with nativeapp_project_directory("napp_stage_subdirs"):
(
project_name,
_,
) = setup_v2_project_w_subdir() # make this a fixture, don't pass temp_dir
with nativeapp_teardown():
result = runner.invoke_with_connection(
split("app deploy --package-entity-id=pkg_v1")
)
Expand All @@ -127,8 +132,9 @@ def test_nativeapp_deploy_w_stage_subdir(
assert sanitize_deploy_output(result.output) == snapshot

# package exist
package_name = f"{project_name}_{default_username}{resource_suffix}".upper()
app_name = f"{project_name}_{default_username}{resource_suffix}".upper()
package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper()
app_name = f"{project_name}_app_v1_{default_username}{resource_suffix}".upper()

assert contains_row_with(
row_from_snowflake_session(
snowflake_session.execute_string(
Expand All @@ -139,7 +145,7 @@ def test_nativeapp_deploy_w_stage_subdir(
)

# manifest file exists
stage_name = "app_src.stage/v1" # as defined in native-apps-templates/basic
stage_name = "app_src.stage/v1"
stage_files = runner.invoke_with_connection_json(
["stage", "list-files", f"{package_name}.{stage_name}"]
)
Expand Down Expand Up @@ -274,17 +280,17 @@ def test_nativeapp_deploy_prune_w_stage_subdir(
command,
contains,
not_contains,
nativeapp_project_directory,
nativeapp_teardown,
runner,
snapshot,
print_paths_as_posix,
default_username,
resource_suffix,
sanitize_deploy_output,
setup_v2_project_w_subdir,
):
test_project = "napp_stage_subdirs"
project_name = "stage_w_subdirs_pkg"
with nativeapp_project_directory(test_project):
project_name, _ = setup_v2_project_w_subdir()
with nativeapp_teardown():
result = runner.invoke_with_connection_json(
["app", "deploy", "--package-entity-id=pkg_v1"]
)
Expand All @@ -299,7 +305,7 @@ def test_nativeapp_deploy_prune_w_stage_subdir(
assert sanitize_deploy_output(result.output) == snapshot

# verify the file does not exist on the stage
package_name = f"{project_name}_{default_username}{resource_suffix}".upper()
package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper()
stage_name = "app_src.stage/v1" # as defined in native-apps-templates/basic
stage_files = runner.invoke_with_connection_json(
["stage", "list-files", f"{package_name}.{stage_name}"]
Expand Down Expand Up @@ -355,16 +361,17 @@ def test_nativeapp_deploy_files(

@pytest.mark.integration
def test_nativeapp_deploy_files_w_stage_subdir(
nativeapp_project_directory,
nativeapp_teardown,
runner,
snapshot,
print_paths_as_posix,
default_username,
resource_suffix,
sanitize_deploy_output,
setup_v2_project_w_subdir,
):
project_name = "stage_w_subdirs_pkg"
with nativeapp_project_directory("napp_stage_subdirs"):
project_name, _ = setup_v2_project_w_subdir()
with nativeapp_teardown():
# sync only two specific files to stage
touch("app/v2/file.txt")
result = runner.invoke_with_connection(
Expand All @@ -379,7 +386,7 @@ def test_nativeapp_deploy_files_w_stage_subdir(
assert sanitize_deploy_output(result.output) == snapshot

# manifest and script files exist, readme doesn't exist
package_name = f"{project_name}_{default_username}{resource_suffix}".upper()
package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper()
stage_name = "app_src.stage/v2" # as defined in native-apps-templates/basic
stage_files = runner.invoke_with_connection_json(
["stage", "list-files", f"{package_name}.{stage_name}"]
Expand Down
60 changes: 50 additions & 10 deletions tests_integration/nativeapp/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from shlex import split
from textwrap import dedent
from typing import Any, Union

import yaml
Expand Down Expand Up @@ -102,13 +103,6 @@ def temporary_role(request, snowflake_session, resource_suffix):
"ws version drop --entity-id=pkg",
"napp_init_v2",
],
[
"stage_w_subdirs",
"app version create --package-entity-id=pkg_v1",
"app version list --package-entity-id=pkg_v1",
"app version drop --package-entity-id=pkg_v1",
"napp_stage_subdirs",
],
],
)
def test_nativeapp_version_create_and_drop(
Expand Down Expand Up @@ -155,6 +149,51 @@ def test_nativeapp_version_create_and_drop(
assert len(actual.json) == 0


@pytest.mark.integration
def test_nativeapp_version_create_and_drop_stage_subdir(
runner,
snowflake_session,
default_username,
resource_suffix,
nativeapp_teardown,
setup_v2_project_w_subdir,
):
project_name, _ = setup_v2_project_w_subdir()
drop_command = "app version drop --package-entity-id=pkg_v1"
list_command = "app version list --package-entity-id=pkg_v1"
create_command = "app version create --package-entity-id=pkg_v1"
with nativeapp_teardown():
result_create = runner.invoke_with_connection_json(
[*split(create_command), "v1", "--force", "--skip-git-check"]
)
assert result_create.exit_code == 0

# 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(split(list_command))
assert actual.json == row_from_snowflake_session(expect)

result_drop = runner.invoke_with_connection_json(
[*split(drop_command), "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(
Expand Down Expand Up @@ -207,15 +246,16 @@ def test_nativeapp_upgrade_w_subdirs(
snowflake_session,
default_username,
resource_suffix,
nativeapp_project_directory,
nativeapp_teardown,
setup_v2_project_w_subdir,
):
project_name = "stage_w_subdirs"
project_name, _ = setup_v2_project_w_subdir()
create_command = (
"app version create v1 --package-entity-id=pkg_v1 --force --skip-git-check"
)
list_command = "app version list --package-entity-id=pkg_v1"
drop_command = "app version drop --package-entity-id=pkg_v1"
with nativeapp_project_directory("napp_stage_subdirs"):
with nativeapp_teardown():
runner.invoke_with_connection_json(["app", "run", "--app-entity-id=app_v1"])
runner.invoke_with_connection_json(split(create_command))

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit aa80ac4

Please sign in to comment.