78ca6202b2c95d52cdbbd734e4c2fd60ec8c81ae
[rusty/samba.git] / source4 / scripting / python / samba / tests / hostconfig.py
1 #!/usr/bin/env python
2
3 # Unix SMB/CIFS implementation. Tests for shares
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
5 #   
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.
10 #   
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.
15 #   
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/>.
18 #
19
20 """Tests for samba.hostconfig."""
21
22 from samba.hostconfig import SharesContainer
23 from samba.tests import TestCase
24
25
26 class MockService(object):
27
28     def __init__(self, data):
29         self.data = data
30
31     def __getitem__(self, name):
32         return self.data[name]
33
34
35 class MockLoadParm(object):
36
37     def __init__(self, data):
38         self.data = data
39
40     def __getitem__(self, name):
41         return MockService(self.data[name])
42
43     def __len__(self):
44         return len(self.data)
45
46     def services(self):
47         return self.data.keys()
48
49
50 class ShareTests(TestCase):
51
52     def _get_shares(self, conf):
53         return SharesContainer(MockLoadParm(conf))
54
55     def test_len_no_global(self):
56         shares = self._get_shares({})
57         self.assertEquals(0, len(shares))
58
59     def test_iter(self):
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":{}})))
63
64     def test_len(self):
65         shares = self._get_shares({"global": {}})
66         self.assertEquals(0, len(shares))
67
68     def test_getitem_nonexistant(self):
69         shares = self._get_shares({"global": {}})
70         self.assertRaises(KeyError, shares.__getitem__, "bla")
71
72     def test_getitem_global(self):
73         shares = self._get_shares({"global": {}})
74         self.assertRaises(KeyError, shares.__getitem__, "global")