Commit b032c93c authored by Titouan Soulard's avatar Titouan Soulard

erp5_json_form: SPLIT add test for argument mappings

Also: typo and update tests (to be finished)
parent 052b33da
...@@ -31,11 +31,7 @@ from DateTime import DateTime ...@@ -31,11 +31,7 @@ from DateTime import DateTime
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
class Test(ERP5TypeTestCase): class TestJSONForm(ERP5TypeTestCase):
"""
A Sample Test Class
"""
def afterSetUp(self): def afterSetUp(self):
""" """
This is ran before anything, used to set the environment This is ran before anything, used to set the environment
...@@ -51,13 +47,11 @@ class Test(ERP5TypeTestCase): ...@@ -51,13 +47,11 @@ class Test(ERP5TypeTestCase):
createZODBPythonScript( createZODBPythonScript(
self.portal.portal_skins.custom, self.portal.portal_skins.custom,
name, name,
"text_data, form_reference", "title, form_reference",
""" """return {
import json
return json.dumps({
"datetime": DateTime().ISO8601(), "datetime": DateTime().ISO8601(),
"content": text_data, "title": title,
}, indent=2) }
""" """
) )
return name return name
...@@ -72,6 +66,7 @@ return json.dumps({ ...@@ -72,6 +66,7 @@ return json.dumps({
reference=reference, reference=reference,
id=reference, id=reference,
) )
json_form.manage_delObjects(list(json_form.objectIds()))
json_form.edit( json_form.edit(
text_content=text_content, text_content=text_content,
after_method_id=after_method_id, after_method_id=after_method_id,
...@@ -79,6 +74,8 @@ return json.dumps({ ...@@ -79,6 +74,8 @@ return json.dumps({
if self.portal.portal_workflow.isTransitionPossible(json_form, 'validate'): if self.portal.portal_workflow.isTransitionPossible(json_form, 'validate'):
json_form.validate() json_form.validate()
return json_form
def test_call_valid_json(self): def test_call_valid_json(self):
""" """
""" """
...@@ -94,14 +91,14 @@ return json.dumps({ ...@@ -94,14 +91,14 @@ return json.dumps({
data = { data = {
"title": "foo" "title": "foo"
} }
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp() after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method) self.fixJSONForm(method, schema, after_method)
self.tic() self.tic()
result = getattr(self.portal, method)(data) result = getattr(self.portal, method)(json.dumps(data))
self.assertEqual( self.assertEqual(
json.loads(result)['content'], json.loads(result),
json.loads(json.dumps(data)) data,
) )
def test_call_no_after_method_id_valid_json(self): def test_call_no_after_method_id_valid_json(self):
...@@ -119,7 +116,7 @@ return json.dumps({ ...@@ -119,7 +116,7 @@ return json.dumps({
data = { data = {
"title": "foo" "title": "foo"
} }
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
self.fixJSONForm(method, schema, "") self.fixJSONForm(method, schema, "")
self.tic() self.tic()
result = getattr(self.portal, method)(data) result = getattr(self.portal, method)(data)
...@@ -144,7 +141,7 @@ return json.dumps({ ...@@ -144,7 +141,7 @@ return json.dumps({
"title": 2, "title": 2,
"number": "2" "number": "2"
} }
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp() after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method) self.fixJSONForm(method, schema, after_method)
self.tic() self.tic()
...@@ -172,7 +169,7 @@ return json.dumps({ ...@@ -172,7 +169,7 @@ return json.dumps({
data = { data = {
"timestamp": DateTime().ISO8601() "timestamp": DateTime().ISO8601()
} }
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp() after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method) self.fixJSONForm(method, schema, after_method)
self.tic() self.tic()
...@@ -198,7 +195,7 @@ return json.dumps({ ...@@ -198,7 +195,7 @@ return json.dumps({
json_data = { json_data = {
"timestamp": "2018-11-13T20:20:67" "timestamp": "2018-11-13T20:20:67"
} }
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp() after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method) self.fixJSONForm(method, schema, after_method)
self.tic() self.tic()
...@@ -228,7 +225,7 @@ return json.dumps({ ...@@ -228,7 +225,7 @@ return json.dumps({
"required": ["title"] "required": ["title"]
}""" }"""
data = {} data = {}
method = "test_ERP5Site_processSimpleStriingAsJSON" method = "test_ERP5Site_processSimpleStringAsJSON"
after_method = self.createBasicScriptreturnJSONWithTimestamp() after_method = self.createBasicScriptreturnJSONWithTimestamp()
self.fixJSONForm(method, schema, after_method) self.fixJSONForm(method, schema, after_method)
self.tic() self.tic()
...@@ -243,3 +240,44 @@ return json.dumps({ ...@@ -243,3 +240,44 @@ return json.dumps({
raise ValueError("No error raised during processing") raise ValueError("No error raised during processing")
except ValueError, e: except ValueError, e:
self.assertEqual(error, json.loads(str(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)
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