Skip to content

Commit

Permalink
get_deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jsikorski committed Dec 20, 2024
1 parent 5d1c94f commit 762aa80
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 145 deletions.
4 changes: 1 addition & 3 deletions src/snowflake/cli/_plugins/snowpark/snowpark_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Generic, List, Optional, TypeVar

from click import ClickException

from snowflake.cli._plugins.nativeapp.feature_flags import FeatureFlag
from snowflake.cli._plugins.snowpark import package_utils
from snowflake.cli._plugins.snowpark.common import DEFAULT_RUNTIME
Expand Down Expand Up @@ -37,11 +36,10 @@ class DeployMode(


class SnowparkEntity(EntityBase[Generic[T]]):

def __init__(self, *args, **kwargs):

if not FeatureFlag.ENABLE_NATIVE_APP_CHILDREN.is_enabled():
raise NotImplementedError("Streamlit entity is not implemented yet")
raise NotImplementedError("Snowpark entity is not implemented yet")
super().__init__(*args, **kwargs)

@property
Expand Down
11 changes: 11 additions & 0 deletions tests/snowpark/__snapshots__/test_snowpark_entity.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@
HANDLER='app.func1_handler'
'''
# ---
# name: test_nativeapp_children_interface
'''
CREATE FUNCTION IDENTIFIER('func1')
COPY GRANTS
RETURNS string
LANGUAGE PYTHON
RUNTIME_VERSION '3.10'
IMPORTS=
HANDLER='app.func1_handler'
'''
# ---
48 changes: 44 additions & 4 deletions tests/snowpark/test_snowpark_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
AnacondaPackages,
AvailablePackage,
)
from snowflake.cli._plugins.snowpark.snowpark_entity import DeployMode, FunctionEntity, ProcedureEntity
from snowflake.cli._plugins.snowpark.snowpark_entity import (
DeployMode,
FunctionEntity,
ProcedureEntity,
)
from snowflake.cli._plugins.snowpark.snowpark_entity_model import FunctionEntityModel
from snowflake.cli._plugins.workspace.context import ActionContext, WorkspaceContext

Expand Down Expand Up @@ -45,14 +49,46 @@ def example_function_workspace(
),
)


def test_cannot_instantiate_without_feature_flag():
with pytest.raises(NotImplementedError) as err:
FunctionEntity()
assert str(err.value) == "Snowpark entities are not implemented yet"
assert str(err.value) == "Snowpark entity is not implemented yet"

with pytest.raises(NotImplementedError) as err:
ProcedureEntity()
assert str(err.value) == "Snowpark entities are not implemented yet"
assert str(err.value) == "Snowpark entity is not implemented yet"


@mock.patch(ANACONDA_PACKAGES)
def test_nativeapp_children_interface(
mock_anaconda, example_function_workspace, snapshot
):
mock_anaconda.return_value = AnacondaPackages(
{
"pandas": AvailablePackage("pandas", "1.2.3"),
"numpy": AvailablePackage("numpy", "1.2.3"),
"snowflake_snowpark_python": AvailablePackage(
"snowflake_snowpark_python", "1.2.3"
),
}
)

sl, action_context = example_function_workspace

sl.bundle(None, False, False, None, False)
bundle_artifact = (
sl.root / "output" / sl.model.stage / "my_snowpark_project" / "app.py"
)
deploy_sql_str = sl.get_deploy_sql(DeployMode.create)
grant_sql_str = sl.get_usage_grant_sql(app_role="app_role")

assert bundle_artifact.exists()
assert deploy_sql_str == snapshot
assert (
grant_sql_str == f"GRANT USAGE ON FUNCTION IDENTIFIER('func1') TO ROLE app_role"
)


@mock.patch(EXECUTE_QUERY)
def test_action_describe(mock_execute, example_function_workspace):
Expand Down Expand Up @@ -130,6 +166,10 @@ def test_get_deploy_sql(mode, example_function_workspace, snapshot):
entity, _ = example_function_workspace
assert entity.get_deploy_sql(mode) == snapshot


def test_get_usage_grant_sql(example_function_workspace):
entity, _ = example_function_workspace
assert entity.get_usage_grant_sql("test_role") == "GRANT USAGE ON FUNCTION IDENTIFIER('func1') TO ROLE test_role"
assert (
entity.get_usage_grant_sql("test_role")
== "GRANT USAGE ON FUNCTION IDENTIFIER('func1') TO ROLE test_role"
)
138 changes: 0 additions & 138 deletions tests/streamlit/test_actions.py

This file was deleted.

0 comments on commit 762aa80

Please sign in to comment.