Skip to content
Permalink
Browse files
Add list by name tests
  • Loading branch information
brogand93 committed Jun 2, 2014
1 parent 4652b4c commit 2146b75d0449af43ca79d16fb5dd58f6d543bd42
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 13 deletions.
@@ -58,7 +58,7 @@ def _cloudstack_securitygroup_to_gce(response_item):
})


@app.route('/compute/v1/projects/<projectid>/global/firewalls', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/firewalls', methods=['GET'])
@authentication.required
def listsecuritygroups(projectid, authorization):
command = 'listSecurityGroups'
@@ -152,12 +152,10 @@ def _get_virtual_machine_by_name(authorization, instance):
'keyword': instance
}
)
print virtual_machine_list

if virtual_machine_list['listvirtualmachinesresponse']:
response = helper.filter_by_name(
data=virtual_machine_list[
'listvirtualmachinesresponse']['virtualmachine'],
data=virtual_machine_list['listvirtualmachinesresponse']['virtualmachine'],
name=instance
)
return response
@@ -338,7 +336,7 @@ def deleteinstance(projectid, authorization, zone, instance):

populated_response = operations.create_response(
projectid=projectid,
operationid=deletion_result['destroyvirtualmachineresponse']['jobid'],
operationid=deletion_result['queryasyncjobresultresponse']['jobid'],
authorization=authorization
)

@@ -51,12 +51,10 @@ def _delete_instance_response(async_result, projectid):
}

if async_result['jobstatus'] is 0:
# handle pending case
populated_response['targetLink'] = ''
populated_response['status'] = 'PENDING'
populated_response['progress'] = 0
elif async_result['jobstatus'] is 1:
# handle successful case
populated_response['status'] = 'DONE'
populated_response['zone'] = urllib.unquote_plus(
helper.get_root_url() +
@@ -71,9 +69,7 @@ def _delete_instance_response(async_result, projectid):
'getinstance',
projectid=projectid,
zone=async_result['jobresult']['virtualmachine']['zonename'],
instance=async_result['jobresult']['virtualmachine']['displayname']))

# need to add a case here for error handling, its job status 2
instance=async_result['jobresult']['virtualmachine']['name']))

return populated_response

@@ -156,7 +156,7 @@ def _cloudstack_project_to_gce(cloudstack_response, metadata=None):
return response


@app.route('//compute/v1/projects/<projectid>', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>', methods=['GET'])
@authentication.required
def getproject(authorization, projectid):
project = _get_account_by_name(authorization, projectid)
@@ -178,7 +178,7 @@ def getproject(authorization, projectid):
return res


@app.route('//compute/v1/projects/<projectid>/setCommonInstanceMetadata', methods=['POST'])
@app.route('/compute/v1/projects/<projectid>/setCommonInstanceMetadata', methods=['POST'])
@authentication.required
def setglobalmetadata(projectid, authorization):
data = json.loads(request.data)
@@ -0,0 +1,38 @@
{
"queryasyncjobresultresponse": {
"jobprocstatus": 0,
"created": "2014-02-25T19:46:35+0000",
"cmd": "org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd",
"userid": "2edb33ec-95e4-11e3-b2e4-d19c9d3e5e1d",
"jobstatus": 1,
"jobid": "1f32404b-d067-43e8-8835-4cc1c55d737a",
"jobresultcode": 0,
"jobresulttype": "object",
"jobresult": {
"volume": {
"size": 10737418240,
"diskofferingname": "Custom",
"account": "admin",
"domainid": "2edae3e4-95e4-11e3-b2e4-d19c9d3e5e1d",
"name": "f0e2a699-1196-49bd-90cd-af809f4c32ea",
"created": "2014-02-25T19:46:34+0000",
"storagetype": "shared",
"type": "DATADISK",
"tags": [],
"domain": "ROOT",
"jobstatus": 0,
"jobid": "1f32404b-d067-43e8-8835-4cc1c55d737a",
"destroyed": false,
"state": "Allocated",
"diskofferingdisplaytext": "Custom Disk",
"isextractable": true,
"displayvolume": true,
"zoneid": "1e47a2fc-61c7-401c-b90e-416b472ada64",
"diskofferingid": "46f0a62e-ba3c-4a49-b619-877a8b2a07ed",
"id": "8552cdce-879a-42f3-bdb5-2e7f55a38996",
"zonename": "Sandbox-simulator"
}
},
"accountid": "2edb0c28-95e4-11e3-b2e4-d19c9d3e5e1d"
}
}
File renamed without changes.
@@ -21,6 +21,21 @@ def test_list_disks(self):

self.assert_ok(response)

def test_list_disks_with_name_filter(self):

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

with mock.patch('requests.get', get):

headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
response = self.get(
'/compute/v1/projects/projectid/zones/zonename/disks?filter=name+eq+volumename',
headers=headers)

self.assert_ok(response)

def test_aggregated_list_disks(self):

get = mock.Mock()
@@ -88,4 +103,3 @@ def test_get_disk_disk_not_found(self):
assert 'The resource \'/compute/v1/projects/exampleproject/zones/examplezone/disks/volumename\' was not found' \
in response.data


@@ -40,6 +40,20 @@ def test_aggregated_list_instances(self):

self.assert_ok(response)

def test_list_instances_with_name_filter(self):

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

with mock.patch('requests.get', get):
headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
response = self.get(
'/compute/v1/projects/projectid/zones/zonename/instances?filter=name+eq+instancename',
headers=headers)

self.assert_ok(response)

def test_aggregated_list_instances_with_name_filter(self):

get = mock.Mock()
@@ -87,4 +101,19 @@ def test_get_instance_instance_not_found(self):
assert 'The resource \'/compute/v1/projects/exampleproject/zones/examplezone/instances/instancename\' was not found' \
in response.data

def test_delete_instance(self):

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

get_instance_id = mock.Mock()
get_instance_id.return_value = {'id':'virtualmachineid'}

with mock.patch('requests.get', get):
with mock.patch('gstack.controllers.instances._get_virtual_machine_by_name',get_instance_id):
headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
response = self.delete('/compute/v1/projects/exampleproject/zones/examplezone/instances/instancename', headers=headers)

self.assert_ok(response)

@@ -29,6 +29,9 @@ def post(self, *args, **kwargs):
def get(self, *args, **kwargs):
return self._request(self.client.get, *args, **kwargs)

def delete(self, *args, **kwargs):
return self._request(self.client.delete, *args, **kwargs)

def assert_status_code(self, response, status_code):
self.assertEquals(status_code, response.status_code)
return response

0 comments on commit 2146b75

Please sign in to comment.