3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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/>.
20 """Samba Python tests."""
25 from samba import param
29 # Other modules import these two classes from here, for convenience:
30 from testtools.testcase import TestCase, TestSkipped
33 class LdbTestCase(TestCase):
34 """Trivial test case for running tests against a LDB."""
37 super(LdbTestCase, self).setUp()
38 self.filename = os.tempnam()
39 self.ldb = samba.Ldb(self.filename)
41 def set_modules(self, modules=[]):
42 """Change the modules for this Ldb."""
44 m.dn = ldb.Dn(self.ldb, "@MODULES")
45 m["@LIST"] = ",".join(modules)
47 self.ldb = samba.Ldb(self.filename)
50 class TestCaseInTempDir(TestCase):
53 super(TestCaseInTempDir, self).setUp()
54 self.tempdir = tempfile.mkdtemp()
57 super(TestCaseInTempDir, self).tearDown()
58 self.assertEquals([], os.listdir(self.tempdir))
59 os.rmdir(self.tempdir)
65 lp.load(os.environ["SMB_CONF_PATH"])
67 raise Exception("SMB_CONF_PATH not set")
70 cmdline_credentials = None
72 class RpcInterfaceTestCase(TestCase):
74 def get_loadparm(self):
77 def get_credentials(self):
78 return cmdline_credentials
81 class ValidNetbiosNameTests(TestCase):
84 self.assertTrue(samba.valid_netbios_name("FOO"))
86 def test_too_long(self):
87 self.assertFalse(samba.valid_netbios_name("FOO"*10))
89 def test_invalid_characters(self):
90 self.assertFalse(samba.valid_netbios_name("*BLA"))
93 class BlackboxTestCase(TestCase):
94 """Base test case for blackbox tests."""
96 def check_run(self, line):
97 bindir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../bin"))
98 parts = line.split(" ")
99 if os.path.exists(os.path.join(bindir, parts[0])):
100 parts[0] = os.path.join(bindir, parts[0])
101 line = " ".join(parts)
102 subprocess.check_call(line, shell=True)