Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetching s3 bucket data #727

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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