def take_action(self, parsed_args): _fields = list(FIELDS) if parsed_args.long: _fields.append(('Result', )) result = models.TaskResult.query.get(parsed_args.result_id) return utils.fields_from_object( _fields, result, xforms={ 'Task': lambda t: '{0} ({1})'.format(t.name, t.id), 'Result': lambda r: utils.format_json(r), })
def take_action(self, args): _fields = list(FIELDS) if args.long: _fields.append(('Result',)) result = models.TaskResult.query.get(args.result_id) if result is None: raise RuntimeError('Result %s could not be found' % args.result_id) return utils.fields_from_object( _fields, result, xforms={ 'Task': lambda t: '{0} ({1})'.format(t.name, t.id), 'Result': lambda r: utils.format_json(r), })
def test_format_json_fail(self): res = u.format_json('{invalid:}') self.assertEqual(res, '{invalid:}')
def test_format_json(self): data = json.dumps({'name': 'value'}) res = u.format_json(json.dumps(data)) self.assertEqual(res, '"{\\"name\\": \\"value\\"}"')