]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python/samba/tests: add test cases for s3/registry init funcs
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 23 Apr 2022 18:42:44 +0000 (14:42 -0400)
committerJeremy Allison <jra@samba.org>
Fri, 6 May 2022 17:16:30 +0000 (17:16 +0000)
A previous change added smbconf initialization functions that allow
access to the registry back-end. Add some simple tests cases that
exercise these new functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/smbconf.py

index 41d9889cf02502ef23b3d1286c91043663c09e96..8b0872cb3a84a61829beba54b89b09305e31009f 100644 (file)
 Tests for samba.smbconf module
 """
 
+from samba.samba3 import param as s3param
 import samba.tests
 
 
 class SMBConfTests(samba.tests.TestCase):
     _smbconf = None
+    _s3smbconf = None
 
     @property
     def smbconf(self):
@@ -39,10 +41,30 @@ class SMBConfTests(samba.tests.TestCase):
         self._smbconf = samba.smbconf
         return self._smbconf
 
+    @property
+    def s3smbconf(self):
+        if self._s3smbconf is not None:
+            return self._s3smbconf
+
+        import samba.samba3.smbconf
+
+        self._s3smbconf = samba.samba3.smbconf
+        return self._s3smbconf
+
     @property
     def example_conf_default(self):
         return "./testdata/samba3/smb.conf"
 
+    def setUp(self):
+        super().setUp()
+        # fetch the configuration in the same style as other test suites
+        self.lp_ctx = samba.tests.env_loadparm()
+        # apply the configuration to the samba3 configuration
+        # (because there are two... and they're independent!)
+        # this is needed to make use of the registry
+        s3_lp = s3param.get_context()
+        s3_lp.load(self.lp_ctx.configfile)
+
     def test_uninitalized_smbconf(self):
         sconf = self.smbconf.SMBConf()
         self.assertRaises(RuntimeError, sconf.requires_messaging)
@@ -95,6 +117,18 @@ class SMBConfTests(samba.tests.TestCase):
             services[1], ("cd1", [("path", "/mnt/cd1"), ("public", "yes")])
         )
 
+    def test_init_reg(self):
+        sconf = self.s3smbconf.init_reg(None)
+        self.assertTrue(sconf.is_writeable())
+
+    def test_init_str_reg(self):
+        sconf = self.s3smbconf.init("registry:")
+        self.assertTrue(sconf.is_writeable())
+
+    def test_init_str_file(self):
+        sconf = self.s3smbconf.init(f"file:{self.example_conf_default}")
+        self.assertFalse(sconf.is_writeable())
+
 
 if __name__ == "__main__":
     import unittest