import boto from boto.s3.key import Key from moto import mock_s3 class MyModel(object): def __init__(self, name, value): self.name = name self.value = value def save(self): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.get_bucket('mybucket') k = Key(bucket) k.key = self.name k.set_contents_from_string(self.value) @mock_s3 def test_my_model_save(): # Create Bucket so that test can run conn = boto.connect_s3('the_key', 'the_secret') conn.create_bucket('mybucket') #################################### model_instance = MyModel('steve', 'is awesome') model_instance.save() assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'