Skip to content

Commit

Permalink
SNOW-1706990 Remove NativeAppVersionCreateProcessor (#1731)
Browse files Browse the repository at this point in the history
Updates version create tests to use `ApplicationPackageEntity` and removes `NativeAppVersionCreateProcessor`
  • Loading branch information
sfc-gh-fcampbell authored Oct 17, 2024
1 parent 43ef533 commit 2a494c3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Dict, Optional
from typing import Optional

from snowflake.cli._plugins.nativeapp.entities.application_package import (
ApplicationPackageEntity,
Expand All @@ -24,52 +24,10 @@
NativeAppCommandProcessor,
NativeAppManager,
)
from snowflake.cli._plugins.nativeapp.run_processor import NativeAppRunProcessor
from snowflake.cli.api.console import cli_console as cc
from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp


class NativeAppVersionCreateProcessor(NativeAppRunProcessor):
def __init__(self, project_definition: Dict, project_root: Path):
super().__init__(project_definition, project_root)

def process(
self,
version: Optional[str],
patch: Optional[int],
force: bool,
interactive: bool,
skip_git_check: bool,
*args,
**kwargs,
):
return ApplicationPackageEntity.version_create(
console=cc,
project_root=self.project_root,
deploy_root=self.deploy_root,
bundle_root=self.bundle_root,
generated_root=self.generated_root,
artifacts=self.artifacts,
package_name=self.package_name,
package_role=self.package_role,
package_distribution=self.package_distribution,
prune=True,
recursive=True,
paths=None,
print_diff=True,
validate=True,
stage_fqn=self.stage_fqn,
package_warehouse=self.package_warehouse,
post_deploy_hooks=self.package_post_deploy_hooks,
package_scripts=self.package_scripts,
version=version,
patch=patch,
force=force,
interactive=interactive,
skip_git_check=skip_git_check,
)


class NativeAppVersionDropProcessor(NativeAppManager, NativeAppCommandProcessor):
def __init__(self, project_definition: NativeApp, project_root: Path):
super().__init__(project_definition, project_root)
Expand Down
126 changes: 77 additions & 49 deletions tests/nativeapp/test_version_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from snowflake.cli._plugins.nativeapp.constants import SPECIAL_COMMENT
from snowflake.cli._plugins.nativeapp.entities.application_package import (
ApplicationPackageEntity,
ApplicationPackageEntityModel,
)
from snowflake.cli._plugins.nativeapp.exceptions import (
ApplicationPackageDoesNotExistError,
Expand All @@ -31,9 +32,6 @@
AskAlwaysPolicy,
DenyAlwaysPolicy,
)
from snowflake.cli._plugins.nativeapp.version.version_processor import (
NativeAppVersionCreateProcessor,
)
from snowflake.cli.api.console import cli_console as cc
from snowflake.cli.api.project.definition_manager import DefinitionManager
from snowflake.connector.cursor import DictCursor
Expand All @@ -42,22 +40,51 @@
APPLICATION_PACKAGE_ENTITY_MODULE,
SQL_EXECUTOR_EXECUTE,
mock_execute_helper,
mock_snowflake_yml_file,
mock_snowflake_yml_file_v2,
)
from tests.testing_utils.files_and_dirs import create_named_file

CREATE_PROCESSOR = "NativeAppVersionCreateProcessor"

allow_always_policy = AllowAlwaysPolicy()
ask_always_policy = AskAlwaysPolicy()
deny_always_policy = DenyAlwaysPolicy()


def _get_version_create_processor():
def _version_create(
version: str | None,
patch: int | None,
force: bool,
interactive: bool,
skip_git_check: bool,
):
dm = DefinitionManager()
return NativeAppVersionCreateProcessor(
project_definition=dm.project_definition.native_app,
pd = dm.project_definition
pkg_model: ApplicationPackageEntityModel = pd.entities["app_pkg"]
return ApplicationPackageEntity.version_create(
console=cc,
project_root=dm.project_root,
deploy_root=dm.project_root / pkg_model.deploy_root,
bundle_root=dm.project_root / pkg_model.bundle_root,
generated_root=(
dm.project_root / pkg_model.deploy_root / pkg_model.generated_root
),
artifacts=pkg_model.artifacts,
package_name=pkg_model.fqn.name,
package_role=pkg_model.meta.role,
package_distribution=pkg_model.distribution,
prune=True,
recursive=True,
paths=None,
print_diff=True,
validate=True,
stage_fqn=f"{pkg_model.fqn.name}.{pkg_model.stage}",
package_warehouse=pkg_model.meta.warehouse,
post_deploy_hooks=pkg_model.meta.post_deploy,
package_scripts=[],
version=version,
patch=patch,
force=force,
interactive=interactive,
skip_git_check=skip_git_check,
)


Expand Down Expand Up @@ -95,13 +122,15 @@ def test_get_existing_release_direction_info(mock_execute, temp_dir, mock_cursor
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
dm = DefinitionManager()
pd = dm.project_definition
pkg_model: ApplicationPackageEntityModel = pd.entities["app_pkg"]
result = ApplicationPackageEntity.get_existing_release_directive_info_for_version(
package_name=processor.package_name,
package_role=processor.package_role,
package_name=pkg_model.fqn.name,
package_role=pkg_model.meta.role,
version=version,
)
assert mock_execute.mock_calls == expected
Expand Down Expand Up @@ -144,15 +173,17 @@ def test_add_version(mock_execute, temp_dir, mock_cursor, version, version_ident
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
dm = DefinitionManager()
pd = dm.project_definition
pkg_model: ApplicationPackageEntityModel = pd.entities["app_pkg"]
ApplicationPackageEntity.add_new_version(
console=cc,
package_name=processor.package_name,
package_role=processor.package_role,
stage_fqn=processor.stage_fqn,
package_name=pkg_model.fqn.name,
package_role=pkg_model.meta.role,
stage_fqn=f"{pkg_model.fqn.name}.{pkg_model.stage}",
version=version,
)
assert mock_execute.mock_calls == expected
Expand Down Expand Up @@ -196,15 +227,17 @@ def test_add_new_patch_auto(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
dm = DefinitionManager()
pd = dm.project_definition
pkg_model: ApplicationPackageEntityModel = pd.entities["app_pkg"]
ApplicationPackageEntity.add_new_patch_to_version(
console=cc,
package_name=processor.package_name,
package_role=processor.package_role,
stage_fqn=processor.stage_fqn,
package_name=pkg_model.fqn.name,
package_role=pkg_model.meta.role,
stage_fqn=f"{pkg_model.fqn.name}.{pkg_model.stage}",
version=version,
)
assert mock_execute.mock_calls == expected
Expand Down Expand Up @@ -248,15 +281,17 @@ def test_add_new_patch_custom(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
dm = DefinitionManager()
pd = dm.project_definition
pkg_model: ApplicationPackageEntityModel = pd.entities["app_pkg"]
ApplicationPackageEntity.add_new_patch_to_version(
console=cc,
package_name=processor.package_name,
package_role=processor.package_role,
stage_fqn=processor.stage_fqn,
package_name=pkg_model.fqn.name,
package_role=pkg_model.meta.role,
stage_fqn=f"{pkg_model.fqn.name}.{pkg_model.stage}",
version=version,
patch=12,
)
Expand Down Expand Up @@ -287,12 +322,11 @@ def test_process_no_version_from_user_no_version_in_manifest(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
with pytest.raises(ClickException):
processor.process(
_version_create(
version=None,
patch=None,
force=force,
Expand Down Expand Up @@ -321,12 +355,11 @@ def test_process_no_version_exists_throws_bad_option_exception_one(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
with pytest.raises(BadOptionUsage):
processor.process(
_version_create(
version="v1",
patch=12,
force=force,
Expand Down Expand Up @@ -354,12 +387,11 @@ def test_process_no_version_exists_throws_bad_option_exception_two(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
with pytest.raises(BadOptionUsage):
processor.process(
_version_create(
version="v1",
patch=12,
force=force,
Expand Down Expand Up @@ -406,11 +438,10 @@ def test_process_no_existing_release_directives_or_versions(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
processor.process(
_version_create(
version=version,
patch=None,
force=force,
Expand Down Expand Up @@ -470,11 +501,10 @@ def test_process_no_existing_release_directives_w_existing_version(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
processor.process(
_version_create(
version=version,
patch=12,
force=force,
Expand Down Expand Up @@ -533,12 +563,11 @@ def test_process_existing_release_directives_user_does_not_proceed(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
with pytest.raises(typer.Exit):
processor.process(
_version_create(
version=version,
patch=12,
force=False,
Expand Down Expand Up @@ -604,11 +633,10 @@ def test_process_existing_release_directives_w_existing_version_two(
create_named_file(
file_name="snowflake.yml",
dir_name=current_working_directory,
contents=[mock_snowflake_yml_file],
contents=[mock_snowflake_yml_file_v2],
)

processor = _get_version_create_processor()
processor.process(
_version_create(
version=version,
patch=12,
force=force,
Expand Down

0 comments on commit 2a494c3

Please sign in to comment.