summaryrefslogtreecommitdiffstats
path: root/app/tests/test_topology_template.py
blob: 8e7da5a6d8e0cb47aaba6e55763a74fbbdabaa83 (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
import unittest
from toscalib.templates.topology import ToscaTopology
from tests.utils.test_utils import init_template


class TestTopologyTemplateMethods(unittest.TestCase):

    def test_update_mapping_template_pointer(self):
        template = init_template()
        sub_sec = {'node_type': 'substituteNodeType', 'capabilities': {'substituteCapability': ['nodeName', 'capabilityName']}}
        sub_type = template.db.NODE_TYPES.get('substituteNodeType')
        self.assertIsNone(sub_type.mapping_template)
        template._parse_substitution(template.db, sub_sec)
        self.assertIsNotNone(sub_type.mapping_template)
        self.assertEqual(sub_type.mapping_template, template)

    def test_parse_substitution(self):
        template = init_template()
        sub_sec = {'node_type': 'substituteNodeType', 'requirements': {'substituteRequirement': ['node2', 'dummyRequirement']}, 'capabilities': {'substituteCapability': ['nodeName', 'capabilityName']}}
        self.assertIsNone(template.sub_type)
        self.assertEqual(len(template.sub_rules), 0)
        template._parse_substitution(template.db, sub_sec)
        self.assertEqual(template.sub_type, 'substituteNodeType')
        self.assertEqual(len(template.sub_rules), 3)

    def test_prepare_output(self):
        template = ToscaTopology('topoName')
        res = template._prepare_output()
        self.assertEqual(res, {'00_YAMLORDER_tosca_definitions_version': 'tosca_simple_yaml_1_0_0', '14_YAMLORDER_topology_template': {}})
        template = init_template()
        res = template._prepare_output()
        self.assertEqual(res, {'00_YAMLORDER_tosca_definitions_version': 'tosca_simple_yaml_1_0_0', '14_YAMLORDER_topology_template': {'11_YAMLORDER_inputs': {'inputName': {'00_YAMLORDER_type': 'string'}},
                               '13_YAMLORDER_node_templates': {'node2': {'00_YAMLORDER_type': 'nodeTypeName', '01_YAMLORDER_properties': {'propertyName': None},'05_YAMLORDER_requirements': [{'dummyRequirement': 'nodeName'}]},
                               'nodeName': {'00_YAMLORDER_type': 'nodeTypeName', '01_YAMLORDER_properties': {'propertyName': None}}}}})