summaryrefslogtreecommitdiffstats
path: root/app/tests/test_node_templates.py
blob: 2d79b955e51a469c76fed90286f0905473aaba41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
from tests.utils.test_utils import init_template
from toscalib.templates.node import Node


class TestNodeTemplateMethods(unittest.TestCase):

    def test_instantiate_with_type(self):
        template = init_template()
        node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
        self.assertEqual(1, len(node.attributes))
        node._instatiateWithType(template.db.NODE_TYPES.get('substituteNodeType'))
        self.assertEqual(0, len(node.attributes))

    def test_parse_pre_defined_content(self):
        template = init_template()
        node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
        self.assertIsNone(node.properties.get('propertyName').value)
        prop_sec = {'properties': {'propertyName': 'template_value'}}
        node._parse_pre_defined_content(prop_sec)
        self.assertEqual('template_value', node.properties.get('propertyName').value.value)

    def test_update_get_node_name_property_value(self):
        template = init_template()
        node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
        prop_sec = {'properties': {'propertyName': '__GET_NODE_NAME__'}}
        node._parse_pre_defined_content(prop_sec)
        self.assertEqual('__GET_NODE_NAME__', node.properties.get('propertyName').value.value)
        node._update_get_node_name()
        self.assertEqual('myNode', node.properties.get('propertyName').value.value)

    def test_update_get_node_name_capability_property_value(self):
        template = init_template()
        node = Node(template, 'myNode', template.db.NODE_TYPES.get('nodeTypeName'))
        prop_sec = {'capabilities': {'capabilityName': {'properties': {'capabilityProperty': '__GET_NODE_NAME__'}}}}
        node._parse_pre_defined_content(prop_sec)
        self.assertEqual('__GET_NODE_NAME__', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)
        node._update_get_node_name()
        self.assertEqual('myNode', node._get_capability_property('capabilityName', 'capabilityProperty').value.value)

    def test_update_prefix(self):
        template = init_template()
        node = template.node_dict.get('nodeName')
        prop_sec = {'properties': {'propertyName': {'get_input': 'inputName'}}, 'capabilities': {'capabilityName': {'properties': {'capabilityProperty': {'get_property': ['nodeName', 'propertyName']}}}}}
        node._parse_pre_defined_content(prop_sec)
        node._update_prefix('PREFIX_')
        self.assertEqual('PREFIX_nodeName', node.name)
        self.assertEqual('PREFIX_nodeName', node.id.value.function.extra_data[0])
        self.assertEqual('PREFIX_inputName', node.properties.get('propertyName').value.function.target_property)
        self.assertEqual('PREFIX_nodeName', node._get_capability_property('capabilityName', 'capabilityProperty').value.function.extra_data[0])

    def test_verify_functions(self):
        template = init_template()
        node = template.node_dict.get('nodeName')
        prop_sec = {'properties': {'propertyName': {'get_input': 'inputName'}}, 'capabilities': {'capabilityName': {'properties': {'capabilityProperty': {'get_property': ['nodeName', 'propertyName']}}}}}
        node._parse_pre_defined_content(prop_sec)
        self.assertIsNone(node.properties.get('propertyName').value.function.value_from_item)
        self.assertIsNone(node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_item)
        self.assertIsNone(node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_node)
        node._verify_functions()
        self.assertIsNotNone(node.properties.get('propertyName').value.function.value_from_item)
        self.assertIsNotNone(node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_item)
        self.assertIsNotNone(node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_node)
        self.assertEqual(template.inputs.get('inputName'), node.properties.get('propertyName').value.function.value_from_item)
        self.assertEqual(node.properties.get('propertyName'), node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_item)
        self.assertEqual(node, node._get_capability_property('capabilityName', 'capabilityProperty').value.function.value_from_node)