Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlm committed Jul 27, 2023
1 parent a5071e1 commit 8ed62a8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
5 changes: 2 additions & 3 deletions botocore/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def _should_compress_request(config, request_dict, operation_model):
):
if not _is_compressible_type(request_dict):
body_type = type(request_dict['body'])
logger.debug(
'Body type %s does not support compression.', body_type
)
log_msg = 'Body type %s does not support compression.'
logger.debug(log_msg, body_type)
return False

if operation_model.has_streaming_input:
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import pytest

from botocore.compress import COMPRESSION_MAPPING
from botocore.config import Config
from tests import ALL_SERVICES, ClientHTTPStubber, patch_load_service_model

KNOWN_COMPRESSION_ENCODINGS = ("gzip",)

FAKE_MODEL = {
"version": "2.0",
"documentation": "",
Expand Down Expand Up @@ -97,7 +96,7 @@ def _all_compression_operations():
@pytest.mark.parametrize("operation_model", _all_compression_operations())
def test_no_unknown_compression_encodings(operation_model):
for encoding in operation_model.request_compression["encodings"]:
assert encoding in KNOWN_COMPRESSION_ENCODINGS, (
assert encoding in COMPRESSION_MAPPING.keys(), (
f"Found unknown compression encoding '{encoding}' "
f"in operation {operation_model.name}."
)
Expand Down
76 changes: 53 additions & 23 deletions tests/unit/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""
NOTE: All classes and functions in this module are considered private and are
subject to abrupt breaking changes. Please do not use them directly.
"""
import gzip
import io
from copy import deepcopy
Expand Down Expand Up @@ -59,9 +64,10 @@ def _make_op(

REQUEST_BODY_STRING = REQUEST_BODY.decode('utf-8')

DEFAULT_COMPRESSION_CONFIG = Config(

COMPRESSION_CONFIG_10240_BYTES = Config(
disable_request_compression=False,
request_min_compression_size_bytes=10420,
request_min_compression_size_bytes=10240,
)
COMPRESSION_CONFIG_128_BYTES = Config(
disable_request_compression=False,
Expand All @@ -81,9 +87,7 @@ def read(self, size=None):
return self._buffer.read(size)


def _request_dict(body=None, headers=None):
if body is None:
body = b''
def _request_dict(body=b'', headers=None):
if headers is None:
headers = {}

Expand Down Expand Up @@ -184,7 +188,7 @@ def assert_compression(original_body, request_dict, encoding):
'gzip',
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
default_request_dict(),
STREAMING_OP_WITH_COMPRESSION,
'gzip',
Expand Down Expand Up @@ -237,13 +241,13 @@ def test_compression(config, request_dict, operation_model, encoding):
'config, request_dict, operation_model, encoding',
[
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_non_seekable_bytes_stream(),
STREAMING_OP_WITH_COMPRESSION,
'gzip',
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_non_seekable_text_stream(),
STREAMING_OP_WITH_COMPRESSION,
'gzip',
Expand Down Expand Up @@ -280,12 +284,12 @@ def test_compression_non_seekable_streams(
OP_WITH_COMPRESSION,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
default_request_dict(),
STREAMING_OP_WITH_COMPRESSION_REQUIRES_LENGTH,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
default_request_dict(),
OP_NO_COMPRESSION,
),
Expand All @@ -295,22 +299,22 @@ def test_compression_non_seekable_streams(
OP_UNKNOWN_COMPRESSION,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_string(),
OP_WITH_COMPRESSION,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_bytearray(),
OP_WITH_COMPRESSION,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_bytes_io(),
OP_WITH_COMPRESSION,
),
(
DEFAULT_COMPRESSION_CONFIG,
COMPRESSION_CONFIG_10240_BYTES,
request_dict_string_io(),
OP_WITH_COMPRESSION,
),
Expand All @@ -329,6 +333,41 @@ def test_compression_non_seekable_streams(
request_dict_non_seekable_text_stream(),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
request_dict_non_seekable_text_stream(),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(1),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(1.0),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(object()),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(True),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(None),
OP_WITH_COMPRESSION,
),
(
COMPRESSION_CONFIG_1_BYTE,
_request_dict(set()),
OP_WITH_COMPRESSION,
),
],
)
def test_no_compression(config, request_dict, operation_model):
Expand All @@ -350,15 +389,6 @@ def test_dict_no_compression():
assert body == encoded_body.encode('utf-8')


@pytest.mark.parametrize('body', [1, object(), True, 1.0])
def test_maybe_compress_bad_types(body):
request_dict = _request_dict(body)
maybe_compress_request(
COMPRESSION_CONFIG_1_BYTE, request_dict, OP_WITH_COMPRESSION
)
assert request_dict['body'] is body


@pytest.mark.parametrize(
'request_dict',
[request_dict_string_io(), request_dict_bytes_io()],
Expand Down

0 comments on commit 8ed62a8

Please sign in to comment.