Fixed examples in README file #141

This commit is contained in:
Federico Reiven 2014-06-20 18:47:16 -03:00
parent aec7d8e998
commit 6ca95a080d

View File

@ -44,7 +44,7 @@ def test_my_model_save():
model_instance = MyModel('steve', 'is awesome') model_instance = MyModel('steve', 'is awesome')
model_instance.save() model_instance.save()
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome' assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
``` ```
With the decorator wrapping the test, all the calls to s3 are automatically mocked out. The mock keeps the state of the buckets and keys. With the decorator wrapping the test, all the calls to s3 are automatically mocked out. The mock keeps the state of the buckets and keys.
@ -119,11 +119,13 @@ All of the services can be used as a decorator, context manager, or in a raw for
```python ```python
@mock_s3 @mock_s3
def test_my_model_save(): def test_my_model_save():
conn = boto.connect_s3()
conn.create_bucket('mybucket')
model_instance = MyModel('steve', 'is awesome') model_instance = MyModel('steve', 'is awesome')
model_instance.save() model_instance.save()
conn = boto.connect_s3() assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
``` ```
### Context Manager ### Context Manager
@ -131,11 +133,13 @@ def test_my_model_save():
```python ```python
def test_my_model_save(): def test_my_model_save():
with mock_s3(): with mock_s3():
conn = boto.connect_s3()
conn.create_bucket('mybucket')
model_instance = MyModel('steve', 'is awesome') model_instance = MyModel('steve', 'is awesome')
model_instance.save() model_instance.save()
conn = boto.connect_s3() assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
``` ```
@ -146,11 +150,13 @@ def test_my_model_save():
mock = mock_s3() mock = mock_s3()
mock.start() mock.start()
conn = boto.connect_s3()
conn.create_bucket('mybucket')
model_instance = MyModel('steve', 'is awesome') model_instance = MyModel('steve', 'is awesome')
model_instance.save() model_instance.save()
conn = boto.connect_s3() assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
mock.stop() mock.stop()
``` ```