Skip to content

Commit

Permalink
Fix fetching s3 bucket data
Browse files Browse the repository at this point in the history
  • Loading branch information
yashvardhannanavati authored and lipoja committed Sep 23, 2024
1 parent f98be87 commit 2c11aaf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iib/web/s3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/test_web/test_s3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 2c11aaf

Please sign in to comment.