Skip to content

Instantly share code, notes, and snippets.

@zscholl
Created May 13, 2020 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zscholl/adb37f40ffaf06e1fa5afe2d00208f05 to your computer and use it in GitHub Desktop.
Save zscholl/adb37f40ffaf06e1fa5afe2d00208f05 to your computer and use it in GitHub Desktop.
Example Moto unittest
import boto3
from moto import mock_s3
from mymodule import MyModel
@mock_s3
def test_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 account
conn.create_bucket(Bucket='mybucket')
model_instance = MyModel('steve', 'is awesome')
model_instance.save()
body = conn.Object('mybucket', 'steve').get()['Body'].read().decode("utf-8")
assert body == 'is awesome'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment