Skip to content

Commit

Permalink
fixed max allowed min compression size, added test for it and moved c…
Browse files Browse the repository at this point in the history
…ompression config tests to test_args
  • Loading branch information
davidlm committed Jul 17, 2023
1 parent b76108c commit 6e08cee
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 81 deletions.
2 changes: 1 addition & 1 deletion botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def _compute_request_compression_config(self, config_kwargs):

def _validate_min_compression_size(self, min_size):
min_allowed_min_size = 0
max_allowed_min_size = 10485760
max_allowed_min_size = 1048576
if min_size is not None:
error_msg_base = (
f'Invalid value "{min_size}" for '
Expand Down
75 changes: 75 additions & 0 deletions tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,81 @@ def test_doesnt_create_ruleset_resolver_if_not_given_data(self):
)
m.assert_not_called()

def test_request_compression_client_config(self):
config = self.call_get_client_args(
client_config=Config(
disable_request_compression=True,
request_min_compression_size_bytes=100,
)
)['client_config']
self.assertEqual(config.request_min_compression_size_bytes, 100)
self.assertTrue(config.disable_request_compression)

def test_request_compression_config_store(self):
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 100
)
self.config_store.set_config_variable(
'disable_request_compression', True
)
config = self.call_get_client_args()['client_config']
self.assertEqual(config.request_min_compression_size_bytes, 100)
self.assertTrue(config.disable_request_compression)

def test_request_compression_client_config_overrides_config_store(self):
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 100
)
self.config_store.set_config_variable(
'disable_request_compression', True
)
config = self.call_get_client_args(
client_config=Config(
disable_request_compression=False,
request_min_compression_size_bytes=0,
)
)['client_config']
self.assertEqual(config.request_min_compression_size_bytes, 0)
self.assertFalse(config.disable_request_compression)

def test_bad_type_request_min_compression_size_bytes(self):
with self.assertRaises(exceptions.InvalidConfigError):
self.call_get_client_args(
client_config=Config(
request_min_compression_size_bytes='foo',
),
)
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 'foo'
)
with self.assertRaises(exceptions.InvalidConfigError):
self.call_get_client_args()

def test_bad_value_request_min_compression_size_bytes(self):
with self.assertRaises(exceptions.InvalidConfigError):
self.call_get_client_args(
client_config=Config(
request_min_compression_size_bytes=-1,
),
)
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 99999999
)
with self.assertRaises(exceptions.InvalidConfigError):
self.call_get_client_args(
client_config=Config(
request_min_compression_size_bytes=-1,
),
)

def test_bad_value_disable_request_compression(self):
config = self.call_get_client_args(
client_config=Config(
disable_request_compression='foo',
),
)['client_config']
self.assertFalse(config.disable_request_compression)


class TestEndpointResolverBuiltins(unittest.TestCase):
def setUp(self):
Expand Down
80 changes: 0 additions & 80 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from botocore.endpoint import DEFAULT_TIMEOUT
from botocore.errorfactory import ClientExceptionsFactory
from botocore.exceptions import (
InvalidConfigError,
InvalidMaxRetryAttemptsError,
InvalidRetryConfigurationError,
InvalidRetryModeError,
Expand Down Expand Up @@ -1690,85 +1689,6 @@ def test_client_close_context_manager(self):

self.endpoint.close.assert_called_once_with()

def test_request_compression_client_config(self):
creator = self.create_client_creator()
service_client = creator.create_client(
'myservice',
'us-west-2',
credentials=self.credentials,
client_config=botocore.config.Config(
disable_request_compression=True,
request_min_compression_size_bytes=100,
),
)
self.assertEqual(
service_client.meta.config.request_min_compression_size_bytes, 100
)
self.assertTrue(service_client.meta.config.disable_request_compression)

def test_request_compression_config_store(self):
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 100
)
self.config_store.set_config_variable(
'disable_request_compression', True
)
creator = self.create_client_creator()
service_client = creator.create_client(
'myservice',
'us-west-2',
credentials=self.credentials,
)
self.assertEqual(
service_client.meta.config.request_min_compression_size_bytes, 100
)
self.assertTrue(service_client.meta.config.disable_request_compression)

def test_request_compression_client_config_overrides_config_store(self):
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 100
)
self.config_store.set_config_variable(
'disable_request_compression', True
)
creator = self.create_client_creator()
service_client = creator.create_client(
'myservice',
'us-west-2',
credentials=self.credentials,
client_config=botocore.config.Config(
disable_request_compression=False,
request_min_compression_size_bytes=0,
),
)
self.assertEqual(
service_client.meta.config.request_min_compression_size_bytes, 0
)
self.assertFalse(
service_client.meta.config.disable_request_compression
)

def test_bad_request_min_compression_size_bytes(self):
creator = self.create_client_creator()
with self.assertRaises(InvalidConfigError):
creator.create_client(
'myservice',
'us-west-2',
credentials=self.credentials,
client_config=botocore.config.Config(
request_min_compression_size_bytes='foo',
),
)
self.config_store.set_config_variable(
'request_min_compression_size_bytes', 'foo'
)
with self.assertRaises(InvalidConfigError):
creator.create_client(
'myservice',
'us-west-2',
credentials=self.credentials,
)


class TestClientErrors(TestAutoGeneratedClient):
def add_error_response(self, error_response):
Expand Down

0 comments on commit 6e08cee

Please sign in to comment.