python: Provide way to iterate over available shares.
[Samba/ekacnet.git] / source4 / bin / python / samba / tests / shares.py
blob9130c36780125d85deb51220827dae4b1d8945cf
1 #!/usr/bin/python
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.
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):
26 self.data = data
28 def __getitem__(self, name):
29 return self.data[name]
32 class MockLoadParm(object):
34 def __init__(self, data):
35 self.data = data
37 def __getitem__(self, name):
38 return MockService(self.data[name])
40 def __contains__(self, name):
41 return name in self.data
43 def __len__(self):
44 return len(self.data)
46 def services(self):
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))
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":{}})))
64 def test_len(self):
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")