Skip to content
Permalink
Browse files
Add instance tests, fix bug encountered in instances.py
  • Loading branch information
brogand93 committed Jun 1, 2014
1 parent 4f6c650 commit 3cc8eacb9724d53963ae6c1b6c69ddd992e52a46
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
@@ -118,17 +118,17 @@ def _cloudstack_virtual_machine_to_gce(cloudstack_response, zone, projectid):
response['disks'] = []

networking = {}
if cloudstack_response['securitygroup']:
accessconfig = {}
if 'securitygroup' in cloudstack_response:
networking['network'] = cloudstack_response['securitygroup'][0]['name']
networking['networkIP'] = cloudstack_response['nic'][0]['ipaddress']
networking['name'] = cloudstack_response['nic'][0]['id']
accessconfig['natIP'] = cloudstack_response['nic'][0]['ipaddress']
networking['accessConfigs'] = []

accessconfig = {}
accessconfig['kind'] = 'compute#accessConfig'
accessconfig['type'] = 'ONE_TO_ONE_NAT'
accessconfig['name'] = 'External NAT'
accessconfig['natIP'] = cloudstack_response['nic'][0]['ipaddress']

networking['accessConfigs'] = accessconfig

@@ -282,6 +282,7 @@ def getinstance(projectid, authorization, zone, instance):
function_route = url_for(
'getinstance',
projectid=projectid,
zone=zone,
instance=instance)
return errors.resource_not_found(function_route)

@@ -28,7 +28,7 @@
"affinitygroup": [],
"account": "admin",
"hostid": "e880bd0f-1597-4cec-b108-c61dd02d78fd",
"name": "43791f77-26f8-48ca-b557-3a9392f735ae",
"name": "instancename",
"networkkbsread": 42369024,
"created": "2014-02-21T17:28:40+0000",
"hypervisor": "Simulator",
@@ -6,7 +6,7 @@
from gstack.helpers import read_file
from . import GStackAppTestCase

class ZonesTestCase(GStackAppTestCase):
class ImagesTestCase(GStackAppTestCase):

def test_list_images(self):

@@ -32,7 +32,7 @@ def test_get_image(self):

self.assert_ok(response)

def test_get_zone_not_found(self):
def test_get_image_image_not_found(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/empty_describe_images.json')
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# encoding: utf-8

import mock

from gstack.helpers import read_file
from . import GStackAppTestCase

class InstancesTestCase(GStackAppTestCase):

def test_list_instances(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/valid_describe_instances.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/exampleproject/zones/examplezone/instances', headers=headers)

self.assert_ok(response)

def test_get_instance(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/exampleproject/zones/examplezone/instances/instancename', headers=headers)

self.assert_ok(response)

def test_get_instance_instance_not_found(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/empty_describe_instances.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/exampleproject/zones/examplezone/instances/instancename', headers=headers)

self.assert_not_found(response)
assert 'The resource \'/compute/v1/projects/exampleproject/zones/examplezone/instances/instancename\' was not found' \
in response.data
@@ -32,7 +32,7 @@ def test_get_zone(self):

self.assert_ok(response)

def test_get_zone_not_found(self):
def test_get_zone_zone_not_found(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/empty_describe_zone.json')

0 comments on commit 3cc8eac

Please sign in to comment.