test_dhcp.py
changeset 0 257003279747
child 1 2223ade4f259
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_dhcp.py	Thu Apr 02 17:47:43 2009 +0300
@@ -0,0 +1,103 @@
+"""
+    Test conf_dhcp
+"""
+
+import conf_dhcp as dhcpc, conf, addr
+
+import unittest
+from cStringIO import StringIO
+
+class TestConfDHCP (unittest.TestCase) :
+    def assert_stmt (self, stmt, line) :
+        """
+            Formats the given Statement, and compares the output against the given line
+        """
+        
+        self.assertEqual(stmt._fmt_data(), line)
+    
+    def test_statement (self) :
+        self.assert_stmt(dhcpc.Statement("stmt0"),                           "stmt0")
+        self.assert_stmt(dhcpc.Statement("stmt3", [ "this", "that" ]),       "stmt3 this, that")
+        self.assert_stmt(dhcpc.Statement("stmt4", dhcpc.Literal("...")),     "stmt4 ...")
+        self.assert_stmt(dhcpc.Statement("stmt1", u"quux"),                  "stmt1 quux")
+        self.assert_stmt(dhcpc.Statement("stmt1", "bar"),                    "stmt1 bar")
+        self.assert_stmt(dhcpc.Statement("stmt2", 1),                        "stmt2 1")
+ 
+    def assert_obj (self, obj, lines) :
+        """
+            Formats the given conf.Object and compares the output against the given lines
+        """
+
+        self.assertEqual(list(obj.fmt_lines()), lines)
+    
+    def test_literal (self) :
+        self.assert_obj(dhcpc.Literal("///"),                               [ "///" ])
+
+    def test_parameter (self) :
+        self.assert_obj(dhcpc.Parameter("param0", "this", 13, "that"),      [ "param0 this 13 that;" ])
+    
+    def test_declaration (self) :
+        self.assert_obj(dhcpc.Declaration("decl0", ["arg0", "arg1"], [
+            dhcpc.Parameter("param0")
+        ], [
+            dhcpc.Declaration("decl0.0", params=[
+                dhcpc.Parameter("param0.0.1", "value")
+            ])
+        ]),  [
+            
+            "decl0 arg0 arg1 {",
+            "\tparam0;",
+            "\tdecl0.0 {",
+            "\t\tparam0.0.1 value;",
+            "\t}",
+            "}",
+        ])
+    
+    def test_shared_network (self) :
+        self.assert_obj(dhcpc.SharedNetwork("net0", params=[
+            dhcpc.Parameter("param0")
+        ]), [
+            "shared-network net0 {",
+            "\tparam0;",
+            "}"
+        ])
+
+    def test_subnet (self) :
+        self.assert_obj(dhcpc.Subnet(addr.Network("194.197.235.0/24"), params=[
+            dhcpc.Parameter("param0")
+        ]), [
+            "subnet 194.197.235.0 netmask 255.255.255.0 {",
+            "\tparam0;",
+            "}"
+        ])
+
+    def test_group (self) :
+        self.assert_obj(dhcpc.Group(decls=[
+            dhcpc.Declaration("decl0.0", params=[
+                dhcpc.Parameter("param0.0.1", "value")
+            ])
+        ]), [
+            "group {",
+            "\tdecl0.0 {",
+            "\t\tparam0.0.1 value;",
+            "\t}",
+            "}"
+        ])
+    
+    def test_host (self) :
+        self.assert_obj(dhcpc.Host("test-hostname", params=[
+            dhcpc.Parameter("param0")
+        ]), [
+            "host test-hostname {",
+            "\tparam0;",
+            "}"
+        ])
+
+    def test_option (self) :
+        self.assert_obj(dhcpc.Option("foo", "example.com"), [
+            "option foo example.com;",
+        ])
+    
+if __name__ == '__main__' :
+    unittest.main()
+