Skip to content

Commit 8dda582

Browse files
committed
[REF] webservice: server_environment should not be a required dependency
1 parent b49f2c9 commit 8dda582

File tree

3 files changed

+3
-93
lines changed

3 files changed

+3
-93
lines changed

webservice/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"maintainers": ["etobella"],
1313
"author": "Creu Blanca, Camptocamp, Odoo Community Association (OCA)",
1414
"website": "https://github.com/OCA/web-api",
15-
"depends": ["component", "server_environment"],
16-
"external_dependencies": {"python": ["requests-oauthlib", "oauthlib", "responses"]},
15+
"depends": ["component"],
16+
"external_dependencies": {"python": ["requests-oauthlib", "oauthlib"]},
1717
"data": [
1818
"security/ir.model.access.csv",
1919
"security/ir_rule.xml",

webservice/models/webservice_backend.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class WebserviceBackend(models.Model):
1515
_name = "webservice.backend"
16-
_inherit = ["collection.base", "server.env.techname.mixin", "server.env.mixin"]
16+
_inherit = ["collection.base"]
1717
_description = "WebService Backend"
1818

1919
name = fields.Char(required=True)
@@ -145,33 +145,3 @@ def button_authorize(self):
145145
"url": authorize_url,
146146
"target": "self",
147147
}
148-
149-
@property
150-
def _server_env_fields(self):
151-
base_fields = super()._server_env_fields
152-
webservice_fields = {
153-
"protocol": {},
154-
"url": {},
155-
"auth_type": {},
156-
"username": {},
157-
"password": {},
158-
"api_key": {},
159-
"api_key_header": {},
160-
"content_type": {},
161-
"oauth2_flow": {},
162-
"oauth2_scope": {},
163-
"oauth2_clientid": {},
164-
"oauth2_client_secret": {},
165-
"oauth2_authorization_url": {},
166-
"oauth2_token_url": {},
167-
"oauth2_audience": {},
168-
}
169-
webservice_fields.update(base_fields)
170-
return webservice_fields
171-
172-
def _compute_server_env(self):
173-
# OVERRIDE: reset ``oauth2_flow`` when ``auth_type`` is not "oauth2", even if
174-
# defined otherwise in server env vars
175-
res = super()._compute_server_env()
176-
self.filtered(lambda r: r.auth_type != "oauth2").oauth2_flow = None
177-
return res

webservice/tests/test_oauth2.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22
# @author Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44
import json
5-
import os
65
import time
7-
from unittest import mock
86
from urllib.parse import quote
97

108
import responses
119
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
1210

1311
from odoo.tests import Form
1412

15-
from odoo.addons.server_environment import server_env
16-
from odoo.addons.server_environment.models import server_env_mixin
17-
1813
from .common import CommonWebService, mock_cursor
1914

2015

@@ -23,17 +18,6 @@ class TestWebServiceOauth2BackendApplication(CommonWebService):
2318
def _setup_records(cls):
2419
res = super()._setup_records()
2520
cls.url = "https://localhost.demo.odoo/"
26-
os.environ["SERVER_ENV_CONFIG"] = "\n".join(
27-
[
28-
"[webservice_backend.test_oauth2_back]",
29-
"auth_type = oauth2",
30-
"oauth2_flow = backend_application",
31-
"oauth2_clientid = some_client_id",
32-
"oauth2_client_secret = shh_secret",
33-
f"oauth2_token_url = {cls.url}oauth2/token",
34-
f"oauth2_audience = {cls.url}",
35-
]
36-
)
3721
cls.webservice = cls.env["webservice.backend"].create(
3822
{
3923
"name": "WebService OAuth2",
@@ -172,18 +156,6 @@ class TestWebServiceOauth2WebApplication(CommonWebService):
172156
def _setup_records(cls):
173157
res = super()._setup_records()
174158
cls.url = "https://localhost.demo.odoo/"
175-
os.environ["SERVER_ENV_CONFIG"] = "\n".join(
176-
[
177-
"[webservice_backend.test_oauth2_web]",
178-
"auth_type = oauth2",
179-
"oauth2_flow = web_application",
180-
"oauth2_clientid = some_client_id",
181-
"oauth2_client_secret = shh_secret",
182-
f"oauth2_token_url = {cls.url}oauth2/token",
183-
f"oauth2_audience = {cls.url}",
184-
f"oauth2_authorization_url = {cls.url}authorize",
185-
]
186-
)
187159
cls.webservice = cls.env["webservice.backend"].create(
188160
{
189161
"name": "WebService OAuth2",
@@ -246,38 +218,6 @@ def test_fetch_token_from_auth(self):
246218
)
247219
self.assertEqual("cool_token", token["access_token"])
248220

249-
def test_oauth2_flow_compute_with_server_env(self):
250-
"""Check the ``compute`` method when updating server envs"""
251-
ws = self.webservice
252-
url = self.url
253-
for auth_type, oauth2_flow in [
254-
(tp, fl)
255-
for tp in ws._fields["auth_type"].get_values(ws.env)
256-
for fl in ws._fields["oauth2_flow"].get_values(ws.env)
257-
]:
258-
# Update env with current ``auth_type`` and ``oauth2_flow``
259-
with mock.patch.dict(
260-
os.environ,
261-
{
262-
"SERVER_ENV_CONFIG": f"""
263-
[webservice_backend.test_oauth2_web]
264-
auth_type = {auth_type}
265-
oauth2_flow = {oauth2_flow}
266-
oauth2_clientid = some_client_id
267-
oauth2_client_secret = shh_secret
268-
oauth2_token_url = {url}oauth2/token
269-
oauth2_audience = {url}
270-
oauth2_authorization_url = {url}/authorize
271-
""",
272-
},
273-
):
274-
server_env_mixin.serv_config = server_env._load_config() # Reload vars
275-
ws.invalidate_recordset() # Avoid reading from cache
276-
if auth_type == "oauth2":
277-
self.assertEqual(ws.oauth2_flow, oauth2_flow)
278-
else:
279-
self.assertFalse(ws.oauth2_flow)
280-
281221
def test_oauth2_flow_compute_with_ui(self):
282222
"""Check the ``compute`` method when updating WS from UI"""
283223
ws = self.webservice

0 commit comments

Comments
 (0)