Skip to content

Commit 9b6aabb

Browse files
krisztian-kovacsencukou
authored andcommitted
Tests and documentation for msgid for exceptions raised from result4()
1 parent a8fd053 commit 9b6aabb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Doc/reference/ldap.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ 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+
For use in asynchronous operations an optional field :py:const:`msg_id` is
333+
also set in the dictionary in cases where the exception can be associated
334+
with a request. This can be used in asynchronous code where
335+
:py:meth:`result()` returns an exception that is effectively the result of a
336+
previously started asynchronous operation. For example, this is the case for
337+
asynchronous (:py:meth:`compare()`), where the boolean result is always
338+
raised as an exception (:py:exc:`COMPARE_TRUE` or :py:exc:`COMPARE_FALSE`).
339+
332340
Most exceptions from protocol results also carry the :py:attr:`errnum`
333341
attribute.
334342

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy