summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2015-08-16 19:00:00 +0200
committerChristian Heimes <cheimes@redhat.com>2015-08-17 21:14:11 +0200
commit724351e7e02d7d15b18d4262b778ebae72040afe (patch)
treed59479875b003a3e0924965842fb00ff92a9f0a3 /tests
parent3725265993960285315942ea5a0355165282dd7c (diff)
downloadpki-724351e7e02d7d15b18d4262b778ebae72040afe.tar.gz
pki-724351e7e02d7d15b18d4262b778ebae72040afe.tar.xz
pki-724351e7e02d7d15b18d4262b778ebae72040afe.zip
Fix encoding issue. On Python 3 requests requires bytes for json body.
Diffstat (limited to 'tests')
-rw-r--r--tests/python/test_pki.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/python/test_pki.py b/tests/python/test_pki.py
index d30a1cd84..606a89232 100644
--- a/tests/python/test_pki.py
+++ b/tests/python/test_pki.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Authors:
# Christian Heimes <cheimes@redhat.com>
#
@@ -30,6 +31,7 @@ class TestHTTPError(requests.exceptions.HTTPError):
super(TestHTTPError, self).__init__()
self.response = requests.Response()
self.response._content = body
+ self.response.encoding = 'utf-8'
class PKITests(unittest.TestCase):
def test_handle_exceptions(self):
@@ -45,7 +47,7 @@ class PKITests(unittest.TestCase):
'Attributes': {
'Attribute': [],
},
- })
+ }).encode('utf-8')
with self.assertRaises(pki.BadRequestException) as e:
raiser(body)
@@ -57,8 +59,28 @@ class PKITests(unittest.TestCase):
'com.netscape.certsrv.base.BadRequestException'
)
+ body = json.dumps({
+ 'Message': u'messag€ with non-äscii',
+ 'Code': 42,
+ 'ClassName': 'com.netscape.certsrv.base.BadRequestException',
+ 'Attributes': {
+ 'Attribute': [],
+ },
+ }).encode('utf-8')
+
+ with self.assertRaises(pki.BadRequestException) as e:
+ raiser(body)
+
+ self.assertEqual(e.exception.message, u'messag€ with non-äscii')
+ self.assertEqual(e.exception.code, 42)
+ self.assertEqual(
+ e.exception.ClassName,
+ 'com.netscape.certsrv.base.BadRequestException'
+ )
+
+
with self.assertRaises(TestHTTPError) as e:
- raiser('no json body')
+ raiser(b'no json body')
if __name__ == '__main__':