Commit 39990102 authored by Valentin Benozillo's avatar Valentin Benozillo

erp5_web_service: Add RESTAPIClientConnector raise error test

parent 66fbfbf8
...@@ -9,6 +9,9 @@ import mock ...@@ -9,6 +9,9 @@ import mock
expected_output_body_dict = { expected_output_body_dict = {
u'output': 'output', u'output': 'output',
} }
input_body_dict = {
'input': 'input',
}
class HTTPResponse_getresponse(): class HTTPResponse_getresponse():
def __init__(self, status=200): def __init__(self, status=200):
...@@ -43,6 +46,9 @@ class RESTAPIClientConnector(RESTAPIClientConnectorMixin): ...@@ -43,6 +46,9 @@ class RESTAPIClientConnector(RESTAPIClientConnectorMixin):
def _getAccessToken(self): def _getAccessToken(self):
return 'access_token' return 'access_token'
def getTimeout(self, timeout):
return 5
def getBaseUrl(self): def getBaseUrl(self):
return 'https://example.com/' return 'https://example.com/'
...@@ -58,9 +64,6 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase): ...@@ -58,9 +64,6 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
self.rest_api_client_connection = RESTAPIClientConnector(id='rest_api_client_connection') self.rest_api_client_connection = RESTAPIClientConnector(id='rest_api_client_connection')
def test_api_call(self): def test_api_call(self):
input_body_dict = {
'input': 'input',
}
timeout = 1 timeout = 1
with mock.patch( with mock.patch(
...@@ -134,3 +137,34 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase): ...@@ -134,3 +137,34 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
status, status,
200 200
) )
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
)
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