Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions webservice/components/request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def _request(self, method, url=None, url_params=None, **kwargs):
{
"auth": self._get_auth(**kwargs),
"headers": self._get_headers(**kwargs),
"timeout": None,
}
)
# pylint: disable=E8106
Expand Down Expand Up @@ -211,7 +210,6 @@ def _request(self, method, url=None, url_params=None, **kwargs):
new_kwargs.update(
{
"headers": self._get_headers(**kwargs),
"timeout": None,
}
)
client = BackendApplicationClient(client_id=self.collection.oauth2_clientid)
Expand Down
2 changes: 1 addition & 1 deletion webservice/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setUpClass(cls):
@classmethod
def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw):
if urlparse(r.url).netloc in ("localhost.demo.odoo", "custom.url"):
return cls._super_send(s, r)
return cls._super_send(s, r, **kw)
return super()._request_handler(s, r, **kw)


Expand Down
3 changes: 2 additions & 1 deletion webservice/tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_fetch_token(self):
)
responses.add(responses.GET, f"{self.url}endpoint", body="OK")
with mock_cursor(self.env.cr):
result = self.webservice.call("get", url=f"{self.url}endpoint")
result = self.webservice.call("get", url=f"{self.url}endpoint", timeout=10)
self.webservice.invalidate_recordset()
self.assertEqual(len(responses.calls), 2)
call_token = json.loads(responses.calls[0].response.content.decode())
Expand All @@ -71,6 +71,7 @@ def test_fetch_token(self):
)
self.assertEqual(responses.calls[1].response.content.decode(), "OK")
self.assertEqual(result.decode(), "OK")
self.assertEqual(responses.calls[-1].request.req_kwargs["timeout"], 10)

@responses.activate
def test_update_token(self):
Expand Down
4 changes: 2 additions & 2 deletions webservice/views/webservice_backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
<field
name="oauth2_scope"
invisible="auth_type != 'oauth2' or oauth2_flow != 'web_application'"
required="auth_type == 'oauth2' and oauth2_flow == 'authorization_code'"
required="auth_type == 'oauth2' and oauth2_flow == 'web_application'"
/>
<field
name="oauth2_authorization_url"
invisible="auth_type != 'oauth2' or oauth2_flow != 'web_application'"
required="auth_type == 'oauth2' and oauth2_flow == 'authorization_code'"
required="auth_type == 'oauth2' and oauth2_flow == 'web_application'"
/>
<field
name="oauth2_token_url"
Expand Down
3 changes: 3 additions & 0 deletions webservice_server_env/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ WebService Server Environment
Glue module to make Server Environment features available for the
Webservice addon.

It is not installed automatically: install it explicitly to manage the
webservice backends via the server environment.

**Table of contents**

.. contents::
Expand Down
1 change: 0 additions & 1 deletion webservice_server_env/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
"depends": ["web", "webservice", "server_environment"],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
"auto_install": True,
}
3 changes: 3 additions & 0 deletions webservice_server_env/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Glue module to make Server Environment features available for the
Webservice addon.

It is not installed automatically: install it explicitly to manage the
webservice backends via the server environment.
2 changes: 2 additions & 0 deletions webservice_server_env/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ <h1>WebService Server Environment</h1>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web-api/tree/19.0/webservice_server_env"><img alt="OCA/web-api" src="https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-api-19-0/web-api-19-0-webservice_server_env"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web-api&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Glue module to make Server Environment features available for the
Webservice addon.</p>
<p>It is not installed automatically: install it explicitly to manage the
webservice backends via the server environment.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down
30 changes: 30 additions & 0 deletions webservice_server_env/tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def test_oauth2_flow_compute_with_ui(self):
ws_form.oauth2_clientid = "Test Client ID"
ws_form.oauth2_client_secret = "Test Client Secret"
ws_form.oauth2_token_url = f"{url}oauth2/token"
if oauth2_flow == "web_application":
ws_form.oauth2_scope = "Test Scope"
ws_form.oauth2_authorization_url = f"{url}oauth2/auth"
if auth_type == "user_pwd":
ws_form.username = "Test Username"
ws_form.password = "Test Password"
Expand All @@ -131,9 +134,36 @@ def test_oauth2_flow_compute_with_ui(self):
ws_form.oauth2_clientid = "Test Client ID"
ws_form.oauth2_client_secret = "Test Client Secret"
ws_form.oauth2_token_url = f"{url}oauth2/token"
if oauth2_flow == "web_application":
ws_form.oauth2_scope = "Test Scope"
ws_form.oauth2_authorization_url = f"{url}oauth2/auth"
ws = ws_form.save()
# Check that ``oauth2_flow`` is the expected one after update only if the
# ``auth_type`` is "oauth2", else it should be False
self.assertEqual(
ws.oauth2_flow, oauth2_flow if ws.auth_type == "oauth2" else False
)

def test_web_application_required_fields_with_ui(self):
"""The authorization URL and the scope are required for the web
application flow, the authorization redirect needs them."""
ws_form = Form(
self.webservice.browse(), "webservice.webservice_backend_form_view"
)
ws_form.name = "WebService Test UI"
ws_form.tech_name = "webservice_test_ui_web_application"
ws_form.protocol = "http"
ws_form.url = self.url
ws_form.auth_type = "oauth2"
ws_form.oauth2_flow = "web_application"
ws_form.oauth2_clientid = "Test Client ID"
ws_form.oauth2_client_secret = "Test Client Secret"
ws_form.oauth2_token_url = f"{self.url}oauth2/token"
with self.assertRaisesRegex(AssertionError, "oauth2_scope"):
ws_form.save()
ws_form.oauth2_scope = "Test Scope"
with self.assertRaisesRegex(AssertionError, "oauth2_authorization_url"):
ws_form.save()
ws_form.oauth2_authorization_url = f"{self.url}oauth2/auth"
ws = ws_form.save()
self.assertEqual(ws.oauth2_authorization_url, f"{self.url}oauth2/auth")
Loading