Skip to content

Commit

Permalink
Avoid importing _CHECKSUM_CLS directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Nov 1, 2024
1 parent e9eade8 commit ce46e4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from botocore import credentials, utils
from botocore.awsrequest import AWSResponse
from botocore.compat import HAS_CRT, parse_qs, urlparse
from botocore.httpchecksum import _CHECKSUM_CLS, DEFAULT_CHECKSUM_ALGORITHM
from botocore.stub import Stubber

_LOADER = botocore.loaders.Loader()
Expand Down Expand Up @@ -597,3 +598,13 @@ def mock_load_service_model(service_name, type_name, api_version=None):

loader = session.get_component('data_loader')
monkeypatch.setattr(loader, 'load_service_model', mock_load_service_model)


def get_checksum_cls(algorithm=DEFAULT_CHECKSUM_ALGORITHM.lower()):
"""
This pass through is grabbing our internally supported list of checksums
to ensure we stay in sync, while not exposing them publicly.
Returns the default checksum algorithm class if none is specified.
"""
return _CHECKSUM_CLS[algorithm]
4 changes: 2 additions & 2 deletions tests/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
UnsupportedS3AccesspointConfigurationError,
UnsupportedS3ConfigurationError,
)
from botocore.httpchecksum import HAS_CRT, Crc32Checksum, CrtCrc32Checksum
from tests import (
BaseSessionTest,
ClientHTTPStubber,
FreezeTime,
create_session,
get_checksum_cls,
mock,
requires_crt,
temporary_file,
Expand Down Expand Up @@ -3738,7 +3738,7 @@ def _verify_presigned_url_addressing(

class TestS3XMLPayloadEscape(BaseS3OperationTest):
def assert_correct_crc32_checksum(self, request):
checksum = CrtCrc32Checksum() if HAS_CRT else Crc32Checksum()
checksum = get_checksum_cls()()
crc32_checksum = checksum.handle(request.body).encode()
self.assertEqual(
crc32_checksum, request.headers["x-amz-checksum-crc32"]
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/test_httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
MissingDependencyException,
)
from botocore.httpchecksum import (
_CHECKSUM_CLS,
AwsChunkedWrapper,
Crc32Checksum,
CrtCrc32cChecksum,
Expand All @@ -37,7 +36,7 @@
resolve_response_checksum_algorithms,
)
from botocore.model import OperationModel
from tests import mock, requires_crt
from tests import get_checksum_cls, mock, requires_crt


class TestHttpChecksumHandlers(unittest.TestCase):
Expand Down Expand Up @@ -737,17 +736,17 @@ def test_crt_crc64nvme(self):
class TestCrtChecksumOverrides(unittest.TestCase):
@requires_crt()
def test_crt_crc32_available(self):
actual_cls = _CHECKSUM_CLS.get("crc32")
actual_cls = get_checksum_cls("crc32")
self.assertEqual(actual_cls, CrtCrc32Checksum)

@requires_crt()
def test_crt_crc32c_available(self):
actual_cls = _CHECKSUM_CLS.get("crc32c")
actual_cls = get_checksum_cls("crc32c")
self.assertEqual(actual_cls, CrtCrc32cChecksum)

@requires_crt()
def test_crt_crc64nvme_available(self):
actual_cls = _CHECKSUM_CLS.get("crc64nvme")
actual_cls = get_checksum_cls("crc64nvme")
self.assertEqual(actual_cls, CrtCrc64NvmeChecksum)


Expand Down

0 comments on commit ce46e4a

Please sign in to comment.