1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

selftest: Move self.assertRaisesLdbError() to samba.tests.TestCase

This is easier to reason with regarding which cases should work
and which cases should fail, avoiding issues where more success
than expected would be OK because a self.fail() was missed in a
try: block.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Andrew Bartlett
2021-09-13 21:48:13 +12:00
committed by Jeremy Allison
parent fc69206f8b
commit 298515cac2
3 changed files with 25 additions and 46 deletions

View File

@ -200,31 +200,6 @@ class SubtreeRenameTests(samba.tests.TestCase):
attrs=['objectGUID'])
return str(misc.GUID(res[0]['objectGUID'][0]))
def assertRaisesLdbError(self, errcode, message, f, *args, **kwargs):
"""Assert a function raises a particular LdbError."""
try:
f(*args, **kwargs)
except ldb.LdbError as e:
(num, msg) = e.args
if num != errcode:
lut = {v: k for k, v in vars(ldb).items()
if k.startswith('ERR_') and isinstance(v, int)}
self.fail("%s, expected "
"LdbError %s, (%d) "
"got %s (%d) "
"%s" % (message,
lut.get(errcode), errcode,
lut.get(num), num,
msg))
else:
lut = {v: k for k, v in vars(ldb).items()
if k.startswith('ERR_') and isinstance(v, int)}
self.fail("%s, expected "
"LdbError %s, (%d) "
"but we got success" % (message,
lut.get(errcode),
errcode))
def test_la_move_ou_tree(self):
tag = 'move_tree'