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
def describe(self):
return {"Table": {
"CreationDateTime": unix_time(self.created_at),
"KeySchema": {
"HashKeyElement": {
"AttributeName": self.hash_key_attr,
"AttributeType": self.hash_key_type
return {
"Table": {
"CreationDateTime": unix_time(self.created_at),
"KeySchema": {
"HashKeyElement": {
"AttributeName": self.hash_key_attr,
"AttributeType": self.hash_key_type
},
"RangeKeyElement": {
"AttributeName": self.range_key_attr,
"AttributeType": self.range_key_type
}
},
"RangeKeyElement": {
"AttributeName": self.range_key_attr,
"AttributeType": self.range_key_type
}
},
"ProvisionedThroughput": {
"ReadCapacityUnits": self.read_capacity,
"WriteCapacityUnits": self.write_capacity
},
"TableName": self.name,
"TableStatus": "ACTIVE",
"ItemCount": 0,
"TableSizeBytes": 0,
"ProvisionedThroughput": {
"ReadCapacityUnits": self.read_capacity,
"WriteCapacityUnits": self.write_capacity
},
"TableName": self.name,
"TableStatus": "ACTIVE",
"ItemCount": 0,
"TableSizeBytes": 0,
}
}
}
class DynamoDBBackend(BaseBackend):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,5 +66,4 @@ class SESBackend(BaseBackend):
def get_send_quota(self):
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(12),
random_hex(6),
)
)

View File

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

View File

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

View File

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

View File

@ -5,4 +5,4 @@ from moto import mock_ec2
@mock_ec2
def test_not_implemented_method():
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')
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')
# 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():
conn = boto.connect_ec2('the_key', 'the_secret')
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)
@ -62,6 +62,7 @@ def test_authorize_ip_range_and_revoke():
security_group = conn.get_all_security_groups()[0]
security_group.rules.should.have.length_of(0)
@mock_ec2
def test_authorize_other_group_and_revoke():
conn = boto.connect_ec2('the_key', 'the_secret')