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
139
Merge Requests
139
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
39990102
Commit
39990102
authored
Jan 31, 2024
by
Valentin Benozillo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_web_service: Add RESTAPIClientConnector raise error test
parent
66fbfbf8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
4 deletions
+38
-4
bt5/erp5_web_service/TestTemplateItem/portal_components/test.erp5.testRESTAPIClientConnectorMixin.py
...l_components/test.erp5.testRESTAPIClientConnectorMixin.py
+38
-4
No files found.
bt5/erp5_web_service/TestTemplateItem/portal_components/test.erp5.testRESTAPIClientConnectorMixin.py
View file @
39990102
...
...
@@ -9,6 +9,9 @@ import mock
expected_output_body_dict
=
{
u'output'
:
'output'
,
}
input_body_dict
=
{
'input'
:
'input'
,
}
class
HTTPResponse_getresponse
():
def
__init__
(
self
,
status
=
200
):
...
...
@@ -43,6 +46,9 @@ class RESTAPIClientConnector(RESTAPIClientConnectorMixin):
def
_getAccessToken
(
self
):
return
'access_token'
def
getTimeout
(
self
,
timeout
):
return
5
def
getBaseUrl
(
self
):
return
'https://example.com/'
...
...
@@ -58,9 +64,6 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
self
.
rest_api_client_connection
=
RESTAPIClientConnector
(
id
=
'rest_api_client_connection'
)
def
test_api_call
(
self
):
input_body_dict
=
{
'input'
:
'input'
,
}
timeout
=
1
with
mock
.
patch
(
...
...
@@ -133,4 +136,35 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
self
.
assertEqual
(
status
,
200
)
\ No newline at end of file
)
def
test_api_call_error
(
self
):
with
mock
.
patch
(
'ssl.create_default_context'
,
),
mock
.
patch
(
'httplib.HTTPSConnection.request'
,
),
mock
.
patch
(
'httplib.HTTPSConnection.getresponse'
,
return_value
=
HTTPResponse_getresponse
(
498
)
):
with
self
.
assertRaises
(
RESTAPIError
)
as
error
:
self
.
rest_api_client_connection
.
call
(
archive_resource
=
None
,
method
=
'POST'
,
path
=
'/path'
,
body
=
input_body_dict
)
self
.
assertEqual
(
error
.
status
,
498
)
self
.
assertEqual
(
error
.
header_dict
[
'content-type'
],
'application/json'
)
self
.
assertEqual
(
error
.
body
,
expected_output_body_dict
)
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