pvl.dhcp.tests: test build_block()
authorTero Marttila <terom@paivola.fi>
Mon, 02 Mar 2015 00:38:59 +0200
changeset 678 5f280b922905
parent 677 8e3dfa27d8d1
child 679 31adba0f586d
pvl.dhcp.tests: test build_block()
pvl/dhcp/tests.py
--- a/pvl/dhcp/tests.py	Mon Mar 02 00:38:50 2015 +0200
+++ b/pvl/dhcp/tests.py	Mon Mar 02 00:38:59 2015 +0200
@@ -1,4 +1,5 @@
 import itertools
+import re
 import unittest
 
 from pvl.dhcp import config
@@ -86,7 +87,7 @@
 
     include "hosts/test.conf";
 
-    host test {
+    host foo {
         fixed-address       192.0.2.1;
         hardware ethernet   00:11:22:33:44:55;
     }
@@ -96,9 +97,47 @@
             ('filename', "/debian/wheezy/pxelinux.0"),
             ('include', "hosts/test.conf"),
         ], [
-            (('host', 'test'), [
+            (('host', 'foo'), [
                 ('fixed-address', '192.0.2.1'),
                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
             ], [])
         ]))
 
+class ConfigBuildTest(unittest.TestCase):
+    def assertEqualWhitespace(self, value, expected):
+        # normalize
+        value = re.sub(r'\s+', ' ', value)
+        expected = re.sub(r'\s+', ' ', expected)
+
+        self.assertEqual(value, expected)
+
+    def assertLinesEqual(self, lines, expected):
+        for line, expect in itertools.izip_longest(lines, expected):
+            self.assertEqualWhitespace(line, expect)
+
+    def testBuildConf(self):
+        self.assertLinesEqual(
+                config.build_block(config.Block(('group', ), [
+                        ('next-server', 'boot.test'),
+                        ('filename', "/debian/wheezy/pxelinux.0"),
+                        ('include', "hosts/test.conf"),
+                    ], [
+                        config.Block(('host', 'foo'), [
+                            ('fixed-address', '192.0.2.1'),
+                            ('hardware', 'ethernet', '00:11:22:33:44:55'),
+                        ]),
+                    ]
+                )),
+                """
+group {
+    next-server boot.test;
+    filename "/debian/wheezy/pxelinux.0";
+    include "hosts/test.conf";
+
+    host foo {
+        fixed-address       192.0.2.1;
+        hardware ethernet   00:11:22:33:44:55;
+    }
+}
+                """.strip().splitlines()
+        )