pvl/hosts/tests.py
changeset 479 1e68e3a30b51
parent 477 6ad810c8039c
child 480 7e44854e85d4
--- a/pvl/hosts/tests.py	Thu Feb 26 14:40:14 2015 +0200
+++ b/pvl/hosts/tests.py	Thu Feb 26 14:40:37 2015 +0200
@@ -436,5 +436,37 @@
             ('6', 'PTR'): ['ufc.domain.'],
         })
 
+class TestDhcp(unittest.TestCase):
+    def setUp(self):
+        self.options = pvl.args.options(
+                hosts_charset   = 'utf-8',
+                hosts_domain    = None,
+                hosts_include   = None,
+        )
+
+    def assertBlocksEqual(self, blockdefs, expected):
+        for (_block, _items, _opts), (block, items, opts) in zip(blockdefs, expected):
+            self.assertEqual(_block, block)
+            self.assertItemsEqual(_items, items)
+
+            if opts is not None:
+                self.assertEqual(_opts, opts)
+        
+        self.assertEqual(len(blockdefs), len(expected))
+    
+    def testHost(self):
+        host = Host.build('foo', 'test',
+                ip          = '192.0.2.1',
+                ethernet    = '00:11:22:33:44:55',
+        )
+
+        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
+            (('host', 'foo'), [
+                ('option', 'host-name', "foo"),
+                ('fixed-address', '192.0.2.1'),
+                ('hardware', 'ethernet', '00:11:22:33:44:55'),
+            ], None)
+        ])
+
 if __name__ == '__main__':
     unittest.main()