selftest: Add --tmpdir to 'samba-tool gpo create' test
[Samba/gebeck_regimport.git] / source4 / scripting / python / samba / tests / hostconfig.py
blob526dc0fe4e311e789fd65b0db9964a22c6e26f92
1 # Unix SMB/CIFS implementation. Tests for shares
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.hostconfig."""
20 from samba.hostconfig import SharesContainer
21 from samba.tests import TestCase
24 class MockService(object):
26 def __init__(self, data):
27 self.data = data
29 def __getitem__(self, name):
30 return self.data[name]
33 class MockLoadParm(object):
35 def __init__(self, data):
36 self.data = data
38 def __getitem__(self, name):
39 return MockService(self.data[name])
41 def __len__(self):
42 return len(self.data)
44 def services(self):
45 return self.data.keys()
48 class ShareTests(TestCase):
50 def _get_shares(self, conf):
51 return SharesContainer(MockLoadParm(conf))
53 def test_len_no_global(self):
54 shares = self._get_shares({})
55 self.assertEquals(0, len(shares))
57 def test_iter(self):
58 self.assertEquals([], list(self._get_shares({})))
59 self.assertEquals([], list(self._get_shares({"global":{}})))
60 self.assertEquals(
61 ["bla"],
62 list(self._get_shares({"global":{}, "bla":{}})))
64 def test_len(self):
65 shares = self._get_shares({"global": {}})
66 self.assertEquals(0, len(shares))
68 def test_getitem_nonexistent(self):
69 shares = self._get_shares({"global": {}})
70 self.assertRaises(KeyError, shares.__getitem__, "bla")
72 def test_getitem_global(self):
73 shares = self._get_shares({"global": {}})
74 self.assertRaises(KeyError, shares.__getitem__, "global")