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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8472a4cdb61e9be9f91445550aabb3275fdd3535b533a4d6385253fef03a05a9
|
|
| MD5 |
b733a0c63d208b702abbe4173cc660b7
|
|
| BLAKE2b-256 |
89caadaea4587387ffbccba21d1c813ecdb09d665a642bb134f36a1158f15079
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3c30758192702fc05120b056a7814dc648b1630eadfeeb9140a820cb995f1d
|
|
| MD5 |
db8eebdbd872e6eac39558f60d24286a
|
|
| BLAKE2b-256 |
ee37e24314b18cecabdf4780a70586d8d2330e2daf8756ecb121a8c7cf5d6acd
|