Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
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
Romain Courteaud
slapos.core
Commits
af0c79aa
Commit
af0c79aa
authored
Dec 04, 2024
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_rpc_api: fail fail
parent
763b1475
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
2 deletions
+95
-2
master/bt5/erp5_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testJsonRpcAPIService.py
...Item/portal_components/test.erp5.testJsonRpcAPIService.py
+95
-2
No files found.
master/bt5/erp5_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testJsonRpcAPIService.py
View file @
af0c79aa
...
@@ -34,15 +34,30 @@ class JsonRpcAPITestCase(ERP5TypeTestCase):
...
@@ -34,15 +34,30 @@ class JsonRpcAPITestCase(ERP5TypeTestCase):
_type_id
=
'JSON RPC API Test Service'
_type_id
=
'JSON RPC API Test Service'
_action_list_text
=
''
_action_list_text
=
''
def
addJSONForm
(
self
,
script_id
,
body
):
def
addJSONForm
(
self
,
script_id
,
input_json_schema
=
None
,
after_method_id
=
None
):
self
.
portal
.
portal_callables
.
newContent
(
self
.
portal
.
portal_callables
.
newContent
(
portal_type
=
'JSON Form'
,
portal_type
=
'JSON Form'
,
id
=
script_id
,
id
=
script_id
,
text_content
=
body
text_content
=
input_json_schema
,
after_method_id
=
after_method_id
)
)
self
.
tic
()
self
.
tic
()
self
.
_json_form_id_to_cleanup
.
append
(
script_id
)
self
.
_json_form_id_to_cleanup
.
append
(
script_id
)
def
addPythonScript
(
self
,
script_id
,
params
,
body
):
skin_folder
=
self
.
portal
.
portal_skins
[
'custom'
]
skin_folder
.
manage_addProduct
[
'ERP5'
].
addPythonScriptThroughZMI
(
id
=
script_id
)
self
.
script
=
skin_folder
.
get
(
script_id
)
self
.
script
.
setParameterSignature
(
params
)
self
.
script
.
setBody
(
body
)
self
.
tic
()
self
.
_python_script_id_to_cleanup
.
append
(
script_id
)
self
.
portal
.
changeSkin
(
None
)
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
self
.
portal
.
portal_types
.
newContent
(
self
.
portal
.
portal_types
.
newContent
(
portal_type
=
'JSON RPC API Type'
,
portal_type
=
'JSON RPC API Type'
,
...
@@ -84,6 +99,9 @@ class JsonRpcAPITestCase(ERP5TypeTestCase):
...
@@ -84,6 +99,9 @@ class JsonRpcAPITestCase(ERP5TypeTestCase):
self
.
tic
()
self
.
tic
()
if
self
.
_json_form_id_to_cleanup
:
if
self
.
_json_form_id_to_cleanup
:
self
.
portal
.
portal_callables
.
manage_delObjects
(
self
.
_json_form_id_to_cleanup
)
self
.
portal
.
portal_callables
.
manage_delObjects
(
self
.
_json_form_id_to_cleanup
)
skin_folder
=
self
.
portal
.
portal_skins
[
'custom'
]
if
self
.
_python_script_id_to_cleanup
:
skin_folder
.
manage_delObjects
(
self
.
_python_script_id_to_cleanup
)
self
.
tic
()
self
.
tic
()
"""
"""
...
@@ -341,6 +359,81 @@ error.handling.callable | JsonRpcService_testExample'''
...
@@ -341,6 +359,81 @@ error.handling.callable | JsonRpcService_testExample'''
'type'
:
'unknown-error'
'type'
:
'unknown-error'
})
})
def
test_requestErrorHandling_unknownAfterMethod
(
self
):
self
.
addJSONForm
(
'JsonRpcService_testExample'
,
'{}'
,
after_method_id
=
'THISSCRIPTDOESNOTEXIST'
,
)
response
=
self
.
publish
(
self
.
connector
.
getPath
()
+
'/error.handling.callable'
,
user
=
'ERP5TypeTestCase'
,
request_method
=
'POST'
,
stdin
=
io
.
BytesIO
(
'{}'
.
encode
()),
env
=
{
'CONTENT_TYPE'
:
'application/json'
})
self
.
assertEqual
(
response
.
getStatus
(),
500
)
self
.
assertEqual
(
response
.
getHeader
(
'content-type'
),
'application/json'
)
self
.
assertEqual
(
json
.
loads
(
response
.
getBody
()),
{
"type"
:
"unknown-error"
,
"title"
:
"AttributeError: 'RequestContainer' object has no attribute 'THISSCRIPTDOESNOTEXIST'"
})
def
test_requestErrorHandling_failingAfterMethod
(
self
):
self
.
addPythonScript
(
'JsonRpcService_fail'
,
'data_dict, json_form'
,
'1//0'
,
)
self
.
addJSONForm
(
'JsonRpcService_testExample'
,
'{}'
,
after_method_id
=
'JsonRpcService_fail'
,
)
response
=
self
.
publish
(
self
.
connector
.
getPath
()
+
'/error.handling.callable'
,
user
=
'ERP5TypeTestCase'
,
request_method
=
'POST'
,
stdin
=
io
.
BytesIO
(
'{}'
.
encode
()),
env
=
{
'CONTENT_TYPE'
:
'application/json'
})
self
.
assertEqual
(
response
.
getStatus
(),
500
)
self
.
assertEqual
(
response
.
getHeader
(
'content-type'
),
'application/json'
)
self
.
assertEqual
(
json
.
loads
(
response
.
getBody
()),
{
"type"
:
"unknown-error"
,
"title"
:
"ZeroDivisionError: integer division or modulo by zero"
})
def
test_requestErrorHandling_abortTransactionOnError
(
self
):
self
.
addPythonScript
(
'JsonRpcService_fail'
,
'data_dict, json_form'
,
'context.getPortalObject().setTitle("ooops")
\
n
'
'1/0'
,
)
self
.
addJSONForm
(
'JsonRpcService_testExample'
,
'{}'
,
after_method_id
=
'JsonRpcService_fail'
,
)
response
=
self
.
publish
(
self
.
connector
.
getPath
()
+
'/error.handling.callable'
,
user
=
'ERP5TypeTestCase'
,
request_method
=
'POST'
,
stdin
=
io
.
BytesIO
(
'{}'
.
encode
()),
env
=
{
'CONTENT_TYPE'
:
'application/json'
})
self
.
assertEqual
(
response
.
getStatus
(),
500
)
self
.
assertEqual
(
response
.
getHeader
(
'content-type'
),
'application/json'
)
self
.
assertEqual
(
json
.
loads
(
response
.
getBody
()),
{
"type"
:
"unknown-error"
,
"title"
:
"ZeroDivisionError: integer division or modulo by zero"
})
self
.
assertNotEqual
(
self
.
portal
.
getTitle
(),
"ooops"
)
class
TestJsonRpcAPIJsonFormHandling
(
JsonRpcAPITestCase
):
class
TestJsonRpcAPIJsonFormHandling
(
JsonRpcAPITestCase
):
_action_list_text
=
'''json.form.handling.callable | JsonRpcService_callFromTest'''
_action_list_text
=
'''json.form.handling.callable | JsonRpcService_callFromTest'''
...
...
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