diff --git a/botocore/compress.py b/botocore/compress.py index 1ca9f99a7c..d78b3053ed 100644 --- a/botocore/compress.py +++ b/botocore/compress.py @@ -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: diff --git a/tests/functional/test_compress.py b/tests/functional/test_compress.py index e069606b93..53ed482b21 100644 --- a/tests/functional/test_compress.py +++ b/tests/functional/test_compress.py @@ -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": "", @@ -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}." ) diff --git a/tests/unit/test_compress.py b/tests/unit/test_compress.py index 0181cd532c..3cf601b19b 100644 --- a/tests/unit/test_compress.py +++ b/tests/unit/test_compress.py @@ -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 @@ -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, @@ -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 = {} @@ -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', @@ -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', @@ -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, ), @@ -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, ), @@ -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): @@ -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()],