1 #!/usr/bin/env python2.5 |
1 #!/usr/bin/env python2.5 |
2 """ |
2 """ |
3 Test conf_dhcp |
3 Test dhcp_conf |
4 """ |
4 """ |
5 |
5 |
6 import dhcp_conf as dhcpc, dhcp, addr |
6 import dhcp_conf as dhcpc |
|
7 import test_conf, dhcp, addr |
7 |
8 |
8 import unittest |
9 import unittest |
9 |
10 |
10 class _TestConfObj (unittest.TestCase) : |
11 class TestDHCPConf (test_conf._TestConfBase) : |
11 def assert_obj (self, obj, lines) : |
|
12 """ |
|
13 Formats the given conf.Object and compares the output against the given lines |
|
14 """ |
|
15 |
|
16 for obj_line, line in zip(obj.fmt_lines(), lines) : |
|
17 self.assertEqual(obj_line, line) |
|
18 |
|
19 class TestDHCPConf (_TestConfObj) : |
|
20 def assert_stmt (self, stmt, line) : |
12 def assert_stmt (self, stmt, line) : |
21 """ |
13 """ |
22 Formats the given Statement, and compares the output against the given line. |
14 Formats the given Statement, and compares the output against the given line. |
23 |
15 |
24 Note that the dhcpc.Statement doesn't have a working fmt_lines implementation. |
16 Note that the dhcpc.Statement doesn't have a working fmt_lines implementation. |
118 "option foo example.com;", |
110 "option foo example.com;", |
119 ]) |
111 ]) |
120 |
112 |
121 class TestDHCP (_TestConfObj) : |
113 class TestDHCP (_TestConfObj) : |
122 def test_host (self) : |
114 def test_host (self) : |
123 self.assert_obj(dhcp.Host("testhost", addr.MAC("12:34:56:78:90:ab"), addr.IP("1.2.3.4")), [ |
115 self.assert_obj(dhcp.Host("testhost", addr.MAC("12:34:56:78:90:ab"), addr.IP("1.2.3.4"), comment="foo"), [ |
|
116 "# foo", |
124 "host testhost {", |
117 "host testhost {", |
125 "\thardware ethernet 12:34:56:78:90:ab;", |
118 "\thardware ethernet 12:34:56:78:90:ab;", |
126 "\tfixed-address 1.2.3.4;", |
119 "\tfixed-address 1.2.3.4;", |
127 "}" |
120 "}" |
128 ]) |
121 ]) |
129 |
122 |
130 def test_subnet (self) : |
123 def test_subnet (self) : |
131 self.assert_obj(dhcp.Subnet(addr.Network("1.2.3.0/24")), [ |
124 self.assert_obj(dhcp.Subnet(addr.Network("1.2.3.0/24"), comment="bar"), [ |
|
125 "# bar", |
132 "subnet 1.2.3.0 netmask 255.255.255.0 {", |
126 "subnet 1.2.3.0 netmask 255.255.255.0 {", |
133 "\toption routers 1.2.3.1;", |
127 "\toption routers 1.2.3.1;", |
134 "}" |
128 "}" |
135 ]) |
129 ]) |
136 |
130 |