Skip to content

Commit 617ca33

Browse files
committed
fixup! don't merge test-requirements
1 parent 7e625e3 commit 617ca33

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

endpoint_auth_api_key/tests/common.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Copyright 2026 Camptocamp SA
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3-
3+
import contextlib
44
from odoo import Command
55
from odoo.tests import tagged
6-
6+
from odoo.tools import DotDict
77
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
8+
from odoo.addons.http_routing.tests.common import MockRequest
89

910

1011
def _setup_demo_api_keys(env, demo_user):
@@ -81,11 +82,28 @@ def _setup_records(cls):
8182
)
8283
cls.api_keys = cls.api_key | cls.api_key2
8384

84-
cls.api_key_group = _setup_demo_api_key_group(
85+
cls.key_group = _setup_demo_api_key_group(
8586
cls.env,
8687
cls.api_keys,
8788
)
8889
cls.endpoint = _setup_demo_endpoint(
8990
cls.env,
90-
cls.api_key_group,
91+
cls.key_group,
9192
)
93+
94+
@contextlib.contextmanager
95+
def _get_mocked_request(
96+
self, httprequest=None, extra_headers=None, request_attrs=None
97+
):
98+
with MockRequest(self.env) as mocked_request:
99+
mocked_request.httprequest = (
100+
DotDict(httprequest) if httprequest else mocked_request.httprequest
101+
)
102+
headers = {}
103+
headers.update(extra_headers or {})
104+
mocked_request.httprequest.headers = headers
105+
request_attrs = request_attrs or {}
106+
for k, v in request_attrs.items():
107+
setattr(mocked_request, k, v)
108+
mocked_request.make_response = lambda data, **kw: data
109+
yield mocked_request

endpoint_auth_api_key/tests/test_endpoint.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,10 @@
77

88
from odoo.tools.misc import mute_logger
99

10-
from odoo.addons.endpoint.tests.common import CommonEndpoint
11-
1210
from .common import CommonEndpointAuthAPIKey
1311

1412

15-
class TestEndpoint(CommonEndpoint, CommonEndpointAuthAPIKey):
16-
@classmethod
17-
def _setup_records(cls):
18-
super()._setup_records()
19-
cls.endpoint = cls.env.ref("endpoint_auth_api_key.endpoint_demo_1")
20-
cls.key_group = cls.env.ref("endpoint_auth_api_key.auth_api_key_group_demo")
21-
cls.api_key = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo")
22-
cls.api_key2 = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo2")
23-
return
24-
13+
class TestEndpoint(CommonEndpointAuthAPIKey):
2514
@mute_logger("endpoint.endpoint")
2615
def test_endpoint_validate_request_no_key(self):
2716
endpoint = self.endpoint.copy(

0 commit comments

Comments
 (0)