Created
July 8, 2014 02:52
-
-
Save tristanwietsma/86081088a28ee379168e to your computer and use it in GitHub Desktop.
Mocking Boto with Moto
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 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' |
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 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