Commit ef723c7a authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Catch invalid value in JSON Schema renderer

A JSON Schema must be a Boolean or an object.
parent e142fe482ba0
...@@ -199,6 +199,9 @@ def includeme(config): ...@@ -199,6 +199,9 @@ def includeme(config):
'$schema', '$schema',
'http://json-schema.org/draft-06/schema#', 'http://json-schema.org/draft-06/schema#',
) )
elif not isinstance(value, bool):
raise ValueError(
"JSON Schema value must be of object or boolean type")
return json.dumps(value, **kwargs) return json.dumps(value, **kwargs)
config.add_renderer( config.add_renderer(
......
...@@ -62,6 +62,10 @@ class JSONSchemaRendererTC(TestCase): ...@@ -62,6 +62,10 @@ class JSONSchemaRendererTC(TestCase):
self.assertEqual(renderers.render('jsonschema', value), self.assertEqual(renderers.render('jsonschema', value),
str(value).lower()) str(value).lower())
def test_invalid_value(self):
with self.assertRaises(ValueError):
renderers.render('jsonschema', 'a')
class BaseTC(PyramidCWTest): class BaseTC(PyramidCWTest):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment