summaryrefslogtreecommitdiff
path: root/reconfigure/tests/includers/nginx_tests.py
blob: ad980a1f85df559dc8249c8f4f687effd3ea7ed5 (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
#coding: utf8
import unittest
from reconfigure.parsers import NginxParser
from reconfigure.includers import NginxIncluder


class IncludersTest (unittest.TestCase):
    def test_compose_decompose(self):
        content = """
            sec1 {
                p1 1;
                include test;
            }
        """
        content2 = """
            sec2 {
                p2 2;
            }
        """

        parser = NginxParser()
        includer = NginxIncluder(parser=parser, content_map={'test': content2})
        tree = parser.parse(content)
        tree = includer.compose(None, tree)
        self.assertTrue(len(tree.children[0].children) == 3)

        treemap = includer.decompose(tree)
        self.assertTrue(len(treemap.keys()) == 2)
        self.assertTrue(treemap['test'].children[0].name == 'sec2')