You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Take a minute to think how you would have tested that in the past.
Now see how you could test it with Moto:
importboto3frommotoimportmock_awsfrommymoduleimportMyModel@mock_awsdeftest_my_model_save():
conn=boto3.resource("s3", region_name="us-east-1")
# We need to create the bucket since this is all in Moto's 'virtual' AWS accountconn.create_bucket(Bucket="mybucket")
model_instance=MyModel("steve", "is awesome")
model_instance.save()
body=conn.Object("mybucket", "steve").get()["Body"].read().decode("utf-8")
assertbody=="is awesome"
With the decorator wrapping the test, all the calls to s3 are automatically mocked out. The mock keeps track of the state of the buckets and keys.
For a full list of which services and features are covered, please see our implementation coverage.
Support this project and its continued development, by sponsoring us!
Click the Sponsor-button at the top of the page for more information.
Our finances are managed by OpenCollective, which means you have full visibility into all our contributions and expenses:
https://opencollective.com/moto
Security contact information
To report a security vulnerability, please use the
Tidelift security contact.
Tidelift will coordinate the fix and disclosure.
About
A library that allows you to easily mock out tests based on AWS infrastructure.