Skip to content

Commit 07f4412

Browse files
committed
Sample test for previous commit
1 parent f754e35 commit 07f4412

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

Tests/t_cext.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -381,30 +381,36 @@ def test_compare(self):
381381
self.assertEqual(type(m), type(0))
382382
result, pmsg, msgid, ctrls = l.result4(m, _ldap.MSG_ALL, self.timeout)
383383
self.assertEqual(result, _ldap.RES_ADD)
384+
384385
# try a false compare
385386
m = l.compare_ext(dn, "userPassword", "bad_string")
386-
try:
387+
with self.assertRaises(_ldap.COMPARE_FALSE) as e:
387388
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
388-
except _ldap.COMPARE_FALSE:
389-
pass
390-
else:
391-
self.fail("expected COMPARE_FALSE, got %r" % r)
389+
390+
self.assertEqual(e.exception.args[0]['msgid'], m)
391+
self.assertEqual(e.exception.args[0]['msgtype'], _ldap.RES_COMPARE)
392+
self.assertEqual(e.exception.args[0]['result'], 5)
393+
self.assertFalse(e.exception.args[0]['ctrls'])
394+
392395
# try a true compare
393396
m = l.compare_ext(dn, "userPassword", "the_password")
394-
try:
397+
with self.assertRaises(_ldap.COMPARE_TRUE) as e:
395398
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
396-
except _ldap.COMPARE_TRUE:
397-
pass
398-
else:
399-
self.fail("expected COMPARE_TRUE, got %r" % r)
399+
400+
self.assertEqual(e.exception.args[0]['msgid'], m)
401+
self.assertEqual(e.exception.args[0]['msgtype'], _ldap.RES_COMPARE)
402+
self.assertEqual(e.exception.args[0]['result'], 6)
403+
self.assertFalse(e.exception.args[0]['ctrls'])
404+
400405
# try a compare on bad attribute
401406
m = l.compare_ext(dn, "badAttribute", "ignoreme")
402-
try:
407+
with self.assertRaises(_ldap.error) as e:
403408
r = l.result4(m, _ldap.MSG_ALL, self.timeout)
404-
except _ldap.error:
405-
pass
406-
else:
407-
self.fail("expected LDAPError, got %r" % r)
409+
410+
self.assertEqual(e.exception.args[0]['msgid'], m)
411+
self.assertEqual(e.exception.args[0]['msgtype'], _ldap.RES_COMPARE)
412+
self.assertEqual(e.exception.args[0]['result'], 17)
413+
self.assertFalse(e.exception.args[0]['ctrls'])
408414

409415
def test_delete_no_such_object(self):
410416
"""

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