author | Tero Marttila <terom@fixme.fi> |
Thu, 02 Apr 2009 20:19:18 +0300 | |
changeset 1 | 2223ade4f259 |
parent 0 | 257003279747 |
child 2 | e66102ab7048 |
permissions | -rwxr-xr-x |
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
1 |
#!/usr/bin/env python2.5 |
0 | 2 |
""" |
3 |
Test conf_dhcp |
|
4 |
""" |
|
5 |
||
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
6 |
import dhcp_conf as dhcpc, conf, addr |
0 | 7 |
|
8 |
import unittest |
|
9 |
from cStringIO import StringIO |
|
10 |
||
11 |
class TestConfDHCP (unittest.TestCase) : |
|
12 |
def assert_stmt (self, stmt, line) : |
|
13 |
""" |
|
14 |
Formats the given Statement, and compares the output against the given line |
|
15 |
""" |
|
16 |
||
17 |
self.assertEqual(stmt._fmt_data(), line) |
|
18 |
||
19 |
def test_statement (self) : |
|
20 |
self.assert_stmt(dhcpc.Statement("stmt0"), "stmt0") |
|
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
21 |
self.assert_stmt(dhcpc.Statement("stmt1", [ "this", "that" ]), "stmt1 this, that") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
22 |
self.assert_stmt(dhcpc.Statement("stmt2", dhcpc.Literal("...")), "stmt2 ...") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
23 |
self.assert_stmt(dhcpc.Statement("stmt3", u"quux"), "stmt3 quux") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
24 |
self.assert_stmt(dhcpc.Statement("stmt4", "bar"), "stmt4 bar") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
25 |
self.assert_stmt(dhcpc.Statement("stmt5", 1), "stmt5 1") |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
26 |
self.assert_stmt(dhcpc.Statement("stmt6", 1, None, 2), "stmt6 1 2") |
0 | 27 |
|
28 |
def assert_obj (self, obj, lines) : |
|
29 |
""" |
|
30 |
Formats the given conf.Object and compares the output against the given lines |
|
31 |
""" |
|
32 |
||
33 |
self.assertEqual(list(obj.fmt_lines()), lines) |
|
34 |
||
35 |
def test_literal (self) : |
|
36 |
self.assert_obj(dhcpc.Literal("///"), [ "///" ]) |
|
37 |
||
38 |
def test_parameter (self) : |
|
39 |
self.assert_obj(dhcpc.Parameter("param0", "this", 13, "that"), [ "param0 this 13 that;" ]) |
|
40 |
||
41 |
def test_declaration (self) : |
|
42 |
self.assert_obj(dhcpc.Declaration("decl0", ["arg0", "arg1"], [ |
|
1
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
43 |
dhcpc.Parameter("param0"), |
2223ade4f259
continue the overengineering effort, we are now able to generate dhcpd.conf files
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
44 |
None |
0 | 45 |
], [ |
46 |
dhcpc.Declaration("decl0.0", params=[ |
|
47 |
dhcpc.Parameter("param0.0.1", "value") |
|
48 |
]) |
|
49 |
]), [ |
|
50 |
||
51 |
"decl0 arg0 arg1 {", |
|
52 |
"\tparam0;", |
|
53 |
"\tdecl0.0 {", |
|
54 |
"\t\tparam0.0.1 value;", |
|
55 |
"\t}", |
|
56 |
"}", |
|
57 |
]) |
|
58 |
||
59 |
def test_shared_network (self) : |
|
60 |
self.assert_obj(dhcpc.SharedNetwork("net0", params=[ |
|
61 |
dhcpc.Parameter("param0") |
|
62 |
]), [ |
|
63 |
"shared-network net0 {", |
|
64 |
"\tparam0;", |
|
65 |
"}" |
|
66 |
]) |
|
67 |
||
68 |
def test_subnet (self) : |
|
69 |
self.assert_obj(dhcpc.Subnet(addr.Network("194.197.235.0/24"), params=[ |
|
70 |
dhcpc.Parameter("param0") |
|
71 |
]), [ |
|
72 |
"subnet 194.197.235.0 netmask 255.255.255.0 {", |
|
73 |
"\tparam0;", |
|
74 |
"}" |
|
75 |
]) |
|
76 |
||
77 |
def test_group (self) : |
|
78 |
self.assert_obj(dhcpc.Group(decls=[ |
|
79 |
dhcpc.Declaration("decl0.0", params=[ |
|
80 |
dhcpc.Parameter("param0.0.1", "value") |
|
81 |
]) |
|
82 |
]), [ |
|
83 |
"group {", |
|
84 |
"\tdecl0.0 {", |
|
85 |
"\t\tparam0.0.1 value;", |
|
86 |
"\t}", |
|
87 |
"}" |
|
88 |
]) |
|
89 |
||
90 |
def test_host (self) : |
|
91 |
self.assert_obj(dhcpc.Host("test-hostname", params=[ |
|
92 |
dhcpc.Parameter("param0") |
|
93 |
]), [ |
|
94 |
"host test-hostname {", |
|
95 |
"\tparam0;", |
|
96 |
"}" |
|
97 |
]) |
|
98 |
||
99 |
def test_option (self) : |
|
100 |
self.assert_obj(dhcpc.Option("foo", "example.com"), [ |
|
101 |
"option foo example.com;", |
|
102 |
]) |
|
103 |
||
104 |
if __name__ == '__main__' : |
|
105 |
unittest.main() |
|
106 |