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/>.
19 from samba
.shares
import SharesContainer
20 from unittest
import TestCase
23 class MockService(object):
25 def __init__(self
, data
):
28 def __getitem__(self
, name
):
29 return self
.data
[name
]
32 class MockLoadParm(object):
34 def __init__(self
, data
):
37 def __getitem__(self
, name
):
38 return MockService(self
.data
[name
])
40 def __contains__(self
, name
):
41 return name
in self
.data
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")