basic ec2 and s3 working
This commit is contained in:
parent
6a060dfd7e
commit
77d6df6531
33 changed files with 561 additions and 1 deletions
BIN
tests/__init__.pyc
Normal file
BIN
tests/__init__.pyc
Normal file
Binary file not shown.
29
tests/test_ec2/test_ec2.py
Normal file
29
tests/test_ec2/test_ec2.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import boto
|
||||
from boto.ec2.instance import Reservation
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_ec2
|
||||
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_instance_launch_and_terminate():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>')
|
||||
reservation.should.be.a(Reservation)
|
||||
reservation.instances.should.have.length_of(1)
|
||||
instance = reservation.instances[0]
|
||||
|
||||
reservations = conn.get_all_instances()
|
||||
reservations.should.have.length_of(1)
|
||||
reservations[0].id.should.equal(reservation.id)
|
||||
instances = reservations[0].instances
|
||||
instances.should.have.length_of(1)
|
||||
instances[0].id.should.equal(instance.id)
|
||||
instances[0].state.should.equal('pending')
|
||||
|
||||
conn.terminate_instances(instances[0].id)
|
||||
|
||||
reservations = conn.get_all_instances()
|
||||
instance = reservations[0].instances[0]
|
||||
instance.state.should.equal('shutting-down')
|
||||
BIN
tests/test_ec2/test_ec2.pyc
Normal file
BIN
tests/test_ec2/test_ec2.pyc
Normal file
Binary file not shown.
30
tests/test_s3/test_s3.py
Normal file
30
tests/test_s3/test_s3.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import boto
|
||||
from boto.s3.key import Key
|
||||
|
||||
from moto import mock_s3
|
||||
|
||||
|
||||
class MyModel(object):
|
||||
def __init__(self, name, value):
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
def save(self):
|
||||
conn = boto.connect_s3('the_key', 'the_secret')
|
||||
bucket = conn.get_bucket('mybucket')
|
||||
k = Key(bucket)
|
||||
k.key = self.name
|
||||
k.set_contents_from_string(self.value)
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_my_model_save():
|
||||
# Create Bucket so that test can run
|
||||
conn = boto.connect_s3('the_key', 'the_secret')
|
||||
conn.create_bucket('mybucket')
|
||||
####################################
|
||||
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
|
||||
BIN
tests/test_s3/test_s3.pyc
Normal file
BIN
tests/test_s3/test_s3.pyc
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue