Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlm committed Jun 27, 2023
1 parent 2b3d6f5 commit bd45734
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
14 changes: 9 additions & 5 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,22 @@ def _compute_request_compression_config(self, config_kwargs):

def _validate_min_compression_size(self, min_size):
if min_size is not None:
error_msg_base = (
f'Invalid value "{min_size}" for '
'request_min_compression_size_bytes. '
)
try:
min_size = int(min_size)
except ValueError:
raise botocore.exceptions.InvalidConfigError(
error_msg=f"Invalid value '{min_size}' for "
"request_min_compression_size_bytes. Value must be an integer."
error_msg=f'{error_msg_base}Value must be an integer.'
)
if not 0 <= min_size <= 1048576:
raise botocore.exceptions.InvalidConfigError(
error_msg=f"Invalid value '{min_size}' for "
"request_min_compression_size_bytes. Value must be between 0 "
"and 1048576."
error_msg=(
f'{error_msg_base}Value must '
'be between 0 and 1048576.'
)
)

def _ensure_boolean(self, val):
Expand Down
2 changes: 1 addition & 1 deletion botocore/awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def prepare(self):

@property
def body(self):
body = self._request_preparer._prepare_body(self)
body = self.prepare().body
if isinstance(body, str):
body = body.encode('utf-8')
return body
Expand Down
6 changes: 3 additions & 3 deletions botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,10 @@ def remove_content_type_header_for_presigning(request, **kwargs):


def urlencode_body(model, params, context, **kwargs):
"""Url encode the request body if it is a dictionary.
"""URL-encode the request body if it is a dictionary.
This is used for services using the query protocol. The body must be serialized
as a urlencoded string before it can be compressed.
This is used for services using the query protocol. The body must be
serialized as a URL-encoded string before it can be compressed.
"""
body = params.get('body')
if (
Expand Down
7 changes: 5 additions & 2 deletions tests/functional/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from botocore.config import Config
from tests import ALL_SERVICES, ClientHTTPStubber, patch_load_service_model

KNOWN_COMPRESSION_ENCODINGS = "gzip"
KNOWN_COMPRESSION_ENCODINGS = ("gzip",)

FAKE_MODEL = {
"version": "2.0",
Expand Down Expand Up @@ -114,7 +114,10 @@ def test_compression(patched_session, monkeypatch):
with ClientHTTPStubber(client, strict=True) as http_stubber:
http_stubber.add_response(
status=200,
body=b'<response><status>success</status><message>Request processed successfully</message></response>',
body=(
b"<response><status>success</status><message>"
b"Request processed successfully</message></response>",
),
)
client.mock_operation(
MockOpParamList=[
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_context_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def test_static_context_param_sent_to_endpoint_resolver(
client = patched_session.create_client(
service_name, region_name='us-east-1'
)

with ClientHTTPStubber(client, strict=True) as http_stubber:
http_stubber.add_response(status=200)
with mock.patch.object(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_awsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def request_dict_with_content_encoding_header():
}


@pytest.fixture(scope="module")
@pytest.fixture(scope='module')
def request_compressor():
return RequestCompressor()

Expand Down Expand Up @@ -989,14 +989,14 @@ def test_iteration(self):
request_dict_with_content_encoding_header(),
OP_UNKNOWN_COMPRESSION,
False,
"foo",
'foo',
),
(
COMPRESSION_CONFIG_128_BYTES,
request_dict_with_content_encoding_header(),
OP_WITH_COMPRESSION,
True,
"gzip",
'gzip',
),
],
)
Expand Down Expand Up @@ -1028,7 +1028,7 @@ def test_compress_bad_types(request_compressor, body):

@pytest.mark.parametrize(
'body',
[io.StringIO("foo"), io.BytesIO(b"foo")],
[io.StringIO('foo'), io.BytesIO(b'foo')],
)
def test_body_streams_position_reset(request_compressor, body):
request_compressor.compress(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ def test_events_are_per_client(self):
second_client = creator.create_client(
'myservice', 'us-west-2', credentials=self.credentials
)

first_client.meta.events.register('before-call', first_handler)
second_client.meta.events.register('before-call', second_handler)

Expand Down

0 comments on commit bd45734

Please sign in to comment.