Skip to content
Permalink
Browse files
Improve test coverage, test invalid item IDs
  • Loading branch information
brogand93 committed Feb 22, 2014
1 parent 028733f commit 8512d0ff5d5516063449e488fb44d8f62b43d024
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
@@ -50,6 +50,7 @@ def _describe_virtual_machines_request(args=None):
args = {}

args['command'] = 'listVirtualMachines'
print(args)

cloudstack_response = requester.make_request(args)

@@ -0,0 +1,8 @@
{
"listtemplatesresponse": {
"errorcode": 431,
"uuidlist": [],
"cserrorcode": 4350,
"errortext": "Please specify a valid template ID."
}
}
@@ -0,0 +1,55 @@
{
"listvolumesresponse": {
"count": 21,
"volume": [
{
"diskofferingname": "Custom",
"account": "admin",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"name": "6f78a7d4-8863-40da-96f8-0e10ad4ea94e",
"created": "2014-02-22T13:25:12+0000",
"storagetype": "shared",
"type": "DATADISK",
"tags": [],
"domain": "ROOT",
"isextractable": true,
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"destroyed": false,
"state": "Allocated",
"diskofferingdisplaytext": "Custom Disk",
"displayvolume": true,
"size": 10737418240,
"diskofferingid": "46f0a62e-ba3c-4a49-b619-877a8b2a07ed",
"id": "aa903a80-efa9-4fac-b424-544cbda9fce9",
"zonename": "Sandbox-simulator"
},
{
"domain": "ROOT",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"vmname": "43791f77-26f8-48ca-b557-3a9392f735ae",
"id": "de2d8297-eaaf-4e81-8ffe-97f37ddbbde5",
"size": 5368709120,
"diskofferingname": "Small",
"diskofferingdisplaytext": "Small Disk, 5 GB",
"storage": "PS0",
"displayvolume": false,
"destroyed": false,
"state": "Ready",
"type": "DATADISK",
"zonename": "Sandbox-simulator",
"tags": [],
"isextractable": true,
"account": "admin",
"name": "DATA-5",
"virtualmachineid": "43791f77-26f8-48ca-b557-3a9392f735ae",
"storagetype": "shared",
"hypervisor": "Simulator",
"created": "2014-02-21T17:28:41+0000",
"deviceid": 1,
"diskofferingid": "8fade6f4-13ea-490f-aff2-65c9b37b7651",
"vmstate": "Running"
}
]
}
}
@@ -8,6 +8,7 @@


class ImagesTestCase(Ec2StackAppTestCase):

def test_describe_images(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
@@ -49,6 +50,27 @@ def test_describe_specific_images(self):
self.assertOk(response)
assert 'DescribeImagesResponse' in response.data

def test_invalid_image_id(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['ImageId.1'] = 'InvalidId'
data['Signature'] = generate_signature(data, 'POST', 'localhost')

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

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

self.assertBadRequest(response)
assert 'InvalidItemId.Malformed' in response.data

def test_describe_image_attribute(self):
data = self.get_example_data()
data['Action'] = 'DescribeImageAttribute'
@@ -70,4 +92,3 @@ def test_describe_image_attribute(self):

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

@@ -71,4 +71,3 @@ def test_describe_image_attribute(self):

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

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


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

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

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

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

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

0 comments on commit 8512d0f

Please sign in to comment.