Commit 0f9986eb authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

cyclades: Update api/networks.py and typo fixes

* Update api/networks.py to use the updated get_attribute from commit
14402edcf6d19fc42a64ef93da3d66ef7969327b.
* Add corresponding test case
* Typo fix in an error message in api/subnets.py

Refs #4979
parent e818eff8
......@@ -112,8 +112,10 @@ def create_network(request):
req = api.utils.get_request_dict(request)
log.info('create_network %s', req)
network_dict = api.utils.get_attribute(req, "network")
flavor = api.utils.get_attribute(network_dict, "type")
network_dict = api.utils.get_attribute(req, "network",
attr_type=dict)
flavor = api.utils.get_attribute(network_dict, "type",
attr_type=basestring)
if flavor not in Network.FLAVORS.keys():
raise api.faults.BadRequest("Invalid network type '%s'" % flavor)
......@@ -121,7 +123,8 @@ def create_network(request):
raise api.faults.Forbidden("Cannot create network of type '%s'." %
flavor)
name = api.utils.get_attribute(network_dict, "name", required=False)
name = api.utils.get_attribute(network_dict, "name", attr_type=basestring,
required=False)
if name is None:
name = ""
......@@ -144,8 +147,9 @@ def get_network_details(request, network_id):
def update_network(request, network_id):
info = api.utils.get_request_dict(request)
network = api.utils.get_attribute(info, "network", required=True)
new_name = api.utils.get_attribute(network, "name")
network = api.utils.get_attribute(info, "network", attr_type=dict,
required=True)
new_name = api.utils.get_attribute(network, "name", attr_type=basestring)
network = util.get_network(network_id, request.user_uniq, for_update=True)
if network.public:
......
......@@ -196,7 +196,7 @@ def update_subnet(request, sub_id):
raise api.faults.BadRequest("Malformed request")
if len(subnet) != 1 or "name" not in subnet:
raise api.faults.BadRequest("Only the name of subnet can be updated")
raise api.faults.BadRequest("Only the name of a subnet can be updated")
name = subnet.get("name", None)
......
......@@ -68,6 +68,18 @@ class NetworkTest(BaseAPITest):
self.assertEqual(response.status_code, 403)
self.assertEqual(len(Network.objects.filter(userid='user1')), 0)
def test_invalid_create2(self):
"""Test invalid name type"""
request = {
"network": {
"type": "MAC_FILTERED",
"name": ["Test"]
}
}
response = self.post(NETWORKS_URL, params=json.dumps(request))
code = response.status_code
self.assertBarRequest(response)
def test_create(self):
request = {
"network": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment