URL: https://github.com/freeipa/freeipa/pull/440 Author: MartinBasti Title: #440: [Py3] fix various issues in tests related to BytesWarning Action: opened
PR body: """ """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/440/head:pr440 git checkout pr440
From 2196847478d8cb9b7a6f69db3b20b26360ffe7f1 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Thu, 2 Feb 2017 15:48:19 +0100 Subject: [PATCH 1/3] py3: DN: fix BytesWarning User repr() instead of str() for bytes, it has the same effect, but it is proper way how to print bytes https://fedorahosted.org/freeipa/ticket/4985 --- ipapython/dn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipapython/dn.py b/ipapython/dn.py index 2f7655d..4e8c22b 100644 --- a/ipapython/dn.py +++ b/ipapython/dn.py @@ -452,7 +452,7 @@ def _adjust_indices(start, end, length): def _normalize_ava_input(val): if six.PY3 and isinstance(val, bytes): - raise TypeError('expected str, got bytes: %s' % val) + raise TypeError('expected str, got bytes: %r' % val) elif not isinstance(val, six.string_types): val = val_encode(six.text_type(val)) elif six.PY2 and isinstance(val, unicode): From 3f5564741e3eb1927ee34f5c9834d41c6282142d Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Thu, 2 Feb 2017 16:51:21 +0100 Subject: [PATCH 2/3] py3: get_memberofindirect: fix ByteWarnings DN must be converted to bytes as other variables adn lists contain bytes https://fedorahosted.org/freeipa/ticket/4985 --- ipapython/ipaldap.py | 6 ++++-- ipaserver/plugins/baseldap.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 497b947..4de8a21 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -379,8 +379,10 @@ def _set_raw(self, name, value): name, value.__class__.__name__, value)) for (i, item) in enumerate(value): if not isinstance(item, bytes): - raise TypeError("%s[%d] value must be str, got %s object %r" % ( - name, i, item.__class__.__name__, item)) + raise TypeError( + "%s[%d] value must be bytes, got %s object %r" % ( + name, i, item.__class__.__name__, item) + ) name = self._add_attr_name(name) diff --git a/ipaserver/plugins/baseldap.py b/ipaserver/plugins/baseldap.py index e7bf43c..94c8547 100644 --- a/ipaserver/plugins/baseldap.py +++ b/ipaserver/plugins/baseldap.py @@ -722,7 +722,7 @@ def get_memberofindirect(self, entry): direct = set() indirect = set(entry.raw.get('memberof', [])) for group_entry in result: - dn = str(group_entry.dn) + dn = str(group_entry.dn).encode('utf-8') if dn in indirect: indirect.remove(dn) direct.add(dn) From 0479dfa6030943caceef011d990fc313f8b4b8b6 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Tue, 7 Feb 2017 13:37:56 +0100 Subject: [PATCH 3/3] py3: test_ipaserver: fix BytesWarnings https://fedorahosted.org/freeipa/ticket/6633 --- ipatests/test_ipaserver/test_rpcserver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ipatests/test_ipaserver/test_rpcserver.py b/ipatests/test_ipaserver/test_rpcserver.py index 6cc2472..7ee94d3 100644 --- a/ipatests/test_ipaserver/test_rpcserver.py +++ b/ipatests/test_ipaserver/test_rpcserver.py @@ -62,7 +62,7 @@ def test_not_found(): url = '/ipa/foo/stuff' assert_equal( f.not_found(None, s, url, None), - [t % dict(url='/ipa/foo/stuff')] + [(t % dict(url='/ipa/foo/stuff')).encode('utf-8')] ) assert s.status == '404 Not Found' assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] @@ -72,7 +72,9 @@ def test_not_found(): url =' ' + '<script>do_bad_stuff();</script>' assert_equal( f.not_found(None, s, url, None), - [t % dict(url='&nbsp;<script>do_bad_stuff();</script>')] + [(t % dict( + url='&nbsp;<script>do_bad_stuff();</script>') + ).encode('utf-8')] ) assert s.status == '404 Not Found' assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] @@ -86,7 +88,7 @@ def test_bad_request(): assert_equal( f.bad_request(None, s, 'illegal request'), - [t % dict(message='illegal request')] + [(t % dict(message='illegal request')).encode('utf-8')] ) assert s.status == '400 Bad Request' assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] @@ -100,7 +102,7 @@ def test_internal_error(): assert_equal( f.internal_error(None, s, 'request failed'), - [t % dict(message='request failed')] + [(t % dict(message='request failed')).encode('utf-8')] ) assert s.status == '500 Internal Server Error' assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] @@ -114,7 +116,7 @@ def test_unauthorized_error(): assert_equal( f.unauthorized(None, s, 'unauthorized', 'password-expired'), - [t % dict(message='unauthorized')] + [(t % dict(message='unauthorized')).encode('utf-8')] ) assert s.status == '401 Unauthorized' assert s.headers == [('Content-Type', 'text/html; charset=utf-8'),
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code