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
Labels
Merge Requests
141
Merge Requests
141
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
f2833d5d
Commit
f2833d5d
authored
Feb 12, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api_style: py3
parent
e9a3c7c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
22 deletions
+32
-22
bt5/erp5_api_style/TestTemplateItem/portal_components/test.erp5.testJioApiStyle.py
...mplateItem/portal_components/test.erp5.testJioApiStyle.py
+32
-22
No files found.
bt5/erp5_api_style/TestTemplateItem/portal_components/test.erp5.testJioApiStyle.py
View file @
f2833d5d
...
@@ -332,12 +332,16 @@ class TestjIOApiStyle(ERP5TypeTestCase):
...
@@ -332,12 +332,16 @@ class TestjIOApiStyle(ERP5TypeTestCase):
"""
"""
# Send bad JSON
# Send bad JSON
json_payload
=
'{'
json_payload
=
'{'
invalid_json_error_message
=
"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"
if
six
.
PY2
:
invalid_json_error_message
=
u"Expecting object: line 1 column 1 (char 0)"
result
=
json
.
loads
(
api_method
(
json_payload
))
result
=
json
.
loads
(
api_method
(
json_payload
))
self
.
assertEqual
(
400
,
result
[
u"status"
])
self
.
assertEqual
(
400
,
result
[
u"status"
])
self
.
assertEqual
(
u"Expecting object: line 1 column 1 (char 0)"
,
result
[
u"message"
]
)
self
.
assertEqual
(
result
[
u"message"
],
invalid_json_error_message
)
self
.
assertEqual
(
u"API-JSON-INVALID-JSON"
,
result
[
u"name"
])
self
.
assertEqual
(
u"API-JSON-INVALID-JSON"
,
result
[
u"name"
])
error_record
=
self
.
portal
.
restrictedTraverse
(
"error_record_module/"
+
result
[
u"debug_id"
].
encode
())
error_record
=
self
.
portal
.
restrictedTraverse
(
"error_record_module/"
+
(
result
[
'debug_id'
]
if
six
.
PY3
else
result
[
'debug_id'
].
encode
()))
self
.
assertEqual
(
error_record
.
getDescription
(),
"Expecting object: line 1 column 1 (char 0)"
)
self
.
assertEqual
(
error_record
.
getDescription
(),
invalid_json_error_message
)
self
.
assertEqual
(
error_record
.
getTitle
(),
"API-JSON-INVALID-JSON"
)
self
.
assertEqual
(
error_record
.
getTitle
(),
"API-JSON-INVALID-JSON"
)
self
.
assertEqual
(
error_record
.
getTextContent
(),
json_payload
)
self
.
assertEqual
(
error_record
.
getTextContent
(),
json_payload
)
# Do not send a JSON object
# Do not send a JSON object
...
@@ -346,7 +350,7 @@ class TestjIOApiStyle(ERP5TypeTestCase):
...
@@ -346,7 +350,7 @@ class TestjIOApiStyle(ERP5TypeTestCase):
self
.
assertEqual
(
400
,
result
[
u"status"
])
self
.
assertEqual
(
400
,
result
[
u"status"
])
self
.
assertEqual
(
u"API-JSON-NOT-JSON-OBJECT"
,
result
[
u"name"
])
self
.
assertEqual
(
u"API-JSON-NOT-JSON-OBJECT"
,
result
[
u"name"
])
self
.
assertEqual
(
u"Did not received a JSON Object"
,
result
[
u"message"
])
self
.
assertEqual
(
u"Did not received a JSON Object"
,
result
[
u"message"
])
error_record
=
self
.
portal
.
restrictedTraverse
(
"error_record_module/"
+
result
[
u"debug_id"
].
encode
(
))
error_record
=
self
.
portal
.
restrictedTraverse
(
"error_record_module/"
+
(
result
[
'debug_id'
]
if
six
.
PY3
else
result
[
'debug_id'
].
encode
()
))
self
.
assertEqual
(
error_record
.
getDescription
(),
"Did not received a JSON Object"
)
self
.
assertEqual
(
error_record
.
getDescription
(),
"Did not received a JSON Object"
)
self
.
assertEqual
(
error_record
.
getTitle
(),
"API-JSON-NOT-JSON-OBJECT"
)
self
.
assertEqual
(
error_record
.
getTitle
(),
"API-JSON-NOT-JSON-OBJECT"
)
self
.
assertEqual
(
error_record
.
getTextContent
(),
json_payload
)
self
.
assertEqual
(
error_record
.
getTextContent
(),
json_payload
)
...
@@ -788,12 +792,14 @@ return [{
...
@@ -788,12 +792,14 @@ return [{
))
))
if
not
"result_list"
in
response
:
if
not
"result_list"
in
response
:
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
self
.
assertEqual
(
1
,
len
(
response
[
"result_list"
]))
self
.
assertEqual
(
self
.
assertEqual
({
response
[
"result_list"
],
u"id"
:
person
.
getRelativeUrl
().
decode
(),
[{
u"portal_type"
:
person
.
getPortalType
().
decode
(),
"id"
:
person
.
getRelativeUrl
(),
u"title"
:
person
.
getTitle
().
decode
(),
"portal_type"
:
person
.
getPortalType
(),
},
response
[
"result_list"
][
0
])
"title"
:
person
.
getTitle
(),
}],
)
def
test_action_all_docs_success_one_action_no_result
(
self
):
def
test_action_all_docs_success_one_action_no_result
(
self
):
"""
"""
...
@@ -882,12 +888,14 @@ return [{
...
@@ -882,12 +888,14 @@ return [{
))
))
if
not
"result_list"
in
response
:
if
not
"result_list"
in
response
:
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
self
.
assertEqual
(
1
,
len
(
response
[
"result_list"
]))
self
.
assertEqual
(
self
.
assertEqual
({
response
[
"result_list"
],
u"id"
:
organisation
.
getRelativeUrl
().
decode
(),
[{
u"portal_type"
:
organisation
.
getPortalType
().
decode
(),
"id"
:
organisation
.
getRelativeUrl
(),
u"title"
:
organisation
.
getTitle
().
decode
(),
"portal_type"
:
organisation
.
getPortalType
(),
},
response
[
"result_list"
][
0
])
"title"
:
organisation
.
getTitle
(),
}],
)
# Check Second action
# Check Second action
response
=
json
.
loads
(
self
.
allDocsToApi
(
response
=
json
.
loads
(
self
.
allDocsToApi
(
"""{
"""{
...
@@ -897,12 +905,14 @@ return [{
...
@@ -897,12 +905,14 @@ return [{
))
))
if
not
"result_list"
in
response
:
if
not
"result_list"
in
response
:
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
raise
ValueError
(
"Unexcpected Answer %s"
%
response
)
self
.
assertEqual
(
1
,
len
(
response
[
"result_list"
]))
self
.
assertEqual
(
self
.
assertEqual
({
response
[
"result_list"
],
u"id"
:
person
.
getRelativeUrl
().
decode
(),
[{
u"portal_type"
:
person
.
getPortalType
().
decode
(),
"id"
:
person
.
getRelativeUrl
(),
u"title"
:
person
.
getTitle
().
decode
(),
"portal_type"
:
person
.
getPortalType
(),
},
response
[
"result_list"
][
0
])
"title"
:
person
.
getTitle
(),
}],
)
def
test_action_all_docs_success_two_actions_with_no_result
(
self
):
def
test_action_all_docs_success_two_actions_with_no_result
(
self
):
"""
"""
...
...
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