Skip to content

Commit c8427c0

Browse files
authored
Tests and documentation for msgid for exceptions raised from result4()
python-ldap#262
2 parents a8fd053 + e2bcd62 commit c8427c0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Doc/reference/ldap.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ The module defines the following exceptions:
329329
is set to a truncated form of the name provided or alias dereferenced
330330
for the lowest entry (object or alias) that was matched.
331331

332+
The field :py:const:`msgid` is set in the dictionary where the
333+
exception can be associated with an asynchronous request.
334+
This can be used in asynchronous code where :py:meth:`result()` raises the
335+
result of an operation as an exception. For example, this is the case for
336+
:py:meth:`compare()`, always raises the boolean result as an exception
337+
(:py:exc:`COMPARE_TRUE` or :py:exc:`COMPARE_FALSE`).
338+
332339
Most exceptions from protocol results also carry the :py:attr:`errnum`
333340
attribute.
334341

Tests/t_ldapobject.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ def test_compare_s_invalidattr(self):
673673
with self.assertRaises(ldap.UNDEFINED_TYPE):
674674
result = l.compare_s('cn=Foo1,%s' % base, 'invalidattr', b'invalid')
675675

676+
def test_compare_true_exception_contains_message_id(self):
677+
base = self.server.suffix
678+
l = self._ldap_conn
679+
msgid = l.compare('cn=Foo1,%s' % base, 'cn', b'Foo1')
680+
with self.assertRaises(ldap.COMPARE_TRUE) as cm:
681+
l.result()
682+
self.assertEqual(cm.exception.args[0]["msgid"], msgid)
683+
684+
def test_async_search_no_such_object_exception_contains_message_id(self):
685+
msgid = self._ldap_conn.search("CN=XXX", ldap.SCOPE_SUBTREE)
686+
with self.assertRaises(ldap.NO_SUCH_OBJECT) as cm:
687+
self._ldap_conn.result()
688+
self.assertEqual(cm.exception.args[0]["msgid"], msgid)
689+
676690

677691
class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):
678692
"""

0 commit comments

Comments
 (0)