Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
7929996d
Commit
7929996d
authored
Feb 02, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_form: Empty data doesn't mean data is valid
* Case of required properties
parent
af3b68a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
...tTemplateItem/portal_components/document.erp5.JSONForm.py
+0
-2
bt5/erp5_json_form/TestTemplateItem/portal_components/test.erp5.testJSONForm.py
...tTemplateItem/portal_components/test.erp5.testJSONForm.py
+29
-0
No files found.
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
View file @
7929996d
...
...
@@ -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
())
...
...
bt5/erp5_json_form/TestTemplateItem/portal_components/test.erp5.testJSONForm.py
View file @
7929996d
...
...
@@ -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
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment