mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
fix test and exception handling in code
With python 2 it was possible to do exception[0][...] to recover details about an exception. It's no longer authorized with python 3. Now, we must do something like exception.args or exception.urls. fortunately this syntax also works with python 2. So we use it for both.
This commit is contained in:
parent
90ff69586b
commit
baa3430e63
@ -132,8 +132,8 @@ class Backend(ldapcherry.backend.Backend):
|
|||||||
".groupdn'",
|
".groupdn'",
|
||||||
)
|
)
|
||||||
elif et is ldap.OBJECT_CLASS_VIOLATION:
|
elif et is ldap.OBJECT_CLASS_VIOLATION:
|
||||||
info = e[0]['info']
|
info = e.args[0]['info']
|
||||||
desc = e[0]['desc']
|
desc = e.args[0]['desc']
|
||||||
self._logger(
|
self._logger(
|
||||||
severity=logging.ERROR,
|
severity=logging.ERROR,
|
||||||
msg="Configuration error, " + desc + ", " + info,
|
msg="Configuration error, " + desc + ", " + info,
|
||||||
@ -147,7 +147,7 @@ class Backend(ldapcherry.backend.Backend):
|
|||||||
self.backend_name,
|
self.backend_name,
|
||||||
)
|
)
|
||||||
elif et is ldap.ALREADY_EXISTS:
|
elif et is ldap.ALREADY_EXISTS:
|
||||||
desc = e[0]['desc']
|
desc = e.args[0]['desc']
|
||||||
self._logger(
|
self._logger(
|
||||||
severity=logging.ERROR,
|
severity=logging.ERROR,
|
||||||
msg="adding user failed, " + desc,
|
msg="adding user failed, " + desc,
|
||||||
|
@ -105,8 +105,8 @@ class TestError(object):
|
|||||||
try:
|
try:
|
||||||
ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
|
ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
|
||||||
except ldap.SERVER_DOWN as e:
|
except ldap.SERVER_DOWN as e:
|
||||||
assert e[0]['info'] == 'TLS: hostname does not match CN in peer certificate' or \
|
assert e.args[0]['info'] == 'TLS: hostname does not match CN in peer certificate' or \
|
||||||
e[0]['info'] == '(unknown error code)'
|
e.args[0]['info'] == '(unknown error code)'
|
||||||
else:
|
else:
|
||||||
raise AssertionError("expected an exception")
|
raise AssertionError("expected an exception")
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class TestError(object):
|
|||||||
app.login(u'jwatsoné', u'passwordwatsoné')
|
app.login(u'jwatsoné', u'passwordwatsoné')
|
||||||
except cherrypy.HTTPRedirect as e:
|
except cherrypy.HTTPRedirect as e:
|
||||||
expected = 'http://127.0.0.1:8080/'
|
expected = 'http://127.0.0.1:8080/'
|
||||||
assert e[0][0] == expected
|
assert e.urls[0] == expected
|
||||||
else:
|
else:
|
||||||
raise AssertionError("expected an exception")
|
raise AssertionError("expected an exception")
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ class TestError(object):
|
|||||||
app.login(u'jwatsoné', u'wrongPasswordé')
|
app.login(u'jwatsoné', u'wrongPasswordé')
|
||||||
except cherrypy.HTTPRedirect as e:
|
except cherrypy.HTTPRedirect as e:
|
||||||
expected = 'http://127.0.0.1:8080/signin'
|
expected = 'http://127.0.0.1:8080/signin'
|
||||||
assert e[0][0] == expected
|
assert e.urls[0] == expected
|
||||||
else:
|
else:
|
||||||
raise AssertionError("expected an exception")
|
raise AssertionError("expected an exception")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user