linked_attribute tests: helper assert function for expected LdbError
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 24 Oct 2017 22:57:50 +0000 (11:57 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 25 Oct 2017 23:32:14 +0000 (01:32 +0200)
commit1e62bbaeac8f3ea44b7b2091d0d1c7ebe0d5e6ff
treee8a79ab8631ea450c38d6e8b57f7b5d4ac7589ea
parent0f0acb00ea853480565a592343ede99c140e7077
linked_attribute tests: helper assert function for expected LdbError

The logic involved in asserting that a function raises an LdbError with
a particular error value has shown itself to be too complicated for me
to repeat too often.

To test this function, you would want a put a test in a bit like this:

    def test_assertRaisesLdbError(self):
        for i in [1, 2, ldb.ERR_ENTRY_ALREADY_EXISTS, 999]:
            def f(*args, **kwargs):
                raise ldb.LdbError(i, 'msg %s' % i)
            self.assertRaisesLdbError(i, 'a message', f, 'la la', la='la')

            def f2(*args, **kwargs):
                raise ldb.LdbError(i + 1, 'msg %s' % i)
            def f3(*args, **kwargs):
                pass
            for f in (f2, f3):
                try:
                    self.assertRaisesLdbError(i, 'a message', f, 'la la', la='la')
                except AssertionError as e:
                    print i, e, f
                    pass
                else:
                    print i, f
                    self.fail('assertRaisesLdbError() failed to fail!')

..but a self-testing test-tester is getting a too meta to run in every
autobuild.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/tests/python/linked_attributes.py