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
):
29 def __getitem__(self
, name
):
30 return self
.data
[name
]
33 class MockLoadParm(object):
35 def __init__(self
, data
):
38 def __getitem__(self
, name
):
39 return MockService(self
.data
[name
])
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
))
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":{}})))
63 shares
= self
._get
_shares
({"global": {}})
64 self
.assertEquals(0, len(shares
))
66 def test_getitem_nonexistent(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")