Skip to content

Commit 64c0ba0

Browse files
Fix integration tests for versioned Streamlit deployment
Update test_streamlit_flow and test_streamlit_deploy_prune_flag to work with versioned Streamlit deployment (now the default behavior). Changes: - test_streamlit_flow: Update stage paths from legacy app_1_stage to versioned snow://streamlit/{DB}.{SCHEMA}.app_1/versions/live/ - test_streamlit_deploy_prune_flag: Rewrite to use managed versioned stages instead of user-created stages Files are now uploaded to managed stages at versions/live/ path instead of user-specified ROOT_LOCATION stages.
1 parent bc27b4e commit 64c0ba0

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

tests_integration/test_streamlit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def test_streamlit_flow(
2525
"app_1", snowflake_session
2626
)
2727

28+
stage_root = f"snow://streamlit/{snowflake_session.database}.{snowflake_session.schema}.app_1/versions/live/"
29+
2830
_streamlit_test_steps.assert_that_only_those_files_were_uploaded(
29-
["app_1_stage/app_1/app_1.py", "app_1_stage/app_1/streamlit_app.py"],
30-
f"{database}.public.app_1_stage",
31+
["app_1.py", "streamlit_app.py"], stage_root, uploaded_to_live_version=True
3132
)
3233
_streamlit_test_steps.assert_that_only_those_entities_are_listed(
3334
[f"{database}.PUBLIC.APP_1"], "APP_1"
@@ -45,8 +46,7 @@ def test_streamlit_flow(
4546
)
4647

4748
_streamlit_test_steps.assert_that_only_those_files_were_uploaded(
48-
["app_1_stage/app_1/app_1.py", "app_1_stage/app_1/streamlit_app.py"],
49-
f"{database}.public.app_1_stage",
49+
["app_1.py", "streamlit_app.py"], stage_root, uploaded_to_live_version=True
5050
)
5151

5252
_streamlit_test_steps.streamlit_describe_should_show_proper_streamlit(

tests_integration/test_streamlit_old.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,53 @@ def test_streamlit_deploy(
113113

114114
@pytest.mark.integration
115115
def test_streamlit_deploy_prune_flag(runner, test_database, project_directory):
116-
stage_name = "streamlit"
116+
# With versioned deployment (default), files are uploaded to a managed stage
117+
# at snow://streamlit/{DB}.{SCHEMA}.{IDENTIFIER}/versions/live
118+
streamlit_identifier = "TEST_STREAMLIT_DEPLOY_SNOWCLI"
119+
versioned_stage_path = f"snow://streamlit/{test_database.upper()}.PUBLIC.{streamlit_identifier}/versions/live"
117120

118121
def _assert_file_names_on_stage(expected_files: List[str]) -> None:
119-
result = runner.invoke_with_connection_json(["stage", "list-files", stage_name])
122+
result = runner.invoke_with_connection_json(
123+
["stage", "list-files", versioned_stage_path]
124+
)
120125
assert result.exit_code == 0, result.output
121-
assert set(file["name"] for file in result.json) == set(expected_files)
126+
actual_files = set(
127+
file["name"].removeprefix("/versions/live/") for file in result.json
128+
)
129+
assert actual_files == set(
130+
expected_files
131+
), f"Expected {expected_files} but got {actual_files}"
122132

123133
with project_directory(f"streamlit_v2") as project_root:
124-
# upload unexpected file on stage
134+
# deploy streamlit first to create the managed stage
135+
result = runner.invoke_with_connection(
136+
["streamlit", "deploy", "my_streamlit", "--replace"]
137+
)
138+
assert result.exit_code == 0, result.output
139+
_assert_file_names_on_stage(["streamlit_app.py"])
140+
141+
# upload unexpected file to the versioned stage
125142
unexpected_file = project_root / "unexpected.txt"
126143
unexpected_file.write_text("This is unexpected")
127-
result = runner.invoke_with_connection(["stage", "create", f"@{stage_name}"])
128-
assert result.exit_code == 0, result.output
129144
result = runner.invoke_with_connection(
130145
[
131146
"stage",
132147
"copy",
133148
str(unexpected_file),
134-
f"@{stage_name}/test_streamlit_deploy_snowcli",
149+
versioned_stage_path,
135150
]
136151
)
137152
assert result.exit_code == 0, result.output
138153

139-
# deploy streamlit - file should remain on stage
154+
# deploy streamlit again without prune - unexpected file should remain on stage
140155
result = runner.invoke_with_connection(
141156
["streamlit", "deploy", "my_streamlit", "--replace"]
142157
)
143158
assert result.exit_code == 0, result.output
144159
_assert_file_names_on_stage(
145160
[
146-
"streamlit/test_streamlit_deploy_snowcli/unexpected.txt",
147-
"streamlit/test_streamlit_deploy_snowcli/streamlit_app.py",
161+
"unexpected.txt",
162+
"streamlit_app.py",
148163
]
149164
)
150165

@@ -153,9 +168,7 @@ def _assert_file_names_on_stage(expected_files: List[str]) -> None:
153168
["streamlit", "deploy", "my_streamlit", "--replace", "--prune"]
154169
)
155170
assert result.exit_code == 0, result.output
156-
_assert_file_names_on_stage(
157-
["streamlit/test_streamlit_deploy_snowcli/streamlit_app.py"]
158-
)
171+
_assert_file_names_on_stage(["streamlit_app.py"])
159172

160173

161174
@pytest.mark.integration

0 commit comments

Comments
 (0)