|
18 | 18 | import tempfile
|
19 | 19 | import time
|
20 | 20 | from pathlib import Path
|
| 21 | + |
21 | 22 | import pytest
|
22 | 23 |
|
23 | 24 | from tests.stage.test_stage import RecursiveUploadTester, NESTED_STRUCTURE
|
@@ -788,6 +789,54 @@ def test_recursive_upload_glob_file_pattern(temporary_directory, runner, test_da
|
788 | 789 | ]
|
789 | 790 |
|
790 | 791 |
|
| 792 | +@pytest.mark.integration |
| 793 | +def test_stage_copy_refreshes_stream( |
| 794 | + runner, snowflake_session, test_database, tmp_path |
| 795 | +): |
| 796 | + stage_name = "test_stage_stream" |
| 797 | + stage_name_with_at = "@" + stage_name |
| 798 | + stream_name = "test_stream" |
| 799 | + |
| 800 | + # Create stage and stream |
| 801 | + runner.invoke_with_connection_json( |
| 802 | + ["stage", "create", stage_name_with_at, "--enable-directory"] |
| 803 | + ) |
| 804 | + snowflake_session.execute_string( |
| 805 | + f"CREATE OR REPLACE STREAM {stream_name} ON STAGE {stage_name}" |
| 806 | + ) |
| 807 | + |
| 808 | + # Create test file |
| 809 | + test_file = tmp_path / "test.txt" |
| 810 | + test_file.write_text("test content") |
| 811 | + |
| 812 | + # Initial copy without --refresh |
| 813 | + result = runner.invoke_with_connection_json( |
| 814 | + ["stage", "copy", str(test_file), stage_name_with_at] |
| 815 | + ) |
| 816 | + assert result.exit_code == 0 |
| 817 | + |
| 818 | + # Check stream has no changes |
| 819 | + stream_changes_cursor = snowflake_session.execute_string( |
| 820 | + f"SELECT * FROM {stream_name}" |
| 821 | + ) |
| 822 | + stream_changes = row_from_snowflake_session(stream_changes_cursor) |
| 823 | + assert len(stream_changes) == 0 |
| 824 | + |
| 825 | + # Copy again with --refresh flag |
| 826 | + result = runner.invoke_with_connection_json( |
| 827 | + ["stage", "copy", str(test_file), stage_name_with_at, "--refresh"] |
| 828 | + ) |
| 829 | + assert result.exit_code == 0 |
| 830 | + |
| 831 | + # Check stream has changes after --refresh was specified |
| 832 | + stream_changes_cursor = snowflake_session.execute_string( |
| 833 | + f"SELECT * FROM {stream_name}" |
| 834 | + ) |
| 835 | + stream_changes = row_from_snowflake_session(stream_changes_cursor) |
| 836 | + assert len(stream_changes) == 1 |
| 837 | + assert stream_changes[0]["RELATIVE_PATH"] == "test.txt" |
| 838 | + |
| 839 | + |
791 | 840 | @pytest.mark.integration
|
792 | 841 | def test_recursive_upload_no_recursive_glob_pattern(
|
793 | 842 | temporary_directory, runner, test_database
|
@@ -866,3 +915,24 @@ def test_create_encryption(runner, test_database, encryption):
|
866 | 915 | )
|
867 | 916 | assert result.exit_code == 0, result.output
|
868 | 917 | assert result.json == {"status": f"Stage area A_STAGE successfully created."}
|
| 918 | + |
| 919 | + |
| 920 | +@pytest.mark.integration |
| 921 | +def test_create_directory_option(runner, test_database): |
| 922 | + stage_name = "stage_with_directory" |
| 923 | + result = runner.invoke_with_connection_json( |
| 924 | + ["stage", "create", stage_name, "--enable-directory"] |
| 925 | + ) |
| 926 | + assert result.exit_code == 0, result.output |
| 927 | + assert result.json == { |
| 928 | + "status": f"Stage area {stage_name.upper()} successfully created." |
| 929 | + } |
| 930 | + |
| 931 | + # Verify directory is enabled |
| 932 | + result = runner.invoke_with_connection_json(["stage", "describe", stage_name]) |
| 933 | + assert result.exit_code == 0, result.output |
| 934 | + assert any( |
| 935 | + row.get("parent_property") == "DIRECTORY" |
| 936 | + and row.get("property_value") == "true" |
| 937 | + for row in result.json |
| 938 | + ) |
0 commit comments