From f5db561a306f0f13f8895f378c193a62b4af480f Mon Sep 17 00:00:00 2001 From: Yashvardhan Nanavati Date: Fri, 20 Sep 2024 17:49:33 -0700 Subject: [PATCH] Fix fetching s3 bucket data --- iib/web/s3_utils.py | 2 +- tests/test_web/test_s3_utils.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/iib/web/s3_utils.py b/iib/web/s3_utils.py index c843990d8..2c4eb5484 100644 --- a/iib/web/s3_utils.py +++ b/iib/web/s3_utils.py @@ -27,7 +27,7 @@ def get_object_from_s3_bucket( try: s3_client = boto3.client('s3') response = s3_client.get_object(Bucket=bucket_name, Key=file_name) - return response['Body'].read() + return response['Body'] except Exception as error: log.exception('Unable to fetch object %s from bucket %s: %s', file_name, bucket_name, error) return None diff --git a/tests/test_web/test_s3_utils.py b/tests/test_web/test_s3_utils.py index 9d0082d36..e7f1591ef 100644 --- a/tests/test_web/test_s3_utils.py +++ b/tests/test_web/test_s3_utils.py @@ -12,12 +12,11 @@ def test_get_object_from_s3_bucket(mock_boto3): mock_client = mock.Mock() mock_boto3.client.return_value = mock_client mock_body = StreamingBody('lots of data', 0) - mock_body.read = mock.Mock(return_value=b'lots of data') mock_client.get_object.return_value = {'Body': mock_body} response = s3_utils.get_object_from_s3_bucket('prefix', 'file', 's3-bucket') - assert response == b'lots of data' + assert response == mock_body mock_boto3.client.assert_called_once_with('s3') mock_client.get_object.assert_called_once_with(Bucket='s3-bucket', Key='prefix/file')