summaryrefslogtreecommitdiff
path: root/cloudinit/tests
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2019-09-27 20:46:00 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-09-27 20:46:00 +0000
commit067516d7bc917e4921b9f1424b7a64e92cae0ad2 (patch)
tree79063a27ea9cf596e7dcbe3e8ba7452abb9b84c8 /cloudinit/tests
parent052d655cfba37243396c491a1e7892ba3736ab6f (diff)
downloadvyos-cloud-init-067516d7bc917e4921b9f1424b7a64e92cae0ad2.tar.gz
vyos-cloud-init-067516d7bc917e4921b9f1424b7a64e92cae0ad2.zip
util: json.dumps on python 2.7 will handle UnicodeDecodeError on binary
Since python 2.7 doesn't handle UnicodeDecodeErrors with the default handler LP: #1801364
Diffstat (limited to 'cloudinit/tests')
-rw-r--r--cloudinit/tests/test_util.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/cloudinit/tests/test_util.py b/cloudinit/tests/test_util.py
index e3d2dbaa..f4f95e92 100644
--- a/cloudinit/tests/test_util.py
+++ b/cloudinit/tests/test_util.py
@@ -2,7 +2,9 @@
"""Tests for cloudinit.util"""
+import base64
import logging
+import json
import platform
import cloudinit.util as util
@@ -528,6 +530,24 @@ class TestGetLinuxDistro(CiTestCase):
self.assertEqual(('foo', '1.1', 'aarch64'), dist)
+class TestJsonDumps(CiTestCase):
+ def test_is_str(self):
+ """json_dumps should return a string."""
+ self.assertTrue(isinstance(util.json_dumps({'abc': '123'}), str))
+
+ def test_utf8(self):
+ smiley = '\\ud83d\\ude03'
+ self.assertEqual(
+ {'smiley': smiley},
+ json.loads(util.json_dumps({'smiley': smiley})))
+
+ def test_non_utf8(self):
+ blob = b'\xba\x03Qx-#y\xea'
+ self.assertEqual(
+ {'blob': 'ci-b64:' + base64.b64encode(blob).decode('utf-8')},
+ json.loads(util.json_dumps({'blob': blob})))
+
+
@mock.patch('os.path.exists')
class TestIsLXD(CiTestCase):