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
38bca977
Commit
38bca977
authored
Mar 08, 2024
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! py2/py3: import from six.moves.
parent
92f2197f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
bt5/erp5_web_service/MixinTemplateItem/portal_components/mixin.erp5.RESTAPIClientConnectorMixin.py
...rtal_components/mixin.erp5.RESTAPIClientConnectorMixin.py
+6
-5
bt5/erp5_web_service/TestTemplateItem/portal_components/test.erp5.testRESTAPIClientConnectorMixin.py
...l_components/test.erp5.testRESTAPIClientConnectorMixin.py
+8
-8
No files found.
bt5/erp5_web_service/MixinTemplateItem/portal_components/mixin.erp5.RESTAPIClientConnectorMixin.py
View file @
38bca977
...
...
@@ -26,10 +26,11 @@
#
##############################################################################
import
time
import
urlparse
import
ssl
import
httplib
import
json
from
six.moves.http_client
import
HTTPSConnection
from
six.moves.urllib.parse
import
urlparse
from
six
import
string_types
as
basestring
from
Products.ERP5Type.Timeout
import
getTimeLeft
from
contextlib
import
contextmanager
from
Products.ERP5Type.XMLObject
import
XMLObject
...
...
@@ -105,7 +106,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
header_dict
[
'content-type'
]
=
'application/json'
body
=
json
.
dumps
(
body
)
plain_url
=
self
.
getBaseUrl
().
rstrip
(
'/'
)
+
'/'
+
path
.
lstrip
(
'/'
)
parsed_url
=
urlparse
.
urlparse
(
plain_url
)
parsed_url
=
urlparse
(
plain_url
)
ssl_context
=
ssl
.
create_default_context
(
cadata
=
self
.
getCaCertificatePem
(),
)
...
...
@@ -115,7 +116,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
if
bind_address
:
bind_address
=
(
bind_address
,
0
)
time_left_before_timeout
=
getTimeLeft
()
http_connection
=
httplib
.
HTTPSConnection
(
http_connection
=
HTTPSConnection
(
host
=
parsed_url
.
hostname
,
port
=
parsed_url
.
port
,
strict
=
True
,
...
...
@@ -184,7 +185,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
with
time_tracker
(
'call'
),
Deadline
(
timeout
):
# Limit numbers of retries, in case the authentication API succeeds
# but the token is not usable.
for
_
in
x
range
(
2
):
for
_
in
range
(
2
):
with
time_tracker
(
'token'
):
access_token
=
self
.
_getAccessToken
()
if
access_token
is
not
None
:
...
...
bt5/erp5_web_service/TestTemplateItem/portal_components/test.erp5.testRESTAPIClientConnectorMixin.py
View file @
38bca977
...
...
@@ -2,7 +2,7 @@
# Copyright (c) 2002-2015 Nexedi SA and Contributors. All Rights Reserved.
from
json
import
dumps
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
httplib
import
HTTPSConnection
from
six.moves.http_client
import
HTTPSConnection
from
erp5.component.mixin.RESTAPIClientConnectorMixin
import
RESTAPIClientConnectorMixin
from
ssl
import
SSLError
from
Products.ERP5Type.Timeout
import
TimeoutReachedError
...
...
@@ -71,11 +71,11 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with
mock
.
patch
(
'ssl.create_default_context'
,
)
as
mock_ssl_create_default_context
,
mock
.
patch
(
'
httplib
.HTTPSConnection.request'
,
'
six.moves.http_client
.HTTPSConnection.request'
,
)
as
mock_https_connection_request
,
mock
.
patch
(
'
httplib
.HTTPSConnection.getresponse'
,
'
six.moves.http_client
.HTTPSConnection.getresponse'
,
return_value
=
HTTPResponse_getresponse
()
),
mock
.
patch
(
'
httplib
.HTTPSConnection'
,
return_value
=
HTTPSConnection
)
as
mock_https_connection
:
),
mock
.
patch
(
'
six.moves.http_client
.HTTPSConnection'
,
return_value
=
HTTPSConnection
)
as
mock_https_connection
:
header_dict
,
body_dict
,
status
=
self
.
rest_api_client_connection
.
call
(
archive_resource
=
None
,
method
=
'POST'
,
...
...
@@ -145,9 +145,9 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with
mock
.
patch
(
'ssl.create_default_context'
,
),
mock
.
patch
(
'
httplib
.HTTPSConnection.request'
,
'
six.moves.http_client
.HTTPSConnection.request'
,
),
mock
.
patch
(
'
httplib
.HTTPSConnection.getresponse'
,
'
six.moves.http_client
.HTTPSConnection.getresponse'
,
return_value
=
HTTPResponse_getresponse
(
498
)
):
with
self
.
assertRaises
(
RESTAPIError
)
as
error
:
...
...
@@ -175,9 +175,9 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with
mock
.
patch
(
'ssl.create_default_context'
,
),
mock
.
patch
(
'
httplib
.HTTPSConnection.request'
,
'
six.moves.http_client
.HTTPSConnection.request'
,
),
mock
.
patch
(
'
httplib
.HTTPSConnection.getresponse'
,
'
six.moves.http_client
.HTTPSConnection.getresponse'
,
)
as
mock_https_connection_getresponse
:
mock_https_connection_getresponse
.
side_effect
=
SSLError
(
'The read operation timed out'
)
self
.
assertRaises
(
...
...
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