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
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_processSimpleStriingAsJSON"
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_processSimpleStriingAsJSON"
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_processSimpleStriingAsJSON"
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_processSimpleStriingAsJSON"
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_processSimpleStriingAsJSON"
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_processSimpleStriingAsJSON"
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)
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