General cleanups of python code, hinted by pyflakes.
[Samba/kamenim.git] / source4 / scripting / python / samba / tests / samdb.py
blob73be13ca2a68e0d1b35ded1b66677df0f057e936
1 #!/usr/bin/python
3 # Unix SMB/CIFS implementation. Tests for SamDB
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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.
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/>.
19 from samba.auth import system_session
20 import os
21 from samba.provision import setup_samdb, guess_names, make_smbconf, find_setup_dir
22 from samba.tests import TestCaseInTempDir
23 from samba.dcerpc import security
24 import uuid
25 from samba import param
28 class SamDBTestCase(TestCaseInTempDir):
29 """Base-class for tests with a Sam Database.
31 This is used by the Samba SamDB-tests, but e.g. also by the OpenChange
32 provisioning tests (which need a Sam).
33 """
35 def setup_path(self, relpath):
36 return os.path.join(find_setup_dir(), relpath)
38 def setUp(self):
39 super(SamDBTestCase, self).setUp()
40 invocationid = str(uuid.uuid4())
41 domaindn = "DC=COM,DC=EXAMPLE"
42 self.domaindn = domaindn
43 configdn = "CN=Configuration," + domaindn
44 schemadn = "CN=Schema," + configdn
45 domainguid = str(uuid.uuid4())
46 policyguid = str(uuid.uuid4())
47 domainsid = security.random_sid()
48 path = os.path.join(self.tempdir, "samdb.ldb")
49 session_info = system_session()
51 hostname="foo"
52 domain="EXAMPLE"
53 dnsdomain="example.com"
54 serverrole="domain controller"
56 smbconf = os.path.join(self.tempdir, "smb.conf")
57 make_smbconf(smbconf, self.setup_path, hostname, domain, dnsdomain,
58 serverrole, self.tempdir)
60 self.lp = param.LoadParm()
61 self.lp.load(smbconf)
63 names = guess_names(lp=self.lp, hostname=hostname,
64 domain=domain, dnsdomain=dnsdomain,
65 serverrole=serverrole,
66 domaindn=self.domaindn, configdn=configdn,
67 schemadn=schemadn)
69 paths = provision_paths_from_lp(self.lp, names.dnsdomain)
71 provision_backend = ProvisionBackend("ldb", backend_type,
72 paths=paths, setup_path=self.setup_path,
73 lp=self.lp, credentials=None,
74 names=names,
75 message=message, hostname=hostname,
76 root=root, schema=schema,
77 domainsid=domainsid)
79 self.samdb = setup_samdb(path, self.setup_path, session_info, provision_backend,
80 self.lp, names,
81 lambda x: None, domainsid,
82 domainguid,
83 policyguid, False, "secret",
84 "secret", "secret", invocationid,
85 "secret", "domain controller")
87 def tearDown(self):
88 for f in ['schema.ldb', 'configuration.ldb',
89 'users.ldb', 'samdb.ldb', 'smb.conf']:
90 os.remove(os.path.join(self.tempdir, f))
91 super(SamDBTestCase, self).tearDown()
94 # disable this test till andrew works it out ...
95 class SamDBTests(SamDBTestCase):
96 """Tests for the SamDB implementation."""
98 print "samdb add_foreign disabled for now"
99 # def test_add_foreign(self):