"""S3 module unit tests.""" import botocore import pytest from src import s3 def test_head_object_exists(mocker): """Test head_object when object exists.""" mocker.patch.object(s3.client, 'head_object') result = s3.head_object('bucket', 'key') s3.client.head_object.assert_called_once_with( Bucket='bucket', Key='key', ExpectedBucketOwner='1234567890' ) assert result == s3.client.head_object.return_value def test_head_object_doesnt_exist(mocker): """Test head_object when object doesn't exist.""" mocker.patch.object( s3.client, 'head_object', side_effect=botocore.exceptions.ClientError( {'Error': {'Code': '404'}}, 'head_object' ) ) result = s3.head_object('bucket', 'key') s3.client.head_object.assert_called_once_with( Bucket='bucket', Key='key', ExpectedBucketOwner='1234567890' ) assert result is None def test_head_object_error(mocker): """Test head_object when error occurs.""" mocker.patch.object( s3.client, 'head_object', side_effect=botocore.exceptions.ClientError( {'Error': {'Code': '500'}}, 'head_object' ) ) with pytest.raises(botocore.exceptions.ClientError): s3.head_object('bucket', 'key')