Move python modules from source4/scripting/python/ to python/.
[mdw/samba.git] / python / samba / tests / core.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
3 #
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.
8 #
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.
13 #
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/>.
16 #
17
18 """Samba Python tests."""
19
20 import ldb
21 import os
22 import samba
23 from samba.tests import TestCase, TestCaseInTempDir
24
25 class SubstituteVarTestCase(TestCase):
26
27     def test_empty(self):
28         self.assertEquals("", samba.substitute_var("", {}))
29
30     def test_nothing(self):
31         self.assertEquals("foo bar",
32                 samba.substitute_var("foo bar", {"bar": "bla"}))
33
34     def test_replace(self):
35         self.assertEquals("foo bla",
36                 samba.substitute_var("foo ${bar}", {"bar": "bla"}))
37
38     def test_broken(self):
39         self.assertEquals("foo ${bdkjfhsdkfh sdkfh ",
40             samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"}))
41
42     def test_unknown_var(self):
43         self.assertEquals("foo ${bla} gsff",
44                 samba.substitute_var("foo ${bla} gsff", {"bar": "bla"}))
45
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}")
50
51
52 class LdbExtensionTests(TestCaseInTempDir):
53
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)