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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
erp5
Commits
b032c93c
Commit
b032c93c
authored
Nov 19, 2024
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_form: SPLIT add test for argument mappings
Also: typo and update tests (to be finished)
parent
052b33da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
20 deletions
+58
-20
bt5/erp5_json_form/TestTemplateItem/portal_components/test.erp5.testJSONForm.py
...tTemplateItem/portal_components/test.erp5.testJSONForm.py
+58
-20
No files found.
bt5/erp5_json_form/TestTemplateItem/portal_components/test.erp5.testJSONForm.py
View file @
b032c93c
...
...
@@ -31,11 +31,7 @@ from DateTime import DateTime
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
Test
(
ERP5TypeTestCase
):
"""
A Sample Test Class
"""
class
TestJSONForm
(
ERP5TypeTestCase
):
def
afterSetUp
(
self
):
"""
This is ran before anything, used to set the environment
...
...
@@ -51,13 +47,11 @@ class Test(ERP5TypeTestCase):
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
name
,
"text_data, form_reference"
,
"""
import json
return json.dumps({
"title, form_reference"
,
"""return {
"datetime": DateTime().ISO8601(),
"
content": text_data
,
}
, indent=2)
"
title": title
,
}
"""
)
return
name
...
...
@@ -72,6 +66,7 @@ return json.dumps({
reference
=
reference
,
id
=
reference
,
)
json_form
.
manage_delObjects
(
list
(
json_form
.
objectIds
()))
json_form
.
edit
(
text_content
=
text_content
,
after_method_id
=
after_method_id
,
...
...
@@ -79,6 +74,8 @@ return json.dumps({
if
self
.
portal
.
portal_workflow
.
isTransitionPossible
(
json_form
,
'validate'
):
json_form
.
validate
()
return
json_form
def
test_call_valid_json
(
self
):
"""
"""
...
...
@@ -94,14 +91,14 @@ return json.dumps({
data
=
{
"title"
:
"foo"
}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
self
.
fixJSONForm
(
method
,
schema
,
after_method
)
self
.
tic
()
result
=
getattr
(
self
.
portal
,
method
)(
data
)
result
=
getattr
(
self
.
portal
,
method
)(
json
.
dumps
(
data
)
)
self
.
assertEqual
(
json
.
loads
(
result
)
[
'content'
]
,
json
.
loads
(
json
.
dumps
(
data
))
json
.
loads
(
result
),
data
,
)
def
test_call_no_after_method_id_valid_json
(
self
):
...
...
@@ -119,7 +116,7 @@ return json.dumps({
data
=
{
"title"
:
"foo"
}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
self
.
fixJSONForm
(
method
,
schema
,
""
)
self
.
tic
()
result
=
getattr
(
self
.
portal
,
method
)(
data
)
...
...
@@ -144,7 +141,7 @@ return json.dumps({
"title"
:
2
,
"number"
:
"2"
}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
self
.
fixJSONForm
(
method
,
schema
,
after_method
)
self
.
tic
()
...
...
@@ -172,7 +169,7 @@ return json.dumps({
data
=
{
"timestamp"
:
DateTime
().
ISO8601
()
}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
self
.
fixJSONForm
(
method
,
schema
,
after_method
)
self
.
tic
()
...
...
@@ -198,7 +195,7 @@ return json.dumps({
json_data
=
{
"timestamp"
:
"2018-11-13T20:20:67"
}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
self
.
fixJSONForm
(
method
,
schema
,
after_method
)
self
.
tic
()
...
...
@@ -228,7 +225,7 @@ return json.dumps({
"required": ["title"]
}"""
data
=
{}
method
=
"test_ERP5Site_processSimpleStri
i
ngAsJSON"
method
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
self
.
fixJSONForm
(
method
,
schema
,
after_method
)
self
.
tic
()
...
...
@@ -243,3 +240,44 @@ return json.dumps({
raise
ValueError
(
"No error raised during processing"
)
except
ValueError
,
e
:
self
.
assertEqual
(
error
,
json
.
loads
(
str
(
e
)))
def
test_supports_argument_mappings
(
self
):
"""
Ensures arguments mappings can be used properly.
"""
schema
=
"""{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "my-schema.json",
"properties":{
"name": {
"type": "string"
}
}
}"""
input_dict
=
{
"name"
:
"foo"
}
method_id
=
"test_ERP5Site_processSimpleStringAsJSON"
after_method
=
self
.
createBasicScriptreturnJSONWithTimestamp
()
json_form
=
self
.
fixJSONForm
(
method_id
,
schema
,
after_method
)
json_form
.
newContent
(
portal_type
=
"Argument Mapping"
,
source
=
"name"
,
destination
=
"title"
,
mapping_type
=
"input"
)
json_form
.
newContent
(
portal_type
=
"Argument Mapping"
,
source
=
"title"
,
destination
=
"output_name"
,
mapping_type
=
"output"
)
self
.
tic
()
method
=
getattr
(
self
.
portal
,
method_id
)
result
=
json
.
loads
(
method
(
json
.
dumps
(
input_dict
)))
self
.
assertIn
(
"output_name"
,
result
)
self
.
assertEqual
(
"foo"
,
result
[
"output_name"
])
self
.
assertNotIn
(
"name"
,
result
)
self
.
assertNotIn
(
"title"
,
result
)
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