s4:python LDB __init__.py - remove completely unused "erase_partitions" call
[obnox/samba/samba-obnox.git] / source4 / scripting / python / samba / tests / provision.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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 #
19
20 import os
21 from samba.provision import setup_secretsdb, findnss
22 import samba.tests
23 from samba.tests import env_loadparm, TestCase
24
25 setup_dir = "setup"
26 def setup_path(file):
27     return os.path.join(setup_dir, file)
28
29
30 def create_dummy_secretsdb(path, lp=None):
31     """Create a dummy secrets database for use in tests.
32
33     :param path: Path to store the secrets db
34     :param lp: Optional loadparm context. A simple one will
35         be generated if not specified.
36     """
37     if lp is None:
38         lp = env_loadparm()
39     secrets_ldb = setup_secretsdb(path, setup_path, None, None, lp=lp)
40     secrets_ldb.transaction_commit()
41     return secrets_ldb
42
43
44 class ProvisionTestCase(samba.tests.TestCaseInTempDir):
45     """Some simple tests for individual functions in the provisioning code.
46     """
47
48     def test_setup_secretsdb(self):
49         path = os.path.join(self.tempdir, "secrets.ldb")
50         ldb = setup_secretsdb(path, setup_path, None, None, lp=env_loadparm())
51         try:
52             self.assertEquals("LSA Secrets",
53                  ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
54         finally:
55             del ldb
56             os.unlink(path)
57             
58
59 class FindNssTests(TestCase):
60     """Test findnss() function."""
61
62     def test_nothing(self):
63         def x(y):
64             raise KeyError
65         self.assertRaises(KeyError, findnss, x, [])
66
67     def test_first(self):
68         self.assertEquals("bla", findnss(lambda x: "bla", ["bla"]))
69
70     def test_skip_first(self):
71         def x(y):
72             if y != "bla":
73                 raise KeyError
74             return "ha"
75         self.assertEquals("ha", findnss(x, ["bloe", "bla"]))
76
77
78 class Disabled(object):
79
80     def test_setup_templatesdb(self):
81         raise NotImplementedError(self.test_setup_templatesdb)
82
83     def test_setup_registry(self):
84         raise NotImplementedError(self.test_setup_registry)
85
86     def test_setup_samdb_rootdse(self):
87         raise NotImplementedError(self.test_setup_samdb_rootdse)
88
89     def test_setup_samdb_partitions(self):
90         raise NotImplementedError(self.test_setup_samdb_partitions)
91
92     def test_create_phpldapadmin_config(self):
93         raise NotImplementedError(self.test_create_phpldapadmin_config)
94
95     def test_provision_dns(self):
96         raise NotImplementedError(self.test_provision_dns)
97
98     def test_provision_ldapbase(self):
99         raise NotImplementedError(self.test_provision_ldapbase)
100
101     def test_provision_guess(self):
102         raise NotImplementedError(self.test_provision_guess)
103
104     def test_join_domain(self):
105         raise NotImplementedError(self.test_join_domain)
106
107     def test_vampire(self):
108         raise NotImplementedError(self.test_vampire)
109
110