Skip to content

Commit 8c8cd1e

Browse files
Add more tests for #2184
1 parent b29daf1 commit 8c8cd1e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

test/integ/test_put_get.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,35 +746,44 @@ def test_get_empty_file(tmp_path, conn_cnx):
746746
assert not empty_file.exists()
747747

748748

749+
@pytest.mark.parametrize("auto_compress", ["TRUE", "FALSE"])
749750
@pytest.mark.skipolddriver
750751
@pytest.mark.skipif(IS_WINDOWS, reason="not supported on Windows")
751-
def test_get_file_permission(tmp_path, conn_cnx, caplog):
752+
def test_get_file_permission(tmp_path, conn_cnx, caplog, auto_compress):
752753
test_file = tmp_path / "data.csv"
753754
test_file.write_text("1,2,3\n")
754755
stage_name = random_string(5, "test_get_file_permission_")
756+
755757
with conn_cnx() as cnx:
756758
with cnx.cursor() as cur:
757759
cur.execute(f"create temporary stage {stage_name}")
758760
filename_in_put = str(test_file).replace("\\", "/")
759761
cur.execute(
760-
f"PUT 'file://{filename_in_put}' @{stage_name} AUTO_COMPRESS=FALSE",
762+
f"PUT 'file://{filename_in_put}' @{stage_name} AUTO_COMPRESS={auto_compress}",
761763
)
764+
test_file.unlink()
762765

763766
with caplog.at_level(logging.ERROR):
764767
cur.execute(f"GET @{stage_name}/data.csv file://{tmp_path}")
765768
assert "FileNotFoundError" not in caplog.text
769+
assert len(list(tmp_path.iterdir())) == 1
770+
downloaded_file = next(tmp_path.iterdir())
766771

767772
default_mask = os.umask(0)
768773
os.umask(default_mask)
769774

770775
assert (
771-
oct(os.stat(test_file).st_mode)[-3:] == oct(0o600 & ~default_mask)[-3:]
776+
oct(os.stat(downloaded_file).st_mode)[-3:]
777+
== oct(0o600 & ~default_mask)[-3:]
772778
)
773779

774780

781+
@pytest.mark.parametrize("auto_compress", ["TRUE", "FALSE"])
775782
@pytest.mark.skipolddriver
776783
@pytest.mark.skipif(IS_WINDOWS, reason="not supported on Windows")
777-
def test_get_unsafe_file_permission_when_flag_set(tmp_path, conn_cnx, caplog):
784+
def test_get_unsafe_file_permission_when_flag_set(
785+
tmp_path, conn_cnx, caplog, auto_compress
786+
):
778787
test_file = tmp_path / "data.csv"
779788
test_file.write_text("1,2,3\n")
780789
stage_name = random_string(5, "test_get_file_permission_")
@@ -784,20 +793,24 @@ def test_get_unsafe_file_permission_when_flag_set(tmp_path, conn_cnx, caplog):
784793
cur.execute(f"create temporary stage {stage_name}")
785794
filename_in_put = str(test_file).replace("\\", "/")
786795
cur.execute(
787-
f"PUT 'file://{filename_in_put}' @{stage_name} AUTO_COMPRESS=FALSE",
796+
f"PUT 'file://{filename_in_put}' @{stage_name} AUTO_COMPRESS={auto_compress}",
788797
)
798+
test_file.unlink()
789799

790800
with caplog.at_level(logging.ERROR):
791801
cur.execute(f"GET @{stage_name}/data.csv file://{tmp_path}")
792802
assert "FileNotFoundError" not in caplog.text
803+
assert len(list(tmp_path.iterdir())) == 1
804+
downloaded_file = next(tmp_path.iterdir())
793805

794806
# get the default mask, usually it is 0o022
795807
default_mask = os.umask(0)
796808
os.umask(default_mask)
797809
# files by default are given the permission 644 (Octal)
798810
# umask is for denial, we need to negate
799811
assert (
800-
oct(os.stat(test_file).st_mode)[-3:] == oct(0o666 & ~default_mask)[-3:]
812+
oct(os.stat(downloaded_file).st_mode)[-3:]
813+
== oct(0o666 & ~default_mask)[-3:]
801814
)
802815
cnx.unsafe_file_write = False
803816

0 commit comments

Comments
 (0)