Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/test_transferconfig.py
1569 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import sys
14
15
from awscli.testutils import unittest
16
17
from awscli.customizations.s3 import transferconfig
18
19
20
class TestTransferConfig(unittest.TestCase):
21
22
def build_config_with(self, **config_from_user):
23
return transferconfig.RuntimeConfig().build_config(**config_from_user)
24
25
def test_user_provides_no_config_uses_default(self):
26
# If the user does not provide any config overrides,
27
# we should just use the default values defined in
28
# the module.
29
config = transferconfig.RuntimeConfig()
30
runtime_config = config.build_config()
31
self.assertEqual(runtime_config, transferconfig.DEFAULTS)
32
33
def test_user_provides_partial_overrides(self):
34
config_from_user = {
35
'max_concurrent_requests': '20',
36
'multipart_threshold': str(64 * (1024 ** 2)),
37
}
38
runtime_config = self.build_config_with(**config_from_user)
39
# Our overrides were accepted.
40
self.assertEqual(runtime_config['multipart_threshold'],
41
int(config_from_user['multipart_threshold']))
42
self.assertEqual(runtime_config['max_concurrent_requests'],
43
int(config_from_user['max_concurrent_requests']))
44
# And defaults were used for values not specified.
45
self.assertEqual(runtime_config['max_queue_size'],
46
int(transferconfig.DEFAULTS['max_queue_size']))
47
48
def test_validates_integer_types(self):
49
with self.assertRaises(transferconfig.InvalidConfigError):
50
self.build_config_with(max_concurrent_requests="not an int")
51
52
def test_validates_positive_integers(self):
53
with self.assertRaises(transferconfig.InvalidConfigError):
54
self.build_config_with(max_concurrent_requests="-10")
55
56
def test_min_value(self):
57
with self.assertRaises(transferconfig.InvalidConfigError):
58
self.build_config_with(max_concurrent_requests="0")
59
60
def test_human_readable_sizes_converted_to_bytes(self):
61
runtime_config = self.build_config_with(multipart_threshold="10MB")
62
self.assertEqual(runtime_config['multipart_threshold'],
63
10 * 1024 * 1024)
64
65
def test_long_value(self):
66
# MAXSIZE is the max size of an int on python 2 and the maximum size
67
# of Py_ssize_t on python 3, but notably not the maximum size of an
68
# int since they are effectively unbounded.
69
long_value = sys.maxsize + 1
70
runtime_config = self.build_config_with(
71
multipart_threshold=long_value)
72
self.assertEqual(runtime_config['multipart_threshold'], long_value)
73
74
def test_converts_max_bandwidth_as_string(self):
75
runtime_config = self.build_config_with(max_bandwidth='1MB/s')
76
self.assertEqual(runtime_config['max_bandwidth'], 1024 * 1024)
77
78
def test_validates_max_bandwidth_no_seconds(self):
79
with self.assertRaises(transferconfig.InvalidConfigError):
80
self.build_config_with(max_bandwidth='1MB')
81
82
def test_validates_max_bandwidth_in_bits_per_second(self):
83
with self.assertRaises(transferconfig.InvalidConfigError):
84
self.build_config_with(max_bandwidth='1Mb/s')
85
86
87
class TestConvertToS3TransferConfig(unittest.TestCase):
88
def test_convert(self):
89
runtime_config = {
90
'multipart_threshold': 1,
91
'multipart_chunksize': 2,
92
'max_concurrent_requests': 3,
93
'max_queue_size': 4,
94
'max_bandwidth': 1024 * 1024,
95
'addressing_style': 'path',
96
'use_accelerate_endpoint': True,
97
# This is a TransferConfig only option, it should
98
# just be ignored if it's in the ~/.aws/config for now.
99
'max_in_memory_upload_chunks': 1000,
100
}
101
result = transferconfig.create_transfer_config_from_runtime_config(
102
runtime_config)
103
self.assertEqual(result.multipart_threshold, 1)
104
self.assertEqual(result.multipart_chunksize, 2)
105
self.assertEqual(result.max_request_concurrency, 3)
106
self.assertEqual(result.max_request_queue_size, 4)
107
self.assertEqual(result.max_bandwidth, 1024 * 1024)
108
self.assertNotEqual(result.max_in_memory_upload_chunks, 1000)
109
110