add other ways to call decorator
This commit is contained in:
parent
4fca60ba98
commit
db943bcdbb
3 changed files with 127 additions and 20 deletions
47
README.md
47
README.md
|
|
@ -55,4 +55,49 @@ With the decorator wrapping the test, all the calls to s3 are automatically mock
|
|||
```console
|
||||
pip install moto
|
||||
```
|
||||
-->
|
||||
-->
|
||||
|
||||
## Usage
|
||||
|
||||
All of the services can be used as a decorator, context manager, or in a raw form.
|
||||
|
||||
### Decorator
|
||||
|
||||
```python
|
||||
@mock_s3
|
||||
def test_my_model_save():
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
conn = boto.connect_s3()
|
||||
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
|
||||
```
|
||||
|
||||
### Context Manager
|
||||
|
||||
```python
|
||||
def test_my_model_save():
|
||||
with mock_s3():
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
conn = boto.connect_s3()
|
||||
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
|
||||
```
|
||||
|
||||
|
||||
### Raw use
|
||||
|
||||
```python
|
||||
def test_my_model_save():
|
||||
mock = mock_s3()
|
||||
mock.start()
|
||||
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
conn = boto.connect_s3()
|
||||
assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
|
||||
|
||||
mock.stop()
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue