Skip to content

Commit

Permalink
fix boto3 socket error (#422)
Browse files Browse the repository at this point in the history
closes #416
  • Loading branch information
gabrielfalcao committed May 13, 2021
1 parent 424009e commit 85ca206
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ tornado>=6.0.4
tox>=3.14.5
twine>=1.15.0
urllib3>=1.25.8
boto3>=1.17.72
1 change: 0 additions & 1 deletion httpretty/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ def getvalue(self):

def close(self):
self.socket.close()
self.file.close()

def fileno(self):
return self._fileno
Expand Down
32 changes: 32 additions & 0 deletions tests/functional/bugfixes/test_416_boto3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import httpretty
import boto3
from botocore.exceptions import ClientError

from sure import expect


@httpretty.activate(allow_net_connect=False, verbose=True)
def test_boto3():
httpretty.register_uri(
httpretty.PUT,
"https://foo-bucket.s3.amazonaws.com/foo-object",
body="""<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>foo</RequestId>
<HostId>foo</HostId>
</Error>""",
status=403
)

session = boto3.Session(aws_access_key_id="foo", aws_secret_access_key="foo")
s3_client = session.client('s3')

put_object = expect(s3_client.put_object).when.called_with(
Bucket="foo-bucket",
Key="foo-object",
Body=b"foo"
)

put_object.should.have.raised(ClientError, 'Access Denied')

0 comments on commit 85ca206

Please sign in to comment.