From baa3430e637589814267eb88dc0741eefe81f621 Mon Sep 17 00:00:00 2001 From: kakwa Date: Sat, 9 Feb 2019 17:12:39 +0100 Subject: [PATCH] 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. --- ldapcherry/backend/backendLdap.py | 6 +++--- tests/test_BackendLdap.py | 4 ++-- tests/test_LdapCherry.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ldapcherry/backend/backendLdap.py b/ldapcherry/backend/backendLdap.py index e60ae98..cceaa96 100644 --- a/ldapcherry/backend/backendLdap.py +++ b/ldapcherry/backend/backendLdap.py @@ -132,8 +132,8 @@ class Backend(ldapcherry.backend.Backend): ".groupdn'", ) elif et is ldap.OBJECT_CLASS_VIOLATION: - info = e[0]['info'] - desc = e[0]['desc'] + info = e.args[0]['info'] + desc = e.args[0]['desc'] self._logger( severity=logging.ERROR, msg="Configuration error, " + desc + ", " + info, @@ -147,7 +147,7 @@ class Backend(ldapcherry.backend.Backend): self.backend_name, ) elif et is ldap.ALREADY_EXISTS: - desc = e[0]['desc'] + desc = e.args[0]['desc'] self._logger( severity=logging.ERROR, msg="adding user failed, " + desc, diff --git a/tests/test_BackendLdap.py b/tests/test_BackendLdap.py index eefabef..3f80930 100644 --- a/tests/test_BackendLdap.py +++ b/tests/test_BackendLdap.py @@ -105,8 +105,8 @@ class TestError(object): try: ldapc.simple_bind_s(inv.binddn, inv.bindpassword) except ldap.SERVER_DOWN as e: - assert e[0]['info'] == 'TLS: hostname does not match CN in peer certificate' or \ - e[0]['info'] == '(unknown error code)' + assert e.args[0]['info'] == 'TLS: hostname does not match CN in peer certificate' or \ + e.args[0]['info'] == '(unknown error code)' else: raise AssertionError("expected an exception") diff --git a/tests/test_LdapCherry.py b/tests/test_LdapCherry.py index 54611f2..536f80d 100644 --- a/tests/test_LdapCherry.py +++ b/tests/test_LdapCherry.py @@ -185,7 +185,7 @@ class TestError(object): app.login(u'jwatsoné', u'passwordwatsoné') except cherrypy.HTTPRedirect as e: expected = 'http://127.0.0.1:8080/' - assert e[0][0] == expected + assert e.urls[0] == expected else: raise AssertionError("expected an exception") @@ -197,7 +197,7 @@ class TestError(object): app.login(u'jwatsoné', u'wrongPasswordé') except cherrypy.HTTPRedirect as e: expected = 'http://127.0.0.1:8080/signin' - assert e[0][0] == expected + assert e.urls[0] == expected else: raise AssertionError("expected an exception")