Skip to main content

Stub boto3 clients to avoid hitting real AWS endpoints in tests

Project description

Stuboto

Stub boto3 clients to avoid hitting real AWS endpoints in tests.

Usage

You can use Stuboto instances as if they were botocore.stub.Stubber:

import boto3
from stuboto import Stuboto

def test_create_bucket():
    s3 = boto3.client("s3")
    stubber = Stuboto(s3)
    stubber.activate()

    response = {"Location": "my-bucket"}
    expected_params = {"Bucket": "my-bucket", "ACL": "private"}

    stubber.add_response("create_bucket", response, expected_params)
    service_response = s3.create_bucket(Bucket="my-bucket", ACL="private")
    assert service_response == response

Stuboto instances are decorated with all the same methods as the original boto3 client so you can also stub responses with the arguably more readable:

import boto3
from stuboto import Stuboto

def test_create_bucket():
    s3 = boto3.client("s3")
    stubber = Stuboto(s3)
    stubber.activate()

    response = stubber.create_bucket(Bucket="my-bucket", ACL="private").add_response(
        Location="my-bucket"
    )
    service_response = s3.create_bucket(Bucket="my-bucket", ACL="private")
    assert service_response == response

botocore.stub.Stubber documentation suggests:

It should be noted, however, that while missing attributes are often considered correct, your code may not function properly if you leave them out. Therefore you should always fill in every value you see in a typical response for your particular request.

But I won't tell anybody if you leave some values out in favor of writing more readable tests.

Installation

pip install stuboto

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stuboto-0.3.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stuboto-0.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file stuboto-0.3.tar.gz.

File metadata

  • Download URL: stuboto-0.3.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for stuboto-0.3.tar.gz
Algorithm Hash digest
SHA256 8472a4cdb61e9be9f91445550aabb3275fdd3535b533a4d6385253fef03a05a9
MD5 b733a0c63d208b702abbe4173cc660b7
BLAKE2b-256 89caadaea4587387ffbccba21d1c813ecdb09d665a642bb134f36a1158f15079

See more details on using hashes here.

File details

Details for the file stuboto-0.3-py3-none-any.whl.

File metadata

  • Download URL: stuboto-0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for stuboto-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aa3c30758192702fc05120b056a7814dc648b1630eadfeeb9140a820cb995f1d
MD5 db8eebdbd872e6eac39558f60d24286a
BLAKE2b-256 ee37e24314b18cecabdf4780a70586d8d2330e2daf8756ecb121a8c7cf5d6acd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page