Commit a351ea21 authored by Titouan Soulard's avatar Titouan Soulard

erp5_action_information_api: validate tests against an input schema

parent eeafb265
...@@ -71,13 +71,52 @@ class TestActionInformationAPI(ERP5TypeTestCase): ...@@ -71,13 +71,52 @@ class TestActionInformationAPI(ERP5TypeTestCase):
action.edit( action.edit(
title=action_id, title=action_id,
reference=action_id, reference=action_id,
action="string:${object_url}/" + action_script, action="string:${object_url}/" + action_id,
action_type=self.object_api_value.getRelativeUrl(), action_type=self.object_api_value.getRelativeUrl(),
float_index=7.0, float_index=7.0,
) )
self.tic() self.tic()
self.commit() self.commit()
json_form = self.portal.portal_callables.get(action_id, None)
if not json_form:
json_form = self.portal.portal_callables.newContent(
portal_type="JSON Form",
id=action_id,
)
json_form.edit(
title=action_id,
reference=action_id,
after_method_id=action_script,
)
# Note: text content is input schema
json_form.setTextContent("""{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "",
"title": "Update Person email",
"description": "Update email address of a Person",
"type": "object",
"properties": {
"email": {
"title": "Email address",
"type": "string",
"format": "email"
},
"reference": {
"title": "Unique identifier",
"type": "string"
}
},
"required": [
"email",
"reference"
]
}""")
json_form.setOutputSchema("{}")
self.tic()
self.commit()
createZODBPythonScript( createZODBPythonScript(
self.portal.portal_skins.custom, self.portal.portal_skins.custom,
action_script, action_script,
...@@ -141,7 +180,7 @@ return {"status": 200}""") ...@@ -141,7 +180,7 @@ return {"status": 200}""")
user="ERP5TypeTestCase" user="ERP5TypeTestCase"
) )
def test_hyperdocument_script(self): def test_hyperdocument_cedric(self):
self.setupAiApi() self.setupAiApi()
response = self.loggedInRequest("/api", "GET", {}) response = self.loggedInRequest("/api", "GET", {})
...@@ -152,7 +191,15 @@ return {"status": 200}""") ...@@ -152,7 +191,15 @@ return {"status": 200}""")
self.assertTrue("Person_updateEmail/getInputJSONSchema" in response_json["links"][0]["$schemaRequest"]) self.assertTrue("Person_updateEmail/getInputJSONSchema" in response_json["links"][0]["$schemaRequest"])
self.assertTrue("Person_updateEmail/getOutputJSONSchema" in response_json["links"][0]["$schemaResponse"]) self.assertTrue("Person_updateEmail/getOutputJSONSchema" in response_json["links"][0]["$schemaResponse"])
def test_update_script(self): def test_hyperdocument_openapi(self):
self.setupOpenApi()
response = self.loggedInRequest("/api", "GET", {})
response_json = json.loads(response.getBody())
self.assertEqual(response_json["openapi"], "3.0.2")
def test_update_cedric(self):
self.setupAiApi() self.setupAiApi()
person = self.portal.person_module.newContent( person = self.portal.person_module.newContent(
...@@ -173,11 +220,3 @@ return {"status": 200}""") ...@@ -173,11 +220,3 @@ return {"status": 200}""")
self.assertEqual(response.getBody(), json.dumps({ "status": 200 }, indent=2)) self.assertEqual(response.getBody(), json.dumps({ "status": 200 }, indent=2))
self.assertEqual(response.getStatus(), 200) self.assertEqual(response.getStatus(), 200)
self.assertEqual(person.getDefaultEmailUrlString(), "alice@looking.glass") self.assertEqual(person.getDefaultEmailUrlString(), "alice@looking.glass")
def test_hyperdocument_openapi(self):
self.setupOpenApi()
response = self.loggedInRequest("/api", "GET", {})
response_json = json.loads(response.getBody())
self.assertEqual(response_json["openapi"], "3.0.2")
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