summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Mulligan <jmulligan@redhat.com>2022-06-06 15:55:22 -0400
committerGünther Deschner <gd@samba.org>2022-06-08 13:13:10 +0000
commit1b6d675feb54d32224047ea59598c04a7a287038 (patch)
tree6544216923083b52111a2e6ff82d3c6b65684806 /python
parentfdc98ff5560903d64b10980d66826e8c50ef204a (diff)
downloadsamba-1b6d675feb54d32224047ea59598c04a7a287038.tar.gz
lib/smbconf: expose smbconf error codes to python wrapper
The smbconf library defines an enum of error codes that can be returned from the C calls. The error codes were getting stored in the python SMBConfError type but it was not easy to access or obvious what the integer code represented. This change makes it easier to get the returned error code: via a `error_code` attribute on the exception value. It also exposes the integer constants to the module. Simple tests for a few of the more obvious error codes check that this new error handling correctly exposes the error code values. Signed-off-by: John Mulligan <jmulligan@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Wed Jun 8 13:13:10 UTC 2022 on sn-devel-184
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/smbconf.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/python/samba/tests/smbconf.py b/python/samba/tests/smbconf.py
index e023e2ad59b..1f432a34608 100644
--- a/python/samba/tests/smbconf.py
+++ b/python/samba/tests/smbconf.py
@@ -324,6 +324,27 @@ class SMBConfTests(samba.tests.TestCase):
names = sconf.share_names()
self.assertEqual(names, ["hello", "goodnight"])
+ def test_error_badfile(self):
+ with self.assertRaises(self.smbconf.SMBConfError) as raised:
+ self.smbconf.init_txt("/foo/bar/baz/_I-dont/.exist/-ok-")
+ self.assertEqual(
+ self.smbconf.SBC_ERR_BADFILE, raised.exception.error_code)
+
+ def test_error_not_supported(self):
+ sconf = self.smbconf.init_txt(self.example_conf_default)
+ with self.assertRaises(self.smbconf.SMBConfError) as raised:
+ sconf.set_global_parameter("client min protocol", "NT1")
+ self.assertEqual(
+ self.smbconf.SBC_ERR_NOT_SUPPORTED, raised.exception.error_code)
+
+ def test_error_no_such_service(self):
+ sconf = self.smbconf.init_txt(self.example_conf_default)
+ with self.assertRaises(self.smbconf.SMBConfError) as raised:
+ sconf.get_share("zilch"),
+ self.assertEqual(
+ self.smbconf.SBC_ERR_NO_SUCH_SERVICE, raised.exception.error_code)
+
+
if __name__ == "__main__":
import unittest