3 # Unix SMB/CIFS implementation. Tests for shares
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for samba.hostconfig."""
22 from samba.hostconfig import SharesContainer
23 from samba.tests import TestCase
26 class MockService(object):
28 def __init__(self, data):
31 def __getitem__(self, name):
32 return self.data[name]
35 class MockLoadParm(object):
37 def __init__(self, data):
40 def __getitem__(self, name):
41 return MockService(self.data[name])
47 return self.data.keys()
50 class ShareTests(TestCase):
52 def _get_shares(self, conf):
53 return SharesContainer(MockLoadParm(conf))
55 def test_len_no_global(self):
56 shares = self._get_shares({})
57 self.assertEquals(0, len(shares))
60 self.assertEquals([], list(self._get_shares({})))
61 self.assertEquals([], list(self._get_shares({"global":{}})))
62 self.assertEquals(["bla"], list(self._get_shares({"global":{}, "bla":{}})))
65 shares = self._get_shares({"global": {}})
66 self.assertEquals(0, len(shares))
68 def test_getitem_nonexistant(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")