22
22
except ImportError :
23
23
from test .randomize import random_string
24
24
25
- from test .generate_test_files import generate_k_lines_of_n_files
26
-
27
25
try :
28
- from .. parameters import CONNECTION_PARAMETERS_ADMIN
26
+ from src . snowflake . connector . compat import IS_WINDOWS
29
27
except ImportError :
30
- CONNECTION_PARAMETERS_ADMIN = {}
28
+ import platform
29
+
30
+ IS_WINDOWS = platform .system () == "Windows"
31
+
32
+ from test .generate_test_files import generate_k_lines_of_n_files
31
33
32
34
THIS_DIR = path .dirname (path .realpath (__file__ ))
33
35
@@ -154,7 +156,9 @@ async def test_get_empty_file(tmp_path, aio_connection):
154
156
assert not empty_file .exists ()
155
157
156
158
157
- async def test_get_file_permission (tmp_path , aio_connection , caplog ):
159
+ @pytest .mark .parametrize ("auto_compress" , ["TRUE" , "FALSE" ])
160
+ @pytest .mark .skipif (IS_WINDOWS , reason = "not supported on Windows" )
161
+ async def test_get_file_permission (tmp_path , aio_connection , caplog , auto_compress ):
158
162
test_file = tmp_path / "data.csv"
159
163
test_file .write_text ("1,2,3\n " )
160
164
stage_name = random_string (5 , "test_get_empty_file_" )
@@ -163,19 +167,54 @@ async def test_get_file_permission(tmp_path, aio_connection, caplog):
163
167
await cur .execute (f"create temporary stage { stage_name } " )
164
168
filename_in_put = str (test_file ).replace ("\\ " , "/" )
165
169
await cur .execute (
166
- f"PUT 'file://{ filename_in_put } ' @{ stage_name } " ,
170
+ f"PUT 'file://{ filename_in_put } ' @{ stage_name } AUTO_COMPRESS={ auto_compress } " ,
171
+ )
172
+ test_file .unlink ()
173
+
174
+ with caplog .at_level (logging .ERROR ):
175
+ await cur .execute (f"GET @{ stage_name } /data.csv file://{ tmp_path } " )
176
+ assert "FileNotFoundError" not in caplog .text
177
+ assert len (list (tmp_path .iterdir ())) == 1
178
+ downloaded_file = next (tmp_path .iterdir ())
179
+
180
+ # get the default mask, usually it is 0o022
181
+ default_mask = os .umask (0 )
182
+ os .umask (default_mask )
183
+ # files by default are given the permission 600 (Octal)
184
+ # umask is for denial, we need to negate
185
+ assert oct (os .stat (downloaded_file ).st_mode )[- 3 :] == oct (0o600 & ~ default_mask )[- 3 :]
186
+
187
+
188
+ @pytest .mark .parametrize ("auto_compress" , ["TRUE" , "FALSE" ])
189
+ @pytest .mark .skipif (IS_WINDOWS , reason = "not supported on Windows" )
190
+ async def test_get_unsafe_file_permission_when_flag_set (
191
+ tmp_path , aio_connection , caplog , auto_compress
192
+ ):
193
+ test_file = tmp_path / "data.csv"
194
+ test_file .write_text ("1,2,3\n " )
195
+ stage_name = random_string (5 , "test_get_empty_file_" )
196
+ await aio_connection .connect ()
197
+ aio_connection .unsafe_file_write = True
198
+ cur = aio_connection .cursor ()
199
+ await cur .execute (f"create temporary stage { stage_name } " )
200
+ filename_in_put = str (test_file ).replace ("\\ " , "/" )
201
+ await cur .execute (
202
+ f"PUT 'file://{ filename_in_put } ' @{ stage_name } AUTO_COMPRESS={ auto_compress } " ,
167
203
)
204
+ test_file .unlink ()
168
205
169
206
with caplog .at_level (logging .ERROR ):
170
207
await cur .execute (f"GET @{ stage_name } /data.csv file://{ tmp_path } " )
171
208
assert "FileNotFoundError" not in caplog .text
209
+ assert len (list (tmp_path .iterdir ())) == 1
210
+ downloaded_file = next (tmp_path .iterdir ())
172
211
173
212
# get the default mask, usually it is 0o022
174
213
default_mask = os .umask (0 )
175
214
os .umask (default_mask )
176
- # files by default are given the permission 644 (Octal)
215
+ # when unsafe_file_write is set, permission is 644 (Octal)
177
216
# umask is for denial, we need to negate
178
- assert oct (os .stat (test_file ).st_mode )[- 3 :] == oct (0o666 & ~ default_mask )[- 3 :]
217
+ assert oct (os .stat (downloaded_file ).st_mode )[- 3 :] == oct (0o666 & ~ default_mask )[- 3 :]
179
218
180
219
181
220
async def test_get_multiple_files_with_same_name (tmp_path , aio_connection , caplog ):
0 commit comments