Path: blob/develop/tests/unit/customizations/s3/test_transferconfig.py
1569 views
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import sys1314from awscli.testutils import unittest1516from awscli.customizations.s3 import transferconfig171819class TestTransferConfig(unittest.TestCase):2021def build_config_with(self, **config_from_user):22return transferconfig.RuntimeConfig().build_config(**config_from_user)2324def test_user_provides_no_config_uses_default(self):25# If the user does not provide any config overrides,26# we should just use the default values defined in27# the module.28config = transferconfig.RuntimeConfig()29runtime_config = config.build_config()30self.assertEqual(runtime_config, transferconfig.DEFAULTS)3132def test_user_provides_partial_overrides(self):33config_from_user = {34'max_concurrent_requests': '20',35'multipart_threshold': str(64 * (1024 ** 2)),36}37runtime_config = self.build_config_with(**config_from_user)38# Our overrides were accepted.39self.assertEqual(runtime_config['multipart_threshold'],40int(config_from_user['multipart_threshold']))41self.assertEqual(runtime_config['max_concurrent_requests'],42int(config_from_user['max_concurrent_requests']))43# And defaults were used for values not specified.44self.assertEqual(runtime_config['max_queue_size'],45int(transferconfig.DEFAULTS['max_queue_size']))4647def test_validates_integer_types(self):48with self.assertRaises(transferconfig.InvalidConfigError):49self.build_config_with(max_concurrent_requests="not an int")5051def test_validates_positive_integers(self):52with self.assertRaises(transferconfig.InvalidConfigError):53self.build_config_with(max_concurrent_requests="-10")5455def test_min_value(self):56with self.assertRaises(transferconfig.InvalidConfigError):57self.build_config_with(max_concurrent_requests="0")5859def test_human_readable_sizes_converted_to_bytes(self):60runtime_config = self.build_config_with(multipart_threshold="10MB")61self.assertEqual(runtime_config['multipart_threshold'],6210 * 1024 * 1024)6364def test_long_value(self):65# MAXSIZE is the max size of an int on python 2 and the maximum size66# of Py_ssize_t on python 3, but notably not the maximum size of an67# int since they are effectively unbounded.68long_value = sys.maxsize + 169runtime_config = self.build_config_with(70multipart_threshold=long_value)71self.assertEqual(runtime_config['multipart_threshold'], long_value)7273def test_converts_max_bandwidth_as_string(self):74runtime_config = self.build_config_with(max_bandwidth='1MB/s')75self.assertEqual(runtime_config['max_bandwidth'], 1024 * 1024)7677def test_validates_max_bandwidth_no_seconds(self):78with self.assertRaises(transferconfig.InvalidConfigError):79self.build_config_with(max_bandwidth='1MB')8081def test_validates_max_bandwidth_in_bits_per_second(self):82with self.assertRaises(transferconfig.InvalidConfigError):83self.build_config_with(max_bandwidth='1Mb/s')848586class TestConvertToS3TransferConfig(unittest.TestCase):87def test_convert(self):88runtime_config = {89'multipart_threshold': 1,90'multipart_chunksize': 2,91'max_concurrent_requests': 3,92'max_queue_size': 4,93'max_bandwidth': 1024 * 1024,94'addressing_style': 'path',95'use_accelerate_endpoint': True,96# This is a TransferConfig only option, it should97# just be ignored if it's in the ~/.aws/config for now.98'max_in_memory_upload_chunks': 1000,99}100result = transferconfig.create_transfer_config_from_runtime_config(101runtime_config)102self.assertEqual(result.multipart_threshold, 1)103self.assertEqual(result.multipart_chunksize, 2)104self.assertEqual(result.max_request_concurrency, 3)105self.assertEqual(result.max_request_queue_size, 4)106self.assertEqual(result.max_bandwidth, 1024 * 1024)107self.assertNotEqual(result.max_in_memory_upload_chunks, 1000)108109110