json serialize additional types in protonmsg

Fixes: https://pagure.io/koji/issue/741
This commit is contained in:
Tomas Kopecek 2017-12-21 13:10:01 +01:00 committed by Mike McLean
parent f869eb4158
commit 3bfcc6a66e
2 changed files with 11 additions and 2 deletions

View file

@ -130,12 +130,20 @@ class TimeoutHandler(MessagingHandler):
self.timeout_task.cancel()
self.timeout_task = None
def json_serialize(o):
"""JSON helper to encode otherwise unserializable data types"""
if isinstance(o, set):
return list(o)
raise TypeError(repr(o) + " is not JSON serializable")
def queue_msg(address, props, data):
msgs = getattr(context, 'protonmsg_msgs', None)
if msgs is None:
msgs = []
context.protonmsg_msgs = msgs
body = json.dumps(data)
body = json.dumps(data, default=json_serialize)
msgs.append((address, props, body))
@convert_datetime

View file

@ -153,7 +153,8 @@ class TestProtonMsg(unittest.TestCase):
user='test-user', **build)
def test_prep_repo_init(self):
protonmsg.prep_repo_init('postRepoInit', tag={'name': 'test-tag'}, repo_id=1234)
protonmsg.prep_repo_init('postRepoInit', tag={'name': 'test-tag',
'arches': set(['x86_64', 'i386'])}, repo_id=1234)
self.assertMsg('repo.init', type='RepoInit', tag='test-tag', repo_id=1234)
def test_prep_repo_done(self):