blob: 8e7da5a6d8e0cb47aaba6e55763a74fbbdabaa83 [file] [log] [blame]
Betzer, Rony (rb844h)2236f9d2018-10-04 16:47:13 +03001import unittest
2from toscalib.templates.topology import ToscaTopology
3from tests.utils.test_utils import init_template
4
5
6class TestTopologyTemplateMethods(unittest.TestCase):
7
8 def test_update_mapping_template_pointer(self):
9 template = init_template()
10 sub_sec = {'node_type': 'substituteNodeType', 'capabilities': {'substituteCapability': ['nodeName', 'capabilityName']}}
11 sub_type = template.db.NODE_TYPES.get('substituteNodeType')
12 self.assertIsNone(sub_type.mapping_template)
13 template._parse_substitution(template.db, sub_sec)
14 self.assertIsNotNone(sub_type.mapping_template)
15 self.assertEqual(sub_type.mapping_template, template)
16
17 def test_parse_substitution(self):
18 template = init_template()
19 sub_sec = {'node_type': 'substituteNodeType', 'requirements': {'substituteRequirement': ['node2', 'dummyRequirement']}, 'capabilities': {'substituteCapability': ['nodeName', 'capabilityName']}}
20 self.assertIsNone(template.sub_type)
21 self.assertEqual(len(template.sub_rules), 0)
22 template._parse_substitution(template.db, sub_sec)
23 self.assertEqual(template.sub_type, 'substituteNodeType')
24 self.assertEqual(len(template.sub_rules), 3)
25
26 def test_prepare_output(self):
27 template = ToscaTopology('topoName')
28 res = template._prepare_output()
29 self.assertEqual(res, {'00_YAMLORDER_tosca_definitions_version': 'tosca_simple_yaml_1_0_0', '14_YAMLORDER_topology_template': {}})
30 template = init_template()
31 res = template._prepare_output()
32 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'}},
33 '13_YAMLORDER_node_templates': {'node2': {'00_YAMLORDER_type': 'nodeTypeName', '01_YAMLORDER_properties': {'propertyName': None},'05_YAMLORDER_requirements': [{'dummyRequirement': 'nodeName'}]},
34 'nodeName': {'00_YAMLORDER_type': 'nodeTypeName', '01_YAMLORDER_properties': {'propertyName': None}}}}})
35