This commit is contained in:
Steve Pulec 2013-02-26 00:31:01 -05:00
parent bcbec29653
commit d32059f301
16 changed files with 59 additions and 58 deletions

View File

@ -20,28 +20,29 @@ class Table(object):
@property @property
def describe(self): def describe(self):
return {"Table": { return {
"CreationDateTime": unix_time(self.created_at), "Table": {
"KeySchema": { "CreationDateTime": unix_time(self.created_at),
"HashKeyElement": { "KeySchema": {
"AttributeName": self.hash_key_attr, "HashKeyElement": {
"AttributeType": self.hash_key_type "AttributeName": self.hash_key_attr,
"AttributeType": self.hash_key_type
},
"RangeKeyElement": {
"AttributeName": self.range_key_attr,
"AttributeType": self.range_key_type
}
}, },
"RangeKeyElement": { "ProvisionedThroughput": {
"AttributeName": self.range_key_attr, "ReadCapacityUnits": self.read_capacity,
"AttributeType": self.range_key_type "WriteCapacityUnits": self.write_capacity
} },
}, "TableName": self.name,
"ProvisionedThroughput": { "TableStatus": "ACTIVE",
"ReadCapacityUnits": self.read_capacity, "ItemCount": 0,
"WriteCapacityUnits": self.write_capacity "TableSizeBytes": 0,
}, }
"TableName": self.name,
"TableStatus": "ACTIVE",
"ItemCount": 0,
"TableSizeBytes": 0,
} }
}
class DynamoDBBackend(BaseBackend): class DynamoDBBackend(BaseBackend):

View File

@ -2,4 +2,4 @@ from .responses import handler
urls = { urls = {
"https://dynamodb.us-east-1.amazonaws.com/": handler, "https://dynamodb.us-east-1.amazonaws.com/": handler,
} }

View File

@ -1,5 +1,6 @@
import datetime import datetime
def unix_time(dt): def unix_time(dt):
epoch = datetime.datetime.utcfromtimestamp(0) epoch = datetime.datetime.utcfromtimestamp(0)
delta = dt - epoch delta = dt - epoch

View File

@ -1,2 +1,2 @@
from .models import ec2_backend from .models import ec2_backend
mock_ec2 = ec2_backend.decorator mock_ec2 = ec2_backend.decorator

View File

@ -132,6 +132,7 @@ class Ami(object):
self.virtualization_type = instance.virtualization_type self.virtualization_type = instance.virtualization_type
self.kernel_id = instance.kernel self.kernel_id = instance.kernel
class AmiBackend(object): class AmiBackend(object):
def __init__(self): def __init__(self):
self.amis = {} self.amis = {}
@ -143,7 +144,7 @@ class AmiBackend(object):
instance = self.get_instance(instance_id) instance = self.get_instance(instance_id)
if not instance: if not instance:
return None return None
ami = Ami(ami_id, instance, name, description) ami = Ami(ami_id, instance, name, description)
self.amis[ami_id] = ami self.amis[ami_id] = ami
return ami return ami
@ -218,7 +219,7 @@ class SecurityRule(object):
self.to_port, self.to_port,
self.ip_ranges, self.ip_ranges,
self.source_groups self.source_groups
) )
def __eq__(self, other): def __eq__(self, other):
return self.unique_representation == other.unique_representation return self.unique_representation == other.unique_representation
@ -244,7 +245,7 @@ class SecurityGroupBackend(object):
existing_group = self.get_security_group_from_name(name) existing_group = self.get_security_group_from_name(name)
if existing_group: if existing_group:
return None return None
group = SecurityGroup(group_id, name, description) group = SecurityGroup(group_id, name, description)
self.groups[group_id] = group self.groups[group_id] = group
return group return group
@ -381,4 +382,3 @@ class EC2Backend(BaseBackend, InstanceBackend, TagBackend, AmiBackend, RegionsAn
ec2_backend = EC2Backend() ec2_backend = EC2Backend()

View File

@ -32,7 +32,6 @@ from .vpn_connections import VPNConnections
from .windows import Windows from .windows import Windows
class EC2Response(object): class EC2Response(object):
sub_responses = [ sub_responses = [

View File

@ -99,4 +99,3 @@ DEREGISTER_IMAGE_RESPONSE = """<DeregisterImageResponse xmlns="http://ec2.amazon
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>{{ success }}</return> <return>{{ success }}</return>
</DeregisterImageResponse>""" </DeregisterImageResponse>"""

View File

@ -1,2 +1,2 @@
from .models import s3_backend from .models import s3_backend
mock_s3 = s3_backend.decorator mock_s3 = s3_backend.decorator

View File

@ -16,6 +16,7 @@ class FakeKey(object):
value_md5.update(self.value) value_md5.update(self.value)
return '"{0}"'.format(value_md5.hexdigest()) return '"{0}"'.format(value_md5.hexdigest())
class FakeBucket(object): class FakeBucket(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
@ -48,7 +49,6 @@ class S3Backend(BaseBackend):
return self.buckets.pop(bucket_name) return self.buckets.pop(bucket_name)
return None return None
def set_key(self, bucket_name, key_name, value): def set_key(self, bucket_name, key_name, value):
bucket = self.buckets[bucket_name] bucket = self.buckets[bucket_name]
new_key = FakeKey(name=key_name, value=value) new_key = FakeKey(name=key_name, value=value)

View File

@ -66,5 +66,4 @@ class SESBackend(BaseBackend):
def get_send_quota(self): def get_send_quota(self):
return SESQuota(self.sent_messages) return SESQuota(self.sent_messages)
ses_backend = SESBackend()
ses_backend = SESBackend()

View File

@ -15,4 +15,4 @@ def get_random_message_id():
random_hex(4), random_hex(4),
random_hex(12), random_hex(12),
random_hex(6), random_hex(6),
) )

View File

@ -23,6 +23,7 @@ class Message(object):
# SQS Message bodies are base64 encoded by default # SQS Message bodies are base64 encoded by default
return base64.b64encode(self._body) return base64.b64encode(self._body)
class Queue(object): class Queue(object):
camelcase_attributes = ['VisibilityTimeout', 'ApproximateNumberOfMessages'] camelcase_attributes = ['VisibilityTimeout', 'ApproximateNumberOfMessages']

View File

@ -263,4 +263,4 @@ DELETE_MESSAGE_BATCH_RESPONSE = """<DeleteMessageBatchResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId>d6f86b7a-74d1-4439-b43f-196a1e29cd85</RequestId> <RequestId>d6f86b7a-74d1-4439-b43f-196a1e29cd85</RequestId>
</ResponseMetadata> </ResponseMetadata>
</DeleteMessageBatchResponse>""" </DeleteMessageBatchResponse>"""

View File

@ -27,26 +27,26 @@ def test_describe_table():
) )
conn = boto.connect_dynamodb('the_key', 'the_secret') conn = boto.connect_dynamodb('the_key', 'the_secret')
expected = { expected = {
'Table': { 'Table': {
'CreationDateTime': 1326499200.0, 'CreationDateTime': 1326499200.0,
'ItemCount': 0, 'ItemCount': 0,
'KeySchema': { 'KeySchema': {
'HashKeyElement': { 'HashKeyElement': {
'AttributeName': 'forum_name', 'AttributeName': 'forum_name',
'AttributeType': 'S' 'AttributeType': 'S'
}, },
'RangeKeyElement': { 'RangeKeyElement': {
'AttributeName': 'subject', 'AttributeName': 'subject',
'AttributeType': 'S' 'AttributeType': 'S'
}
},
'ProvisionedThroughput': {
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
},
'TableName': 'messages',
'TableSizeBytes': 0,
'TableStatus': 'ACTIVE'
} }
} },
'ProvisionedThroughput': {
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
},
'TableName': 'messages',
'TableSizeBytes': 0,
'TableStatus': 'ACTIVE'
}
}
assert conn.describe_table('messages') == expected assert conn.describe_table('messages') == expected

View File

@ -5,4 +5,4 @@ from moto import mock_ec2
@mock_ec2 @mock_ec2
def test_not_implemented_method(): def test_not_implemented_method():
requests.post.when.called_with("https://ec2.us-east-1.amazonaws.com/", requests.post.when.called_with("https://ec2.us-east-1.amazonaws.com/",
data={'Action':['foobar']}).should.throw(NotImplementedError) data={'Action': ['foobar']}).should.throw(NotImplementedError)

View File

@ -10,7 +10,7 @@ def test_create_and_describe_security_group():
conn = boto.connect_ec2('the_key', 'the_secret') conn = boto.connect_ec2('the_key', 'the_secret')
security_group = conn.create_security_group('test security group', 'this is a test security group') security_group = conn.create_security_group('test security group', 'this is a test security group')
security_group.name.should.equal('test security group') expect(security_group).name.should.equal('test security group')
security_group.description.should.equal('this is a test security group') security_group.description.should.equal('this is a test security group')
# Trying to create another group with the same name should throw an error # Trying to create another group with the same name should throw an error
@ -25,7 +25,7 @@ def test_create_and_describe_security_group():
def test_deleting_security_groups(): def test_deleting_security_groups():
conn = boto.connect_ec2('the_key', 'the_secret') conn = boto.connect_ec2('the_key', 'the_secret')
security_group1 = conn.create_security_group('test1', 'test1') security_group1 = conn.create_security_group('test1', 'test1')
security_group2 = conn.create_security_group('test2', 'test2') conn.create_security_group('test2', 'test2')
conn.get_all_security_groups().should.have.length_of(2) conn.get_all_security_groups().should.have.length_of(2)
@ -62,6 +62,7 @@ def test_authorize_ip_range_and_revoke():
security_group = conn.get_all_security_groups()[0] security_group = conn.get_all_security_groups()[0]
security_group.rules.should.have.length_of(0) security_group.rules.should.have.length_of(0)
@mock_ec2 @mock_ec2
def test_authorize_other_group_and_revoke(): def test_authorize_other_group_and_revoke():
conn = boto.connect_ec2('the_key', 'the_secret') conn = boto.connect_ec2('the_key', 'the_secret')