Commit a1c17c1a authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

erp5_json_form: Empty data doesn't mean data is valid

* Case of required properties
parent 97ae8091
......@@ -73,8 +73,6 @@ class JSONForm(JSONType, TextDocument):
"""
Validate contained JSON with the Schema defined in the Portal Type.
"""
if not json_data:
return True
defined_schema = json.loads(self.getTextContent() or "")
try:
jsonschema.validate(json_data, defined_schema, format_checker=jsonschema.FormatChecker())
......
......@@ -214,3 +214,32 @@ return json.dumps({
except ValueError as e:
self.assertEqual(error, json.loads(str(e)))
def test_empty_data_with_required_property(self):
"""
"""
schema = """{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "my-schema.json",
"properties":{
"title": {
"type": "string"
}
},
"required": ["title"]
}"""
data = {}
method = "test_ERP5Site_processSimpleStriingAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method)
self.tic()
self.assertRaises(ValueError, getattr(self.portal, method), data, list_error=True)
error = {
"my-schema.json": [[
'Validation Error', u"u'title' is a required property"
]]
}
try:
getattr(self.portal, method)(data, list_error=True)
raise ValueError("No error raised during processing")
except ValueError, e:
self.assertEqual(error, json.loads(str(e)))
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