Skip to content

Instantly share code, notes, and snippets.

@tristanwietsma
Created July 8, 2014 02:52
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 tristanwietsma/86081088a28ee379168e to your computer and use it in GitHub Desktop.
Save tristanwietsma/86081088a28ee379168e to your computer and use it in GitHub Desktop.
Mocking Boto with Moto
import boto
from moto import mock_s3
from model import MyModel
@mock_s3
def test_save_study():
conn = boto.connect_s3()
conn.create_bucket('mybucket')
m = MyModel('x/z.json', 'y')
m.save()
assert conn.get_bucket('mybucket').get_key(
'x/z.json').get_contents_as_string() == 'y'
import boto
from boto.s3.key import Key
class MyModel(object):
def __init__(self, name, value):
self.name = name
self.value = value
def save(self):
conn = boto.connect_s3()
bucket = conn.get_bucket('mybucket')
k = Key(bucket)
k.key = self.name
k.set_contents_from_string(self.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment