22# @author Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
33# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44import json
5- import os
65import time
7- from unittest import mock
86from urllib .parse import quote
97
108import responses
119from oauthlib .oauth2 .rfc6749 .errors import InvalidGrantError
1210
1311from 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-
1813from .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