add other ways to call decorator

This commit is contained in:
Steve Pulec 2013-02-27 22:25:15 -05:00
commit db943bcdbb
3 changed files with 127 additions and 20 deletions

View file

@ -0,0 +1,39 @@
import boto
from boto.exception import EC2ResponseError
from sure import expect
from moto import mock_ec2
'''
Test the different ways that the decorator can be used
'''
@mock_ec2
def test_basic_decorator():
conn = boto.connect_ec2('the_key', 'the_secret')
list(conn.get_all_instances()).should.equal([])
def test_context_manager():
conn = boto.connect_ec2('the_key', 'the_secret')
conn.get_all_instances.when.called_with().should.throw(EC2ResponseError)
with mock_ec2():
conn = boto.connect_ec2('the_key', 'the_secret')
list(conn.get_all_instances()).should.equal([])
conn.get_all_instances.when.called_with().should.throw(EC2ResponseError)
def test_decorator_start_and_stop():
conn = boto.connect_ec2('the_key', 'the_secret')
conn.get_all_instances.when.called_with().should.throw(EC2ResponseError)
mock = mock_ec2()
mock.start()
conn = boto.connect_ec2('the_key', 'the_secret')
list(conn.get_all_instances()).should.equal([])
mock.stop()
expect(conn.get_all_instances.when.called_with()).should.throw(EC2ResponseError)