Move python modules from source4/scripting/python/ to python/.
[nivanova/samba-autobuild/.git] / python / samba / tests / hostconfig.py
1 # Unix SMB/CIFS implementation. Tests for shares
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
3 #
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.
8 #
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.
13 #
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/>.
16 #
17
18 """Tests for samba.hostconfig."""
19
20 from samba.hostconfig import SharesContainer
21 from samba.tests import TestCase
22
23
24 class MockService(object):
25
26     def __init__(self, data):
27         self.data = data
28
29     def __getitem__(self, name):
30         return self.data[name]
31
32
33 class MockLoadParm(object):
34
35     def __init__(self, data):
36         self.data = data
37
38     def __getitem__(self, name):
39         return MockService(self.data[name])
40
41     def __len__(self):
42         return len(self.data)
43
44     def services(self):
45         return self.data.keys()
46
47
48 class ShareTests(TestCase):
49
50     def _get_shares(self, conf):
51         return SharesContainer(MockLoadParm(conf))
52
53     def test_len_no_global(self):
54         shares = self._get_shares({})
55         self.assertEquals(0, len(shares))
56
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":{}})))
63
64     def test_len(self):
65         shares = self._get_shares({"global": {}})
66         self.assertEquals(0, len(shares))
67
68     def test_getitem_nonexistent(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")