summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2011-11-02 13:31:40 +0100
committerMatthieu Patou <mat@matws.net>2011-11-02 13:37:18 +0100
commit37703892bd59637db129bf1342e34be83c77cebe (patch)
treeae8fd270f1ae2774fee4fb666b3ac82d49fd1870
parent66a34d86de6237272c7bc99176dbcfad856345f3 (diff)
downloadsamba-37703892bd59637db129bf1342e34be83c77cebe.tar.gz
samba-37703892bd59637db129bf1342e34be83c77cebe.tar.bz2
samba-37703892bd59637db129bf1342e34be83c77cebe.zip
s4-selftest: add unit tests for sites's function in python
-rw-r--r--source4/dsdb/tests/python/sites.py125
-rwxr-xr-xsource4/selftest/tests.py1
2 files changed, 126 insertions, 0 deletions
diff --git a/source4/dsdb/tests/python/sites.py b/source4/dsdb/tests/python/sites.py
new file mode 100644
index 0000000000..d3f5c5769f
--- /dev/null
+++ b/source4/dsdb/tests/python/sites.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+#
+# Unit tests for sites manipulation in samba
+# Copyright (C) Matthieu Patou <mat@matws.net> 2011
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import optparse
+import sys
+sys.path.insert(0, "bin/python")
+import samba
+samba.ensure_external_module("testtools", "testtools")
+samba.ensure_external_module("subunit", "subunit/python")
+
+import samba.getopt as options
+from samba import sites
+from samba.auth import system_session
+from samba.samdb import SamDB
+import samba.tests
+from samba.dcerpc import security
+from subunit.run import SubunitTestRunner
+import unittest
+
+parser = optparse.OptionParser("dirsync.py [options] <host>")
+sambaopts = options.SambaOptions(parser)
+parser.add_option_group(sambaopts)
+parser.add_option_group(options.VersionOptions(parser))
+
+# use command line creds if available
+credopts = options.CredentialsOptions(parser)
+parser.add_option_group(credopts)
+opts, args = parser.parse_args()
+
+if len(args) < 1:
+ parser.print_usage()
+ sys.exit(1)
+
+host = args[0]
+if not "://" in host:
+ ldaphost = "ldap://%s" % host
+ ldapshost = "ldaps://%s" % host
+else:
+ ldaphost = host
+ start = host.rindex("://")
+ host = host.lstrip(start+3)
+
+lp = sambaopts.get_loadparm()
+creds = credopts.get_credentials(lp)
+
+#
+# Tests start here
+#
+
+class SitesBaseTests(samba.tests.TestCase):
+
+ def setUp(self):
+ super(SitesBaseTests, self).setUp()
+ self.ldb_admin = ldb
+ self.base_dn = ldb.domain_dn()
+ self.domain_sid = security.dom_sid(ldb.get_domain_sid())
+ self.configuration_dn = self.ldb_admin.get_config_basedn().get_linearized()
+
+ def get_user_dn(self, name):
+ return "CN=%s,CN=Users,%s" % (name, self.base_dn)
+
+
+#tests on sites
+class SimpleSitesTests(SitesBaseTests):
+
+
+ def test_create(self):
+ """test creation of 1 site"""
+
+ self.ldb_admin.transaction_start()
+ ok = sites.create_site(self.ldb_admin, self.ldb_admin.get_config_basedn(),
+ "testsamba")
+ self.ldb_admin.transaction_commit()
+ self.assertTrue(ok)
+ ok = False
+ try:
+ ok = sites.create_site(self.ldb_admin, self.ldb_admin.get_config_basedn(),
+ "testsamba")
+ self.assertFalse(ok)
+ except:
+ self.assertFalse(ok)
+
+ def test_delete(self):
+ """test creation of 1 site"""
+
+ self.ldb_admin.transaction_start()
+ ok = sites.delete_site(self.ldb_admin, self.ldb_admin.get_config_basedn(),
+ "testsamba")
+ self.ldb_admin.transaction_commit()
+ self.assertTrue(ok)
+ ok = False
+ try:
+ ok = sites.delete_site(self.ldb_admin, self.ldb_admin.get_config_basedn(),
+ "testsamba")
+ self.assertFalse(ok)
+ except:
+ self.assertFalse(ok)
+
+
+ldb = SamDB(ldapshost, credentials=creds, session_info=system_session(lp), lp=lp)
+
+runner = SubunitTestRunner()
+rc = 0
+
+if not runner.run(unittest.makeSuite(SimpleSitesTests)).wasSuccessful():
+ rc = 1
+
+sys.exit(rc)
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index 6e61b7340c..ba1902057b 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -431,6 +431,7 @@ plantestsuite("samba4.sam.python(dc)", "dc", [python, os.path.join(samba4srcdir,
plansambapythontestsuite("samba4.schemaInfo.python(dc)", "dc", os.path.join(samba4srcdir, 'dsdb/tests/python'), 'dsdb_schema_info', extra_args=['-U"$DOMAIN/$DC_USERNAME%$DC_PASSWORD"'])
plantestsuite("samba4.urgent_replication.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/urgent_replication.py"), '$PREFIX_ABS/dc/private/sam.ldb'], allow_empty_output=True)
plantestsuite("samba4.ldap.dirsync.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/dirsync.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
+plantestsuite("samba4.ldap.sites.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/sites.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
for env in ["dc", "fl2000dc", "fl2003dc", "fl2008r2dc"]:
plantestsuite("samba4.ldap_schema.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap_schema.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
plantestsuite("samba4.ldap.possibleInferiors.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/samdb/ldb_modules/tests/possibleinferiors.py"), "ldap://$SERVER", '-U"$USERNAME%$PASSWORD"', "-W", "$DOMAIN"])