Merge "Make str(json_param) return string vs python"
This commit is contained in:
commit
38aa12a015
@ -391,6 +391,11 @@ class JsonParam(Parameter):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.parsed)
|
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):
|
def _validate(self, val, context):
|
||||||
val = self.parse(val)
|
val = self.parse(val)
|
||||||
self.schema.validate_value(val, context)
|
self.schema.validate_value(val, context)
|
||||||
|
@ -50,6 +50,16 @@ class ParameterTest(testtools.TestCase):
|
|||||||
p = self.new_parameter('p', {'Type': 'Json'}, validate_value=False)
|
p = self.new_parameter('p', {'Type': 'Json'}, validate_value=False)
|
||||||
self.assertIsInstance(p, parameters.JsonParam)
|
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):
|
def test_new_bad_type(self):
|
||||||
self.assertRaises(exception.InvalidSchemaError, self.new_parameter,
|
self.assertRaises(exception.InvalidSchemaError, self.new_parameter,
|
||||||
'p', {'Type': 'List'}, validate_value=False)
|
'p', {'Type': 'List'}, validate_value=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user