tests: Improve tests of samba.registry Python module
authorLumir Balhar <lbalhar@redhat.com>
Wed, 11 Oct 2017 11:05:01 +0000 (13:05 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 18 Oct 2017 08:20:26 +0000 (10:20 +0200)
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
python/samba/tests/registry.py
selftest/tests.py

index 8016a0bb6860627e8e929bb692488fb4d7d0be5b..1a8a1266b8231d7986386539a7f6fc3a6ca2ba58 100644 (file)
@@ -20,6 +20,9 @@
 import os
 from samba import registry
 import samba.tests
+from samba import WERRORError
+from subprocess import Popen, PIPE
+
 
 class HelperTests(samba.tests.TestCase):
 
@@ -31,7 +34,6 @@ class HelperTests(samba.tests.TestCase):
         self.assertEquals("REG_DWORD", registry.str_regtype(4))
 
 
-
 class HiveTests(samba.tests.TestCaseInTempDir):
 
     def setUp(self):
@@ -47,14 +49,27 @@ class HiveTests(samba.tests.TestCaseInTempDir):
     def test_ldb_new(self):
         self.assertTrue(self.hive is not None)
 
-    #def test_flush(self):
-    #    self.hive.flush()
+    def test_set_value(self):
+        self.assertIsNone(self.hive.set_value('foo1', 1, 'bar1'))
+
+    def test_flush(self):
+        self.assertIsNone(self.hive.set_value('foo2', 1, 'bar2'))
+        self.assertIsNone(self.hive.flush())
+
+        proc = Popen(['bin/tdbdump', self.hive_path], stdout=PIPE, stderr=PIPE)
+        tdb_dump, err = proc.communicate()
+        self.assertTrue(b'DN=VALUE=FOO2,HIVE=NONE' in tdb_dump)
+
+    def test_del_value(self):
+        self.assertIsNone(self.hive.set_value('foo3', 1, 'bar3'))
+        self.assertIsNone(self.hive.del_value('foo3'))
 
-    #def test_del_value(self):
-    #    self.hive.del_value("FOO")
+    def test_del_nonexisting_value(self):
+        self.assertRaises(WERRORError, self.hive.del_value, 'foo4')
 
 
 class RegistryTests(samba.tests.TestCase):
 
     def test_new(self):
         self.registry = registry.Registry()
+        self.assertIsNotNone(self.registry)
index 9d1d9d3908b271b1453642f3b6821c243c507ebb..3e3ef84a5ecabcfaa86e0e717777fbd42d74ac38 100644 (file)
@@ -55,7 +55,7 @@ else:
 planpythontestsuite("none", "samba.tests.blackbox.ndrdump")
 planpythontestsuite("none", "api", name="ldb.python", extra_path=['lib/ldb/tests/python'])
 planpythontestsuite("none", "samba.tests.credentials", py3_compatible=True)
-planpythontestsuite("none", "samba.tests.registry")
+planpythontestsuite("none", "samba.tests.registry", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.auth", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.get_opt", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.security", py3_compatible=True)