|
3 | 3 |
|
4 | 4 | from os import chmod, path |
5 | 5 | from unittest import mock |
| 6 | +from unittest.mock import patch |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 |
|
@@ -252,3 +253,43 @@ def test_iobound_limit(tmp_path): |
252 | 253 | pass |
253 | 254 | # 2 IObound TPEs should be created for 3 files limited to 2 |
254 | 255 | assert len(list(filter(lambda e: e.args == (2,), tpe.call_args_list))) == 2 |
| 256 | + |
| 257 | + |
| 258 | +def test_strip_stage_prefix_from_dst_file_name_for_download(): |
| 259 | + """Verifies that _strip_stage_prefix_from_dst_file_name_for_download is called when initializing file meta. |
| 260 | +
|
| 261 | + Workloads like sproc will need to monkeypatch _strip_stage_prefix_from_dst_file_name_for_download on the server side |
| 262 | + to maintain its behavior. So we add this unit test to make sure that we do not accidentally refactor this method and |
| 263 | + break sproc workloads. |
| 264 | + """ |
| 265 | + file = "test.txt" |
| 266 | + agent = SnowflakeFileTransferAgent( |
| 267 | + mock.MagicMock(autospec=SnowflakeCursor), |
| 268 | + "GET @stage_foo/test.txt file:///tmp", |
| 269 | + { |
| 270 | + "data": { |
| 271 | + "localLocation": "/tmp", |
| 272 | + "command": "DOWNLOAD", |
| 273 | + "autoCompress": False, |
| 274 | + "src_locations": [file], |
| 275 | + "sourceCompression": "none", |
| 276 | + "stageInfo": { |
| 277 | + "creds": {}, |
| 278 | + "location": "", |
| 279 | + "locationType": "S3", |
| 280 | + "path": "remote_loc", |
| 281 | + }, |
| 282 | + }, |
| 283 | + "success": True, |
| 284 | + }, |
| 285 | + ) |
| 286 | + agent._parse_command() |
| 287 | + with patch.object( |
| 288 | + agent, |
| 289 | + "_strip_stage_prefix_from_dst_file_name_for_download", |
| 290 | + return_value="mock value", |
| 291 | + ): |
| 292 | + agent._init_file_metadata() |
| 293 | + agent._strip_stage_prefix_from_dst_file_name_for_download.assert_called_with( |
| 294 | + file |
| 295 | + ) |
0 commit comments