Skip to content
Permalink
Browse files
Extend tests to cover images / instances controllers
  • Loading branch information
brogand93 committed Feb 22, 2014
1 parent 9f5e97a commit 028733f526b8c24c9786b6101ae89a46030a74b0
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 13 deletions.
@@ -58,14 +58,6 @@ def _describe_specific_images():
return images


def invalid_image_id():
raise Ec2stackError(
'400',
'InvalidImageId.Malformed',
'The specified Image ID is not valid'
)


def _describe_templates_request(args=None):
if not args:
args = {}
@@ -85,7 +77,7 @@ def _describe_templates_request(args=None):
def _create_describe_image_attribute_response(item_attribute):
response = {
'template_name_or_list': 'image_attribute.xml',
'response_type': 'DescribeImageAttributes',
'response_type': 'DescribeImageAttributeResponse',
'attribute': get('Attribute', request.form),
'value': item_attribute.values()[0],
'id': get('ImageId', request.form)
@@ -84,7 +84,7 @@ def _describe_specific_instances():
def _create_describe_instance_attribute_response(item_attribute):
response = {
'template_name_or_list': 'instance_attribute.xml',
'response_type': 'DescribeInstanceAttributes',
'response_type': 'DescribeInstanceAttributeResponse',
'attribute': get('Attribute', request.form),
'value': item_attribute.values()[0],
'id': get('InstanceId', request.form)
@@ -0,0 +1,35 @@
{
"listtemplatesresponse": {
"count": 1,
"template": [
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"ostypename": "CentOS 5.3 (32-bit)",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"displaytext": "CentOS 5.3(64-bit) no GUI (Simulator)",
"ostypeid": "2e678976-95e4-11e3-b2e4-d19c9d3e5e1d",
"passwordenabled": false,
"id": "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d",
"size": 2147483648,
"isready": true,
"format": "VHD",
"templatetype": "BUILTIN",
"crosszones": true,
"zonename": "Sandbox-simulator",
"status": "Download Complete",
"isdynamicallyscalable": false,
"tags": [],
"isfeatured": true,
"sshkeyenabled": false,
"isextractable": false,
"account": "system",
"name": "CentOS 5.3(64-bit) no GUI (Simulator)",
"created": "2014-02-15T02:50:13+0000",
"hypervisor": "Simulator",
"ispublic": true,
"checksum": ""
}
]
}
}
@@ -0,0 +1,35 @@
{
"listtemplatesresponse": {
"count": 1,
"template": [
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"ostypename": "CentOS 5.3 (32-bit)",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"displaytext": "CentOS 5.3(64-bit) no GUI (Simulator)",
"ostypeid": "2e678976-95e4-11e3-b2e4-d19c9d3e5e1d",
"passwordenabled": false,
"id": "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d",
"size": 2147483648,
"isready": true,
"format": "VHD",
"templatetype": "BUILTIN",
"crosszones": true,
"zonename": "Sandbox-simulator",
"status": "Download Complete",
"isdynamicallyscalable": false,
"tags": [],
"isfeatured": true,
"sshkeyenabled": false,
"isextractable": false,
"account": "system",
"name": "CentOS 5.3(64-bit) no GUI (Simulator)",
"created": "2014-02-15T02:50:13+0000",
"hypervisor": "Simulator",
"ispublic": true,
"checksum": ""
}
]
}
}
@@ -0,0 +1,42 @@
{
"listvirtualmachinesresponse": {
"count": 2,
"virtualmachine": [
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"haenable": false,
"templatename": "CentOS 5.3(64-bit) no GUI (Simulator)",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"cpunumber": 1,
"passwordenabled": false,
"instancename": "i-2-5-QA",
"id": "43791f77-26f8-48ca-b557-3a9392f735ae",
"networkkbswrite": 21184512,
"hostname": "SimulatedAgent.74a0cc00-96c0-4b60-a170-7c749c6e2f10",
"displayvm": true,
"state": "Running",
"guestosid": "2e678976-95e4-11e3-b2e4-d19c9d3e5e1d",
"cpuused": "10%",
"memory": 512,
"serviceofferingid": "739292ce-3e12-4643-8ca1-abfdc2b2eb76",
"zonename": "Sandbox-simulator",
"isdynamicallyscalable": false,
"tags": [],
"cpuspeed": 500,
"templateid": "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d",
"affinitygroup": [],
"account": "admin",
"hostid": "e880bd0f-1597-4cec-b108-c61dd02d78fd",
"name": "43791f77-26f8-48ca-b557-3a9392f735ae",
"networkkbsread": 42369024,
"created": "2014-02-21T17:28:40+0000",
"hypervisor": "Simulator",
"rootdevicetype": "ROOT",
"rootdeviceid": 0,
"serviceofferingname": "Small Instance",
"templatedisplaytext": "CentOS 5.3(64-bit) no GUI (Simulator)"
}
]
}
}
@@ -0,0 +1,77 @@
{
"listvirtualmachinesresponse": {
"count": 2,
"virtualmachine": [
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"haenable": false,
"templatename": "CentOS 5.3(64-bit) no GUI (Simulator)",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"cpunumber": 1,
"passwordenabled": false,
"instancename": "i-2-5-QA",
"id": "43791f77-26f8-48ca-b557-3a9392f735ae",
"networkkbswrite": 21184512,
"hostname": "SimulatedAgent.74a0cc00-96c0-4b60-a170-7c749c6e2f10",
"displayvm": true,
"state": "Running",
"guestosid": "2e678976-95e4-11e3-b2e4-d19c9d3e5e1d",
"cpuused": "10%",
"memory": 512,
"serviceofferingid": "739292ce-3e12-4643-8ca1-abfdc2b2eb76",
"zonename": "Sandbox-simulator",
"isdynamicallyscalable": false,
"tags": [],
"cpuspeed": 500,
"templateid": "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d",
"affinitygroup": [],
"account": "admin",
"hostid": "e880bd0f-1597-4cec-b108-c61dd02d78fd",
"name": "43791f77-26f8-48ca-b557-3a9392f735ae",
"networkkbsread": 42369024,
"created": "2014-02-21T17:28:40+0000",
"hypervisor": "Simulator",
"rootdevicetype": "ROOT",
"rootdeviceid": 0,
"serviceofferingname": "Small Instance",
"templatedisplaytext": "CentOS 5.3(64-bit) no GUI (Simulator)"
},
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"haenable": false,
"templatename": "CentOS 5.3(64-bit) no GUI (Simulator)",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"cpunumber": 1,
"passwordenabled": false,
"instancename": "i-2-3-QA",
"id": "aa10a43e-56db-4a34-88bd-1c2a51c0bc04",
"networkkbswrite": 119291904,
"hostname": "SimulatedAgent.74a0cc00-96c0-4b60-a170-7c749c6e2f10",
"displayvm": true,
"state": "Running",
"guestosid": "2e678976-95e4-11e3-b2e4-d19c9d3e5e1d",
"cpuused": "10%",
"memory": 512,
"serviceofferingid": "739292ce-3e12-4643-8ca1-abfdc2b2eb76",
"zonename": "Sandbox-simulator",
"isdynamicallyscalable": false,
"tags": [],
"cpuspeed": 500,
"templateid": "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d",
"affinitygroup": [],
"account": "admin",
"hostid": "e880bd0f-1597-4cec-b108-c61dd02d78fd",
"name": "aa10a43e-56db-4a34-88bd-1c2a51c0bc04",
"networkkbsread": 238583808,
"created": "2014-02-15T20:04:05+0000",
"hypervisor": "Simulator",
"rootdevicetype": "ROOT",
"rootdeviceid": 0,
"serviceofferingname": "Small Instance",
"templatedisplaytext": "CentOS 5.3(64-bit) no GUI (Simulator)"
}
]
}
}
@@ -7,4 +7,67 @@
from . import Ec2StackAppTestCase


#class ImagesTestCase(Ec2StackAppTestCase):
class ImagesTestCase(Ec2StackAppTestCase):
def test_describe_images(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_images.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeImagesResponse' in response.data

def test_describe_specific_images(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['ImageId.1'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_images.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeImagesResponse' in response.data

def test_describe_image_attribute(self):
data = self.get_example_data()
data['Action'] = 'DescribeImageAttribute'
data['ImageId.1'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Attribute'] = 'isready'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_image_attribute.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeImageAttributeResponse' in response.data

@@ -7,4 +7,68 @@
from . import Ec2StackAppTestCase


#class InstancesTestCase(Ec2StackAppTestCase):
class InstancesTestCase(Ec2StackAppTestCase):

def test_describe_instances(self):
data = self.get_example_data()
data['Action'] = 'DescribeInstances'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_instances.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeInstancesResponse' in response.data

def test_describe_specific_instances(self):
data = self.get_example_data()
data['Action'] = 'DescribeInstances'
data['InstanceId.1'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_instances.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeInstancesResponse' in response.data

def test_describe_image_attribute(self):
data = self.get_example_data()
data['Action'] = 'DescribeInstanceAttribute'
data['ImageId.1'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Attribute'] = 'name'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

get = mock.Mock()
text = get.return_value.text = read_file(
'tests/data/valid_describe_instance_attribute.json'
)
status_code = get.return_value.status_code = 200

with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)

self.assertOk(response)
assert 'DescribeInstanceAttributeResponse' in response.data

@@ -7,4 +7,4 @@
from . import Ec2StackAppTestCase


#class VolumeTestCase(Ec2StackAppTestCase):
#class VolumeTestCase(Ec2StackAppTestCase):

0 comments on commit 028733f

Please sign in to comment.