python selftest: split samba3 test into separate tests
authorNoel Power <noel.power@suse.com>
Wed, 21 Mar 2018 18:24:18 +0000 (18:24 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 5 Apr 2018 06:59:08 +0000 (08:59 +0200)
This patch splits the tests contained in samba3.py into separate
tests s3idmapdb.py, s3param.py, s3passdb.py, s3registry.py, s3windb.py
This allows test of associated python c-modules to be done independently.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/s3idmapdb.py [new file with mode: 0644]
python/samba/tests/s3param.py [new file with mode: 0644]
python/samba/tests/s3passdb.py [moved from python/samba/tests/samba3.py with 69% similarity]
python/samba/tests/s3registry.py [new file with mode: 0644]
python/samba/tests/s3windb.py [new file with mode: 0644]
selftest/tests.py

diff --git a/python/samba/tests/s3idmapdb.py b/python/samba/tests/s3idmapdb.py
new file mode 100644 (file)
index 0000000..aa27840
--- /dev/null
@@ -0,0 +1,57 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+#
+# 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/>.
+#
+
+"""Tests for samba.samba3."""
+
+from samba.samba3 import IdmapDatabase
+from samba.tests import TestCase, TestCaseInTempDir
+from samba.dcerpc.security import dom_sid
+import os
+
+for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
+    DATADIR = os.path.join(os.path.dirname(__file__), p)
+    if os.path.exists(DATADIR):
+        break
+
+class IdmapDbTestCase(TestCase):
+
+    def setUp(self):
+        super(IdmapDbTestCase, self).setUp()
+        self.idmapdb = IdmapDatabase(os.path.join(DATADIR,
+            "winbindd_idmap"))
+
+    def test_user_hwm(self):
+        self.assertEquals(10000, self.idmapdb.get_user_hwm())
+
+    def test_group_hwm(self):
+        self.assertEquals(10002, self.idmapdb.get_group_hwm())
+
+    def test_uids(self):
+        self.assertEquals(1, len(list(self.idmapdb.uids())))
+
+    def test_gids(self):
+        self.assertEquals(3, len(list(self.idmapdb.gids())))
+
+    def test_get_user_sid(self):
+        self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534))
+
+    def test_get_group_sid(self):
+        self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001))
+
+    def tearDown(self):
+        self.idmapdb.close()
+        super(IdmapDbTestCase, self).tearDown()
diff --git a/python/samba/tests/s3param.py b/python/samba/tests/s3param.py
new file mode 100644 (file)
index 0000000..5d06191
--- /dev/null
@@ -0,0 +1,50 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+#
+# 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/>.
+#
+
+"""Tests for samba.samba3.param"""
+
+from samba.samba3 import param as s3param
+from samba.tests import TestCase, TestCaseInTempDir
+import os
+
+
+for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
+    DATADIR = os.path.join(os.path.dirname(__file__), p)
+    if os.path.exists(DATADIR):
+        break
+
+
+class ParamTestCase(TestCaseInTempDir):
+
+    def setUp(self):
+        super(ParamTestCase, self).setUp()
+        os.system("cp -r %s %s" % (DATADIR, self.tempdir))
+        datadir = os.path.join(self.tempdir, "samba3")
+
+        self.lp = s3param.get_context()
+        self.lp.load(os.path.join(datadir, "smb.conf"))
+
+    def tearDown(self):
+        self.lp = []
+        os.system("rm -rf %s" % os.path.join(self.tempdir, "samba3"))
+        super(ParamTestCase, self).tearDown()
+
+    def test_param(self):
+        self.assertEquals("BEDWYR", self.lp.get("netbios name"))
+        self.assertEquals("SAMBA", self.lp.get("workgroup"))
+        self.assertEquals("USER", self.lp.get("security"))
+        self.assertEquals("/mnt/cd1", self.lp.get("path", "cd1"))
similarity index 69%
rename from python/samba/tests/samba3.py
rename to python/samba/tests/s3passdb.py
index 126e133f4c1b196740d6f77c31dbb91d66fe1c45..2f6bc74e869a143c52a16622c18aa248e0480e45 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-"""Tests for samba.samba3."""
+"""Tests for samba.s3passdb"""
 
-from samba.samba3 import (
-    Registry,
-    WinsDatabase,
-    IdmapDatabase,
-    )
 from samba.samba3 import passdb
 from samba.samba3 import param as s3param
 from samba.tests import TestCase, TestCaseInTempDir
@@ -35,31 +30,6 @@ for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
         break
 
 
-class RegistryTestCase(TestCase):
-
-    def setUp(self):
-        super(RegistryTestCase, self).setUp()
-        self.registry = Registry(os.path.join(DATADIR, "registry"))
-
-    def tearDown(self):
-        self.registry.close()
-        super(RegistryTestCase, self).tearDown()
-
-    def test_length(self):
-        self.assertEquals(28, len(self.registry))
-
-    def test_keys(self):
-        self.assertTrue("HKLM" in self.registry.keys())
-
-    def test_subkeys(self):
-        self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM"))
-
-    def test_values(self):
-        self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'),
-                           'ErrorControl': (4L, '\x01\x00\x00\x00')},
-                           self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
-
-
 class PassdbTestCase(TestCaseInTempDir):
 
     def setUp(self):
@@ -82,11 +52,6 @@ class PassdbTestCase(TestCaseInTempDir):
         os.system("rm -rf %s" % os.path.join(self.tempdir, "samba3"))
         super(PassdbTestCase, self).tearDown()
 
-    def test_param(self):
-        self.assertEquals("BEDWYR", self.lp.get("netbios name"))
-        self.assertEquals("SAMBA", self.lp.get("workgroup"))
-        self.assertEquals("USER", self.lp.get("security"))
-
     def test_policy(self):
         policy = self.pdb.get_account_policy()
         self.assertEquals(0, policy['bad lockout attempt'])
@@ -171,50 +136,3 @@ class PassdbTestCase(TestCaseInTempDir):
         aliaslist = self.pdb.search_aliases()
         self.assertEquals(1, len(aliaslist))
         self.assertEquals("Jelmers NT Group", aliaslist[0]['account_name'])
-
-
-class WinsDatabaseTestCase(TestCase):
-
-    def setUp(self):
-        super(WinsDatabaseTestCase, self).setUp()
-        self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
-
-    def test_length(self):
-        self.assertEquals(22, len(self.winsdb))
-
-    def test_first_entry(self):
-        self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"])
-
-    def tearDown(self):
-        self.winsdb.close()
-        super(WinsDatabaseTestCase, self).tearDown()
-
-
-class IdmapDbTestCase(TestCase):
-
-    def setUp(self):
-        super(IdmapDbTestCase, self).setUp()
-        self.idmapdb = IdmapDatabase(os.path.join(DATADIR,
-            "winbindd_idmap"))
-
-    def test_user_hwm(self):
-        self.assertEquals(10000, self.idmapdb.get_user_hwm())
-
-    def test_group_hwm(self):
-        self.assertEquals(10002, self.idmapdb.get_group_hwm())
-
-    def test_uids(self):
-        self.assertEquals(1, len(list(self.idmapdb.uids())))
-
-    def test_gids(self):
-        self.assertEquals(3, len(list(self.idmapdb.gids())))
-
-    def test_get_user_sid(self):
-        self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534))
-
-    def test_get_group_sid(self):
-        self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001))
-
-    def tearDown(self):
-        self.idmapdb.close()
-        super(IdmapDbTestCase, self).tearDown()
diff --git a/python/samba/tests/s3registry.py b/python/samba/tests/s3registry.py
new file mode 100644 (file)
index 0000000..43be412
--- /dev/null
@@ -0,0 +1,54 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+#
+# 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/>.
+#
+
+"""Tests for samba.samba3."""
+
+from samba.samba3 import Registry
+from samba.tests import TestCase, TestCaseInTempDir
+from samba.dcerpc.security import dom_sid
+import os
+
+
+for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
+    DATADIR = os.path.join(os.path.dirname(__file__), p)
+    if os.path.exists(DATADIR):
+        break
+
+
+class RegistryTestCase(TestCase):
+
+    def setUp(self):
+        super(RegistryTestCase, self).setUp()
+        self.registry = Registry(os.path.join(DATADIR, "registry"))
+
+    def tearDown(self):
+        self.registry.close()
+        super(RegistryTestCase, self).tearDown()
+
+    def test_length(self):
+        self.assertEquals(28, len(self.registry))
+
+    def test_keys(self):
+        self.assertTrue("HKLM" in self.registry.keys())
+
+    def test_subkeys(self):
+        self.assertEquals(["SOFTWARE", "SYSTEM"], self.registry.subkeys("HKLM"))
+
+    def test_values(self):
+        self.assertEquals({'DisplayName': (1L, 'E\x00v\x00e\x00n\x00t\x00 \x00L\x00o\x00g\x00\x00\x00'),
+                           'ErrorControl': (4L, '\x01\x00\x00\x00')},
+                           self.registry.values("HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/EVENTLOG"))
diff --git a/python/samba/tests/s3windb.py b/python/samba/tests/s3windb.py
new file mode 100644 (file)
index 0000000..6fc5b09
--- /dev/null
@@ -0,0 +1,45 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+#
+# 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/>.
+#
+
+"""Tests for samba.samba3."""
+
+from samba.samba3 import WinsDatabase
+from samba.tests import TestCase, TestCaseInTempDir
+import os
+
+
+for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]:
+    DATADIR = os.path.join(os.path.dirname(__file__), p)
+    if os.path.exists(DATADIR):
+        break
+
+
+class WinsDatabaseTestCase(TestCase):
+
+    def setUp(self):
+        super(WinsDatabaseTestCase, self).setUp()
+        self.winsdb = WinsDatabase(os.path.join(DATADIR, "wins.dat"))
+
+    def test_length(self):
+        self.assertEquals(22, len(self.winsdb))
+
+    def test_first_entry(self):
+        self.assertEqual((1124185120, ["192.168.1.5"], 0x64), self.winsdb["ADMINISTRATOR#03"])
+
+    def tearDown(self):
+        self.winsdb.close()
+        super(WinsDatabaseTestCase, self).tearDown()
index c18cfbc9f79cb30a49540eb7f0972d93af35d925..027a80e03f18ab90003899577f9a1ddadede92c0 100644 (file)
@@ -67,7 +67,6 @@ planpythontestsuite("none", "samba.tests.core", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.common")
 planpythontestsuite("none", "samba.tests.provision")
 planpythontestsuite("none", "samba.tests.password_quality")
-planpythontestsuite("none", "samba.tests.samba3")
 planpythontestsuite("none", "samba.tests.strings")
 planpythontestsuite("none", "samba.tests.netcmd")
 planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc")
@@ -76,6 +75,11 @@ planpythontestsuite("none", "samba.tests.dcerpc.string")
 planpythontestsuite("none", "samba.tests.hostconfig")
 planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.messaging",
                     py3_compatible=True)
+planpythontestsuite("none", "samba.tests.s3param")
+planpythontestsuite("none", "samba.tests.s3passdb")
+planpythontestsuite("none", "samba.tests.s3registry")
+planpythontestsuite("none", "samba.tests.s3windb")
+planpythontestsuite("none", "samba.tests.s3idmapdb")
 planpythontestsuite("none", "samba.tests.samba3sam")
 planpythontestsuite(
     "none", "wafsamba.tests.test_suite",