Skip to content

Commit 0754e27

Browse files
committed
Bring test coverage back up to 97%
1 parent 2f57c3f commit 0754e27

11 files changed

+307
-14
lines changed

ec2stack/providers/cloudstack/volumes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ def _create_volume_response(response):
122122
@return: Response.
123123
"""
124124
if 'errortext' in response:
125-
if 'Invalid parameter snapshotid' in response['errortext']:
126-
errors.invalid_snapshot_id()
127-
elif 'unable to find a snapshot with id' in response['errortext']:
125+
if 'unable to find a snapshot with id' in response['errortext']:
128126
errors.invalid_snapshot_id()
129127
else:
130128
errors.invalid_request(response['errortext'])
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"queryasyncjobresultresponse": {
3+
"jobprocstatus": 0,
4+
"created": "2014-03-03T14:58:12+0000",
5+
"cmd": "org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd",
6+
"userid": "a5fa60a6-a2d5-11e3-8f5e-e2e3ca4a127e",
7+
"jobstatus": 2,
8+
"jobid": "706c88e5-72a2-415d-95bc-3edc05c45420",
9+
"jobresultcode": 530,
10+
"jobresulttype": "object",
11+
"jobresult": {
12+
"errorcode": 530,
13+
"errortext": "Invalid parameter virtualmachineid."
14+
},
15+
"accountid": "a5fa2942-a2d5-11e3-8f5e-e2e3ca4a127e"
16+
}
17+
}
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"queryasyncjobresultresponse": {
3+
"jobprocstatus": 0,
4+
"created": "2014-03-03T14:58:12+0000",
5+
"cmd": "org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd",
6+
"userid": "a5fa60a6-a2d5-11e3-8f5e-e2e3ca4a127e",
7+
"jobstatus": 2,
8+
"jobid": "706c88e5-72a2-415d-95bc-3edc05c45420",
9+
"jobresultcode": 530,
10+
"jobresulttype": "object",
11+
"jobresult": {
12+
"errorcode": 530,
13+
"errortext": "Invalid parameter id."
14+
},
15+
"accountid": "a5fa2942-a2d5-11e3-8f5e-e2e3ca4a127e"
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"queryasyncjobresultresponse": {
3+
"jobprocstatus": 0,
4+
"created": "2014-03-03T14:51:54+0000",
5+
"cmd": "org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd",
6+
"userid": "a5fa60a6-a2d5-11e3-8f5e-e2e3ca4a127e",
7+
"jobstatus": 2,
8+
"jobid": "5c034fe1-696e-46ae-9105-50a768391835",
9+
"jobresultcode": 530,
10+
"jobresulttype": "object",
11+
"jobresult": {
12+
"errorcode": 530,
13+
"errortext": "Invalid parameter virtualmachineid."
14+
},
15+
"accountid": "a5fa2942-a2d5-11e3-8f5e-e2e3ca4a127e"
16+
}
17+
}
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"queryasyncjobresultresponse": {
3+
"jobprocstatus": 0,
4+
"created": "2014-03-03T14:51:54+0000",
5+
"cmd": "org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd",
6+
"userid": "a5fa60a6-a2d5-11e3-8f5e-e2e3ca4a127e",
7+
"jobstatus": 2,
8+
"jobid": "5c034fe1-696e-46ae-9105-50a768391835",
9+
"jobresultcode": 530,
10+
"jobresulttype": "object",
11+
"jobresult": {
12+
"errorcode": 530,
13+
"errortext": "Invalid parameter id."
14+
},
15+
"accountid": "a5fa2942-a2d5-11e3-8f5e-e2e3ca4a127e"
16+
}
17+
}

tests/data/service_offering_search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"issystem": false,
1313
"id": "739292ce-3e12-4643-8ca1-abfdc2b2eb76",
1414
"defaultuse": false
15-
}
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"serviceoffering": [
3+
{
4+
"name": "Small Instance",
5+
"created": "2014-02-15T02:01:42+0000",
6+
"storagetype": "shared",
7+
"limitcpuuse": false,
8+
"memory": 512,
9+
"offerha": false,
10+
"isvolatile": false,
11+
"cpunumber": 1,
12+
"cpuspeed": 500,
13+
"displaytext": "Small Instance",
14+
"issystem": false,
15+
"id": "739292ce-3e12-4643-8ca1-abfdc2b2eb76",
16+
"defaultuse": false
17+
},
18+
{
19+
"name": "Medium Instance",
20+
"created": "2014-07-15T02:01:42+0000",
21+
"storagetype": "shared",
22+
"limitcpuuse": false,
23+
"memory": 2014,
24+
"offerha": false,
25+
"isvolatile": false,
26+
"cpunumber": 2,
27+
"cpuspeed": 500,
28+
"displaytext": "Medium Instance",
29+
"issystem": false,
30+
"id": "879654ce-4f12-4643-8ca1-789542eb76",
31+
"defaultuse": false
32+
}
33+
]
34+
}

tests/service_offering_tests.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
4+
import json
5+
6+
import mock
7+
8+
from ec2stack.helpers import read_file, generate_signature
9+
from . import Ec2StackAppTestCase
10+
11+
12+
class ServiceOfferingsTestCase(Ec2StackAppTestCase):
13+
14+
def test_get_service_offering(self):
15+
data = self.get_example_data()
16+
data['Action'] = 'RunInstances'
17+
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
18+
data['InstanceType'] = 'Small Instance'
19+
data['MinCount'] = '0'
20+
data['MaxCount'] = '0'
21+
data['SecurityGroupId.1'] = 'example-security-group-id'
22+
data['SecurityGroup.1'] = 'example-security-group-name'
23+
data['KeyName'] = 'example-ssh-key-name'
24+
data['UserData'] = 'example-user-data'
25+
data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
26+
27+
get = mock.Mock()
28+
get.return_value.text = read_file(
29+
'tests/data/valid_run_instance.json'
30+
)
31+
get.return_value.status_code = 200
32+
33+
get_service_offering = mock.Mock()
34+
get_service_offering.return_value = json.loads(read_file(
35+
'tests/data/service_offerings_search.json'
36+
))
37+
38+
get_zone = mock.Mock()
39+
get_zone.return_value = json.loads(read_file(
40+
'tests/data/zones_search.json'
41+
))
42+
43+
with mock.patch('requests.get', get):
44+
with mock.patch(
45+
'ec2stack.providers.cloudstack.describe_items_request',
46+
get_service_offering
47+
):
48+
with mock.patch(
49+
'ec2stack.providers.cloudstack.zones.get_zone',
50+
get_zone
51+
):
52+
response = self.post(
53+
'/',
54+
data=data
55+
)
56+
57+
self.assert_ok(response)
58+
assert 'RunInstancesResponse' in response.data
59+
60+
def test_get_service_offering_invalid_name(self):
61+
data = self.get_example_data()
62+
data['Action'] = 'RunInstances'
63+
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
64+
data['InstanceType'] = 'invalid-instance-type'
65+
data['MinCount'] = '0'
66+
data['MaxCount'] = '0'
67+
data['SecurityGroupId.1'] = 'example-security-group-id'
68+
data['SecurityGroup.1'] = 'example-security-group-name'
69+
data['KeyName'] = 'example-ssh-key-name'
70+
data['UserData'] = 'example-user-data'
71+
data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
72+
73+
get = mock.Mock()
74+
get.return_value.text = read_file(
75+
'tests/data/valid_run_instance.json'
76+
)
77+
get.return_value.status_code = 200
78+
79+
get_service_offering = mock.Mock()
80+
get_service_offering.return_value = json.loads(read_file(
81+
'tests/data/service_offerings_search.json'
82+
))
83+
84+
get_zone = mock.Mock()
85+
get_zone.return_value = json.loads(read_file(
86+
'tests/data/zones_search.json'
87+
))
88+
89+
with mock.patch('requests.get', get):
90+
with mock.patch(
91+
'ec2stack.providers.cloudstack.describe_items_request',
92+
get_service_offering
93+
):
94+
with mock.patch(
95+
'ec2stack.providers.cloudstack.zones.get_zone',
96+
get_zone
97+
):
98+
response = self.post(
99+
'/',
100+
data=data
101+
)
102+
103+
self.assert_bad_request(response)
104+
assert 'InvalidServiceOffering.NotFound' in response.data

0 commit comments

Comments
 (0)