3 # Unit tests for sites manipulation in samba
4 # Copyright (C) Matthieu Patou <mat@matws.net> 2011
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 sys.path.insert(0, "bin/python")
26 from samba.tests.subunitrun import TestProgram, SubunitOptions
28 import samba.getopt as options
29 from samba import sites
30 from samba.auth import system_session
31 from samba.samdb import SamDB
33 from samba.dcerpc import security
35 parser = optparse.OptionParser(__file__ + " [options] <host>")
36 sambaopts = options.SambaOptions(parser)
37 parser.add_option_group(sambaopts)
38 parser.add_option_group(options.VersionOptions(parser))
40 # use command line creds if available
41 credopts = options.CredentialsOptions(parser)
42 parser.add_option_group(credopts)
43 subunitopts = SubunitOptions(parser)
44 parser.add_option_group(subunitopts)
46 opts, args = parser.parse_args()
54 ldaphost = "ldap://%s" % host
58 lp = sambaopts.get_loadparm()
59 creds = credopts.get_credentials(lp)
65 class SitesBaseTests(samba.tests.TestCase):
68 super(SitesBaseTests, self).setUp()
69 self.ldb = SamDB(ldaphost, credentials=creds,
70 session_info=system_session(lp), lp=lp)
71 self.base_dn = self.ldb.domain_dn()
72 self.domain_sid = security.dom_sid(self.ldb.get_domain_sid())
73 self.configuration_dn = self.ldb.get_config_basedn().get_linearized()
75 def get_user_dn(self, name):
76 return "CN=%s,CN=Users,%s" % (name, self.base_dn)
80 class SimpleSitesTests(SitesBaseTests):
82 def test_create_and_delete(self):
83 """test creation and deletion of 1 site"""
85 self.ldb.transaction_start()
86 sites.create_site(self.ldb, self.ldb.get_config_basedn(),
88 self.ldb.transaction_commit()
90 self.assertRaises(sites.SiteAlreadyExistsException,
91 sites.create_site, self.ldb,
92 self.ldb.get_config_basedn(),
95 self.ldb.transaction_start()
96 sites.delete_site(self.ldb, self.ldb.get_config_basedn(),
98 self.ldb.transaction_commit()
100 self.assertRaises(sites.SiteNotFoundException,
101 sites.delete_site, self.ldb,
102 self.ldb.get_config_basedn(),
105 def test_delete_not_empty(self):
106 """test removal of 1 site with servers"""
108 self.assertRaises(sites.SiteServerNotEmptyException,
109 sites.delete_site, self.ldb,
110 self.ldb.get_config_basedn(),
111 "Default-First-Site-Name")
115 TestProgram(module=__name__, opts=subunitopts)