Skip to content

Commit d97636e

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
tests: add unit tests for smbconf_api
Signed-off-by: John Mulligan <[email protected]>
1 parent 9d20023 commit d97636e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/test_smbconf_api.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#
2+
# sambacc: a samba container configuration tool
3+
# Copyright (C) 2023 John Mulligan
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>
17+
#
18+
19+
import io
20+
21+
import sambacc.smbconf_api
22+
23+
24+
def test_simple_config_store():
25+
scs = sambacc.smbconf_api.SimpleConfigStore()
26+
assert scs.writeable, "SimpleConfigStore should always be writeable"
27+
scs["foo"] = [("a", "Artichoke"), ("b", "Broccoli")]
28+
scs["bar"] = [("example", "yes"), ("production", "no")]
29+
assert list(scs) == ["foo", "bar"]
30+
assert scs["foo"] == [("a", "Artichoke"), ("b", "Broccoli")]
31+
assert scs["bar"] == [("example", "yes"), ("production", "no")]
32+
33+
34+
def test_simple_config_store_import():
35+
a = sambacc.smbconf_api.SimpleConfigStore()
36+
b = sambacc.smbconf_api.SimpleConfigStore()
37+
a["foo"] = [("a", "Artichoke"), ("b", "Broccoli")]
38+
b["bar"] = [("example", "yes"), ("production", "no")]
39+
assert list(a) == ["foo"]
40+
assert list(b) == ["bar"]
41+
42+
a.import_smbconf(b)
43+
assert list(a) == ["foo", "bar"]
44+
assert list(b) == ["bar"]
45+
assert a["bar"] == [("example", "yes"), ("production", "no")]
46+
47+
b["baz"] = [("quest", "one")]
48+
b["bar"] = [("example", "no"), ("production", "no"), ("unittest", "yes")]
49+
a.import_smbconf(b)
50+
51+
assert list(a) == ["foo", "bar", "baz"]
52+
assert a["bar"] == [
53+
("example", "no"),
54+
("production", "no"),
55+
("unittest", "yes"),
56+
]
57+
assert a["baz"] == [("quest", "one")]
58+
59+
60+
def test_write_store_as_smb_conf():
61+
scs = sambacc.smbconf_api.SimpleConfigStore()
62+
scs["foo"] = [("a", "Artichoke"), ("b", "Broccoli")]
63+
scs["bar"] = [("example", "yes"), ("production", "no")]
64+
scs["global"] = [("first", "1"), ("second", "2")]
65+
fh = io.StringIO()
66+
sambacc.smbconf_api.write_store_as_smb_conf(fh, scs)
67+
res = fh.getvalue().splitlines()
68+
assert res[0] == ""
69+
assert res[1] == "[global]"
70+
assert res[2] == "\tfirst = 1"
71+
assert res[3] == "\tsecond = 2"
72+
assert "[foo]" in res
73+
assert "\ta = Artichoke" in res
74+
assert "\tb = Broccoli" in res
75+
assert "[bar]" in res
76+
assert "\texample = yes" in res
77+
assert "\tproduction = no" in res

0 commit comments

Comments
 (0)