|
1 | 1 | # |
2 | 2 | # Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. |
3 | 3 | # |
| 4 | +from os import path |
| 5 | +from unittest.mock import MagicMock |
| 6 | + |
| 7 | +try: |
| 8 | + from snowflake.connector import SnowflakeConnection |
| 9 | + from snowflake.connector.constants import ResultStatus |
| 10 | + from snowflake.connector.file_transfer_agent import ( |
| 11 | + SnowflakeFileMeta, |
| 12 | + StorageCredential, |
| 13 | + ) |
| 14 | + from snowflake.connector.s3_storage_client import SnowflakeS3RestClient |
| 15 | +except ImportError: |
| 16 | + # Compatibility for olddriver tests |
| 17 | + from snowflake.connector.s3_util import ERRORNO_WSAECONNABORTED # NOQA |
| 18 | + |
| 19 | + SnowflakeFileMeta = dict |
| 20 | + SnowflakeS3RestClient = None |
| 21 | + RequestExceedMaxRetryError = None |
| 22 | + StorageCredential = None |
| 23 | + megabytes = 1024 * 1024 |
| 24 | + DEFAULT_MAX_RETRY = 5 |
| 25 | + |
| 26 | +THIS_DIR = path.dirname(path.realpath(__file__)) |
| 27 | +megabyte = 1024 * 1024 |
| 28 | + |
| 29 | + |
| 30 | +def test_status_when_num_of_chunks_is_zero(): |
| 31 | + meta_info = { |
| 32 | + "name": "data1.txt.gz", |
| 33 | + "stage_location_type": "S3", |
| 34 | + "no_sleeping_time": True, |
| 35 | + "put_callback": None, |
| 36 | + "put_callback_output_stream": None, |
| 37 | + "sha256_digest": "123456789abcdef", |
| 38 | + "dst_file_name": "data1.txt.gz", |
| 39 | + "src_file_name": path.join(THIS_DIR, "../data", "put_get_1.txt"), |
| 40 | + "overwrite": True, |
| 41 | + } |
| 42 | + meta = SnowflakeFileMeta(**meta_info) |
| 43 | + creds = {"AWS_SECRET_KEY": "", "AWS_KEY_ID": "", "AWS_TOKEN": ""} |
| 44 | + rest_client = SnowflakeS3RestClient( |
| 45 | + meta, |
| 46 | + StorageCredential( |
| 47 | + creds, |
| 48 | + MagicMock(autospec=SnowflakeConnection), |
| 49 | + "PUT file:/tmp/file.txt @~", |
| 50 | + ), |
| 51 | + { |
| 52 | + "locationType": "AWS", |
| 53 | + "location": "bucket/path", |
| 54 | + "creds": creds, |
| 55 | + "region": "test", |
| 56 | + "endPoint": None, |
| 57 | + }, |
| 58 | + 8 * megabyte, |
| 59 | + ) |
| 60 | + rest_client.successful_transfers = 0 |
| 61 | + rest_client.num_of_chunks = 0 |
| 62 | + rest_client.finish_upload() |
| 63 | + assert meta.result_status == ResultStatus.ERROR |
0 commit comments