Skip to content
Permalink
Browse files
Add regions tests
  • Loading branch information
brogand93 committed Jun 3, 2014
1 parent 80cb827 commit 55f75c155b3db1170120c8ade40bc808d60f8523
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
@@ -76,10 +76,12 @@ def getregion(projectid, authorization, region):
args={'name': region}
)

if cloudstack_response['listregionsresponse']:
cloudstack_response = _cloudstack_region_to_gce(
cloudstack_response['listregionsresponse']['region'][0])
return helper.create_response(data=cloudstack_response)

function_route = url_for('getimage', projectid=projectid, image=region)
return errors.resource_not_found(function_route)
if region == cloudstack_response['listregionsresponse']['region'][0]['name']:
return helper.create_response(
data=_cloudstack_region_to_gce(
cloudstack_response['listregionsresponse']['region'][0]
)
)
else:
function_route = url_for('getregion', projectid=projectid, region=region)
return errors.resource_not_found(function_route)
@@ -7,7 +7,7 @@
"gslbserviceenabled": true,
"endpoint": "http://localhost:8080/client/",
"id": 1,
"name": "Local"
"name": "regionname"
}
]
}
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# encoding: utf-8

import mock

from gstack.helpers import read_file
from . import GStackAppTestCase

class RegionsTestCase(GStackAppTestCase):

def test_list_regions(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/valid_describe_regions.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/regions', headers=headers)

self.assert_ok(response)


def test_get_region(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/valid_describe_regions.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/regions/regionname', headers=headers)

self.assert_ok(response)

def test_get_region_region_not_found(self):

get = mock.Mock()
get.return_value.text = read_file('tests/data/valid_describe_regions.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/regions/invalidregionname', headers=headers)

self.assert_not_found(response)
assert 'The resource \'/compute/v1/projects/exampleproject/regions/invalidregionname\' was not found' \
in response.data

0 comments on commit 55f75c1

Please sign in to comment.