Created
May 13, 2020 16:55
-
-
Save zscholl/adb37f40ffaf06e1fa5afe2d00208f05 to your computer and use it in GitHub Desktop.
Example Moto unittest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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