-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afacaea
commit 5014ad1
Showing
11 changed files
with
232 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
from snowflake.cli._plugins.streamlit.streamlit_entity import ( | ||
StreamlitEntity, | ||
) | ||
from snowflake.cli._plugins.streamlit.streamlit_entity_model import ( | ||
StreamlitEntityModel, | ||
) | ||
from snowflake.cli._plugins.workspace.context import WorkspaceContext | ||
from snowflake.cli.api.console import cli_console as cc | ||
from snowflake.cli.api.project.definition_manager import DefinitionManager | ||
|
||
from tests.testing_utils.mock_config import mock_config_key | ||
|
||
|
||
def test_cannot_instantiate_without_feature_flag(): | ||
with pytest.raises(NotImplementedError) as err: | ||
StreamlitEntity() | ||
assert str(err.value) == "Streamlit entity is not implemented yet" | ||
|
||
|
||
def test_nativeapp_children_interface(temp_dir): | ||
with mock_config_key("enable_native_app_children", True): | ||
dm = DefinitionManager() | ||
ctx = WorkspaceContext( | ||
console=cc, | ||
project_root=dm.project_root, | ||
get_default_role=lambda: "mock_role", | ||
get_default_warehouse=lambda: "mock_warehouse", | ||
) | ||
main_file = "main.py" | ||
(Path(temp_dir) / main_file).touch() | ||
model = StreamlitEntityModel( | ||
type="streamlit", | ||
main_file=main_file, | ||
artifacts=[main_file], | ||
) | ||
sl = StreamlitEntity(model, ctx) | ||
|
||
sl.bundle() | ||
bundle_artifact = Path(temp_dir) / "output" / "deploy" / main_file | ||
deploy_sql_str = sl.get_deploy_sql() | ||
grant_sql_str = sl.get_usage_grant_sql(app_role="app_role") | ||
|
||
assert bundle_artifact.exists() | ||
assert deploy_sql_str == "CREATE OR REPLACE STREAMLIT None MAIN_FILE='main.py';" | ||
assert ( | ||
grant_sql_str | ||
== "GRANT USAGE ON STREAMLIT None TO APPLICATION ROLE app_role;" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# README |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This is the v2 version of the napp_init_v1 project | ||
|
||
manifest_version: 1 | ||
|
||
artifacts: | ||
setup_script: setup_script.sql | ||
readme: README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE OR ALTER VERSIONED SCHEMA v_schema; | ||
CREATE APPLICATION ROLE IF NOT EXISTS my_app_role; | ||
GRANT USAGE ON SCHEMA v_schema TO APPLICATION ROLE my_app_role; |
Oops, something went wrong.