Move python modules from source4/scripting/python/ to python/.
[Samba.git] / python / samba / tests / core.py
blob8206e68d4fb8b3a8e51362090dc5c839c0fa1436
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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 """Samba Python tests."""
20 import ldb
21 import os
22 import samba
23 from samba.tests import TestCase, TestCaseInTempDir
25 class SubstituteVarTestCase(TestCase):
27 def test_empty(self):
28 self.assertEquals("", samba.substitute_var("", {}))
30 def test_nothing(self):
31 self.assertEquals("foo bar",
32 samba.substitute_var("foo bar", {"bar": "bla"}))
34 def test_replace(self):
35 self.assertEquals("foo bla",
36 samba.substitute_var("foo ${bar}", {"bar": "bla"}))
38 def test_broken(self):
39 self.assertEquals("foo ${bdkjfhsdkfh sdkfh ",
40 samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"}))
42 def test_unknown_var(self):
43 self.assertEquals("foo ${bla} gsff",
44 samba.substitute_var("foo ${bla} gsff", {"bar": "bla"}))
46 def test_check_all_substituted(self):
47 samba.check_all_substituted("nothing to see here")
48 self.assertRaises(Exception, samba.check_all_substituted,
49 "Not subsituted: ${FOOBAR}")
52 class LdbExtensionTests(TestCaseInTempDir):
54 def test_searchone(self):
55 path = self.tempdir + "/searchone.ldb"
56 l = samba.Ldb(path)
57 try:
58 l.add({"dn": "foo=dc", "bar": "bla"})
59 self.assertEquals("bla",
60 l.searchone(basedn=ldb.Dn(l, "foo=dc"), attribute="bar"))
61 finally:
62 del l
63 os.unlink(path)