Merge "Return variables in response on Network create"
This commit is contained in:
commit
2fe08e9f4c
@ -35,13 +35,19 @@ class Networks(base.Resource):
|
||||
"""Create a new network."""
|
||||
json = util.copy_project_id_into_json(context, request_data)
|
||||
network_obj = dbapi.networks_create(context, json)
|
||||
network = jsonutils.to_primitive(network_obj)
|
||||
if 'variables' in json:
|
||||
network["variables"] = jsonutils.to_primitive(
|
||||
network_obj.variables)
|
||||
else:
|
||||
network["variables"] = {}
|
||||
|
||||
location = v1.api.url_for(
|
||||
NetworkById, id=network_obj.id, _external=True
|
||||
)
|
||||
headers = {'Location': location}
|
||||
|
||||
return jsonutils.to_primitive(network_obj), 201, headers
|
||||
return network, 201, headers
|
||||
|
||||
|
||||
class NetworkById(base.Resource):
|
||||
|
@ -1345,6 +1345,25 @@ class APIV1NetworksTest(APIV1Test):
|
||||
"http://localhost/v1/networks/1"
|
||||
)
|
||||
|
||||
@mock.patch.object(dbapi, 'networks_create')
|
||||
def test_create_network_returns_network_obj(self, mock_network):
|
||||
mock_network.return_value = fake_resources.NETWORK1
|
||||
data = {
|
||||
'name': 'PrivateNetwork',
|
||||
'cidr': '192.168.1.0/24',
|
||||
'gateway': '192.168.1.1',
|
||||
'netmask': '255.255.255.0',
|
||||
'variables': {'key1': 'value1'},
|
||||
'region_id': 1,
|
||||
'cloud_id': 1,
|
||||
}
|
||||
expected_result = copy.deepcopy(data)
|
||||
expected_result.update({'id': 1, 'project_id': 1})
|
||||
|
||||
resp = self.post('/v1/networks', data=data)
|
||||
self.assertEqual(201, resp.status_code)
|
||||
self.assertEqual(expected_result, resp.json)
|
||||
|
||||
@mock.patch.object(dbapi, 'networks_create')
|
||||
def test_create_networks_with_invalid_data(self, mock_network):
|
||||
mock_network.return_value = None
|
||||
|
Loading…
Reference in New Issue
Block a user