• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/samba-3.5.8/source4/scripting/python/samba/tests/
1#!/usr/bin/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#
19from samba.shares import SharesContainer
20from unittest import TestCase
21
22
23class MockService(object):
24
25    def __init__(self, data):
26        self.data = data
27
28    def __getitem__(self, name):
29        return self.data[name]
30
31
32class MockLoadParm(object):
33
34    def __init__(self, data):
35        self.data = data
36
37    def __getitem__(self, name):
38        return MockService(self.data[name])
39
40    def __contains__(self, name):
41        return name in self.data
42
43    def __len__(self):
44        return len(self.data)
45
46    def services(self):
47        return self.data.keys()
48
49
50class 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")
75