summaryrefslogtreecommitdiffstats
path: root/app/tests/test_substitution_rule.py
blob: aec374547bf6c5f0da00a7e6790bc74c13fedf8b (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
import unittest
from tests.utils.test_utils import *


class TestSubstitutionRuleMethods(unittest.TestCase):

    def test_update_pointer(self):
        template = init_template()
        sub_template = init_sub_template()
        src_node = sub_template.node_dict.get('nodeName')
        target_node = template.node_dict.get('node2')
        sub_sec = {'node_type': 'nodeTypeName',
                      'requirements': {'substituteRequirement': ['node2', 'dummyRequirement']},
                     'capabilities': {'substituteCapability': ['node2', 'capabilityName']}}
        sub_template._parse_substitution(template.db, sub_sec)
        rules = sub_template.sub_rules
        self.assertIsNone(src_node.properties[rules[0].property].sub_pointer)
        self.assertIsNone(src_node.capabilities[rules[1].item].sub_pointer)
        self.assertIsNone(src_node.capabilities[rules[1].item].properties['capabilityProperty'].sub_pointer)
        self.assertIsNone(src_node.requirements[0].sub_pointer)
        rules[0]._update_pointer(src_node, sub_template)
        self.assertIsNotNone(src_node.properties[rules[0].property].sub_pointer)
        self.assertEqual(src_node.properties[rules[0].property].sub_pointer, sub_template.inputs[rules[0].property])
        rules[1]._update_pointer(src_node, template)
        self.assertIsNotNone(src_node.capabilities[rules[1].item].sub_pointer)
        self.assertIsNotNone(src_node.capabilities[rules[1].item].properties['capabilityProperty'].sub_pointer)
        self.assertEqual(src_node.capabilities[rules[1].item].sub_pointer, target_node.capabilities[rules[1].value[1]])
        self.assertEqual(src_node.capabilities[rules[1].item].properties['capabilityProperty'].sub_pointer, target_node.capabilities[rules[1].value[1]].properties['capabilityProperty'])
        rules[2]._update_pointer(src_node, template)
        self.assertIsNotNone(src_node.requirements[0].sub_pointer)
        self.assertEqual(src_node.requirements[0].sub_pointer, target_node.requirements[0])