Skip to content
Permalink
Browse files
Add network unittests
  • Loading branch information
brogand93 committed Jun 1, 2014
1 parent 3cc8eac commit 8e90072771c4caf133d86c8aee31f81e8c618df1
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
@@ -49,8 +49,7 @@ def get_network_by_name(authorization, securitygroup):

if securitygroup_list['listsecuritygroupsresponse']:
response = helper.filter_by_name(
data=securitygroup_list[
'listsecuritygroupsresponse']['securitygroup'],
data=securitygroup_list['listsecuritygroupsresponse']['securitygroup'],
name=securitygroup
)
return response
@@ -62,6 +61,7 @@ def _get_network(authorization, args=None):
command = 'createSecurityGroup'
if not args:
args = {}

cloudstack_response = requester.make_request(
command,
args,
@@ -123,8 +123,7 @@ def _create_populated_network_response(projectid, networks=None):
return populated_response


@app.route(
'/compute/v1/projects/<projectid>/global/networks', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/networks', methods=['GET'])
@authentication.required
def listnetworks(projectid, authorization):
securitygroup_list = _get_networks(
@@ -185,7 +184,7 @@ def addnetwork(authorization, projectid):
'error': {
'errors': [{
'code': 'RESOURCE_ALREADY_EXISTS',
'message': 'the resource \'projects/\'' + projectid + '/global/networks/' + args['name']
'message': 'The resource \'projects/\'' + projectid + '/global/networks/' + args['name']
}]
}
}
@@ -1,6 +1,6 @@
{
"listvirtualmachinesresponse": {
"count": 2,
"count": 1,
"virtualmachine": [
{
"domain": "ROOT",
@@ -0,0 +1,40 @@
{
"listsecuritygroupsresponse": {
"count": 1,
"securitygroup": [
{
"egressrule": [],
"account": "example-account",
"domainid": "66d69e46-a95b-437b-ac6c-bcaa5331999d",
"description": "Default Security Group",
"tags": [],
"domain": "example-account",
"ingressrule": [
{
"protocol": "tcp",
"cidr": "0.0.0.0/0",
"startport": 22,
"endport": 22,
"ruleid": "3d92cc70-8c84-4e8a-9989-6efcd7ff7905"
},
{
"protocol": "icmp",
"cidr": "0.0.0.0/0",
"ruleid": "2ba7dd7b-13b2-49ae-bf8e-26ffadd32c9e",
"icmpcode": 0,
"icmptype": 0
},
{
"protocol": "tcp",
"cidr": "0.0.0.0/0",
"startport": 8080,
"endport": 8080,
"ruleid": "c4562b3c-d1b0-4844-a771-3c3434e1a5d0"
}
],
"id": "1f95ee9b-b291-48c1-9492-0eee632677e3",
"name": "networkname"
}
]
}
}
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# encoding: utf-8

import mock

from gstack.helpers import read_file
from . import GStackAppTestCase

class NetworksTestCase(GStackAppTestCase):

def test_list_networks(self):

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

self.assert_ok(response)

def test_get_network(self):

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

self.assert_ok(response)

def test_get_network_network_not_found(self):

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

self.assert_not_found(response)
assert 'The resource \'/compute/v1/projects/exampleproject/global/networks/networkname\'' \
in response.data

0 comments on commit 8e90072

Please sign in to comment.