Enable parameter check before node composition
This patch enabled check for "name" field in request body before node composition, raise BadRequest exception if if don't exits. Changed "description" to optional, and will set it to empty string if it don't exist. Change-Id: Ib3624ad85e12823c5f6fd6321d3161b88a7b6ecf Closes-Bug: #1677046
This commit is contained in:
parent
65710b799c
commit
d0b9f60bba
@ -217,7 +217,7 @@ node_request_description:
|
||||
description: |
|
||||
A description for a new composed node
|
||||
in: body
|
||||
required: tree
|
||||
required: false
|
||||
type: string
|
||||
node_request_name:
|
||||
description: |
|
||||
|
@ -77,8 +77,12 @@ class Node(object):
|
||||
"processor": {}
|
||||
}
|
||||
|
||||
if not("name" in request_body and request_body["name"].strip()):
|
||||
raise exception.BadRequest(
|
||||
detail="Please specify a name of the node to compose")
|
||||
name = request_body["name"]
|
||||
description = request_body["description"]
|
||||
# "description" is optional
|
||||
description = request_body.get("description", "")
|
||||
|
||||
compose_request = cls._create_compose_request(name,
|
||||
description,
|
||||
|
@ -73,6 +73,14 @@ class TestAPINodes(unittest.TestCase):
|
||||
requirements)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_compose_node_with_wrong_parameters(self):
|
||||
"""Test compose node with no name input"""
|
||||
with self.assertRaises(exception.BadRequest) as context:
|
||||
nodes.Node.compose_node({"no_name": "fake_value"})
|
||||
|
||||
self.assertTrue("Please specify a name of the node to compose"
|
||||
in context.exception.detail)
|
||||
|
||||
@mock.patch("valence.db.api.Connection.create_composed_node")
|
||||
@mock.patch("valence.common.utils.generate_uuid")
|
||||
@mock.patch("valence.controller.nodes.Node.list_composed_nodes")
|
||||
|
Loading…
x
Reference in New Issue
Block a user