Make str(json_param) return string vs python
Closes-Bug: #1366798 Change-Id: I3f435932787662cb1bfa91bd5a84c21cf6ddf9d0
This commit is contained in:
parent
35d7465c11
commit
3913658527
@ -386,6 +386,11 @@ class JsonParam(Parameter):
|
||||
def __len__(self):
|
||||
return len(self.parsed)
|
||||
|
||||
def __str__(self):
|
||||
if self.hidden():
|
||||
return super(JsonParam, self).__str__()
|
||||
return strutils.safe_decode(json.dumps(self.value()))
|
||||
|
||||
def _validate(self, val, context):
|
||||
val = self.parse(val)
|
||||
self.schema.validate_value(val, context)
|
||||
|
@ -50,6 +50,16 @@ class ParameterTest(testtools.TestCase):
|
||||
p = self.new_parameter('p', {'Type': 'Json'}, validate_value=False)
|
||||
self.assertIsInstance(p, parameters.JsonParam)
|
||||
|
||||
def test_json_return(self):
|
||||
p = self.new_parameter('p', {'Type': 'Json'}, {"a": 1, "b": "a"})
|
||||
self.assertEqual('{"a": 1, "b": "a"}', str(p))
|
||||
|
||||
def test_json_return_no_echo_true(self):
|
||||
p = self.new_parameter(
|
||||
'p', {'Type': 'Json', 'NoEcho': 'true'}, {"a": 1})
|
||||
self.assertTrue(p.hidden())
|
||||
self.assertEqual(str(p), '******')
|
||||
|
||||
def test_new_bad_type(self):
|
||||
self.assertRaises(exception.InvalidSchemaError, self.new_parameter,
|
||||
'p', {'Type': 'List'}, validate_value=False)
|
||||
|
Loading…
Reference in New Issue
Block a user