s4-python: Remove env from non-executable test scripts.
[Samba/vl.git] / source4 / scripting / python / samba / tests / hostconfig.py
blob8f42a2b6529111fd56e29a731c787aea2e9c6539
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(["bla"], list(self._get_shares({"global":{}, "bla":{}})))
62 def test_len(self):
63 shares = self._get_shares({"global": {}})
64 self.assertEquals(0, len(shares))
66 def test_getitem_nonexistant(self):
67 shares = self._get_shares({"global": {}})
68 self.assertRaises(KeyError, shares.__getitem__, "bla")
70 def test_getitem_global(self):
71 shares = self._get_shares({"global": {}})
72 self.assertRaises(KeyError, shares.__getitem__, "global")