File: test_416_boto3.py

package info (click to toggle)
python-httpretty 1.1.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: python: 4,233; makefile: 72
file content (33 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import httpretty
import boto3
from botocore.exceptions import ClientError

from sure import expect


@httpretty.activate(allow_net_connect=False, verbose=True)
def test_boto3():
    "#416 boto3 issue"
    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')