Skip to content

Commit 30ebe92

Browse files
committed
[MIG] endpoint: Migration to 19.0
1 parent 759e0ba commit 30ebe92

10 files changed

Lines changed: 124 additions & 131 deletions

File tree

endpoint/README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Endpoint
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
24-
:target: https://github.com/OCA/web-api/tree/18.0/endpoint
24+
:target: https://github.com/OCA/web-api/tree/19.0/endpoint
2525
:alt: OCA/web-api
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-endpoint
27+
:target: https://translation.odoo-community.org/projects/web-api-19-0/web-api-19-0-endpoint
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -66,7 +66,7 @@ Bug Tracker
6666
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
6767
In case of trouble, please check there if your issue has already been reported.
6868
If you spotted it first, help us to smash it by providing a detailed and welcomed
69-
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
69+
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7070

7171
Do not contact contributors directly about support or help with technical issues.
7272

@@ -82,6 +82,7 @@ Contributors
8282
------------
8383

8484
- Simone Orsi <simone.orsi@camptocamp.com>
85+
- Alex Garcia <alex@studio73.es>
8586

8687
Maintainers
8788
-----------
@@ -104,6 +105,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
104105

105106
|maintainer-simahawk|
106107

107-
This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/18.0/endpoint>`_ project on GitHub.
108+
This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/19.0/endpoint>`_ project on GitHub.
108109

109110
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

endpoint/__manifest__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Endpoint",
66
"summary": """Provide custom endpoint machinery.""",
7-
"version": "18.0.1.1.1",
7+
"version": "19.0.1.0.0",
88
"license": "LGPL-3",
99
"development_status": "Beta",
1010
"author": "Camptocamp,Odoo Community Association (OCA)",
@@ -17,7 +17,4 @@
1717
"security/ir_rule.xml",
1818
"views/endpoint_view.xml",
1919
],
20-
"demo": [
21-
"demo/endpoint_demo.xml",
22-
],
2320
}

endpoint/demo/endpoint_demo.xml

Lines changed: 0 additions & 84 deletions
This file was deleted.

endpoint/migrations/18.0.1.0.0/post-migrate.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

endpoint/models/endpoint_mixin.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import werkzeug
88

9-
from odoo import _, api, exceptions, fields, http, models
9+
from odoo import api, exceptions, fields, http, models
1010
from odoo.exceptions import UserError
1111
from odoo.tools import safe_eval
1212

@@ -75,14 +75,18 @@ def _validate_exec_mode(self):
7575
def _validate_exec__code(self):
7676
if not self._code_snippet_valued():
7777
raise UserError(
78-
_("Exec mode is set to `Code`: you must provide a piece of code")
78+
self.env._(
79+
"Exec mode is set to `Code`: you must provide a piece of code"
80+
)
7981
)
8082

8183
@api.constrains("auth_type")
8284
def _check_auth(self):
8385
for rec in self:
8486
if rec.auth_type == "public" and not rec.exec_as_user_id:
85-
raise UserError(_("'Exec as user' is mandatory for public endpoints."))
87+
raise UserError(
88+
self.env._("'Exec as user' is mandatory for public endpoints.")
89+
)
8690

8791
def _default_code_snippet_docs(self):
8892
return """
@@ -177,7 +181,7 @@ def _code_snippet_log_func(self, message, level="info"):
177181
(
178182
self.env.uid,
179183
"server",
180-
self._cr.dbname,
184+
self.env.cr.dbname,
181185
__name__,
182186
level,
183187
message,
@@ -192,11 +196,11 @@ def _handle_exec__code(self, request):
192196
return {}
193197
eval_ctx = self._get_code_snippet_eval_context(request)
194198
snippet = self.code_snippet
195-
safe_eval.safe_eval(snippet, eval_ctx, mode="exec", nocopy=True)
199+
safe_eval.safe_eval(snippet, eval_ctx, mode="exec")
196200
result = eval_ctx.get("result")
197201
if not isinstance(result, dict):
198202
raise exceptions.UserError(
199-
_("code_snippet should return a dict into `result` variable.")
203+
self.env._("code_snippet should return a dict into `result` variable.")
200204
)
201205
return result
202206

@@ -235,7 +239,7 @@ def _get_handler(self):
235239
return getattr(self, "_handle_exec__" + self.exec_mode)
236240
except AttributeError as e:
237241
raise UserError(
238-
_("Missing handler for exec mode %s") % self.exec_mode
242+
self.env._("Missing handler for exec mode %s", self.exec_mode)
239243
) from e
240244

241245
def _handle_request(self, request):

endpoint/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Simone Orsi \<<simone.orsi@camptocamp.com>\>
2+
- Alex Garcia \<<alex@studio73.es>\>

endpoint/static/description/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Endpoint</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:96cb1ce0681b1d235bbc6b73054c059b2bcc09b8966368052fe6773105665f6b
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web-api/tree/18.0/endpoint"><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-18-0/web-api-18-0-endpoint"><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=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web-api/tree/19.0/endpoint"><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-endpoint"><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>
378378
<p>Provide an endpoint framework allowing users to define their own custom
379379
endpoint.</p>
380380
<p>Thanks to endpoint mixin the endpoint records are automatically
@@ -413,7 +413,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
413413
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web-api/issues">GitHub Issues</a>.
414414
In case of trouble, please check there if your issue has already been reported.
415415
If you spotted it first, help us to smash it by providing a detailed and welcomed
416-
<a class="reference external" href="https://github.com/OCA/web-api/issues/new?body=module:%20endpoint%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
416+
<a class="reference external" href="https://github.com/OCA/web-api/issues/new?body=module:%20endpoint%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
417417
<p>Do not contact contributors directly about support or help with technical issues.</p>
418418
</div>
419419
<div class="section" id="credits">
@@ -428,6 +428,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
428428
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
429429
<ul class="simple">
430430
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simone.orsi&#64;camptocamp.com">simone.orsi&#64;camptocamp.com</a>&gt;</li>
431+
<li>Alex Garcia &lt;<a class="reference external" href="mailto:alex&#64;studio73.es">alex&#64;studio73.es</a>&gt;</li>
431432
</ul>
432433
</div>
433434
<div class="section" id="maintainers">
@@ -441,7 +442,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
441442
promote its widespread use.</p>
442443
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
443444
<p><a class="reference external image-reference" href="https://github.com/simahawk"><img alt="simahawk" src="https://github.com/simahawk.png?size=40px" /></a></p>
444-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web-api/tree/18.0/endpoint">OCA/web-api</a> project on GitHub.</p>
445+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web-api/tree/19.0/endpoint">OCA/web-api</a> project on GitHub.</p>
445446
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
446447
</div>
447448
</div>

endpoint/tests/common.py

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,101 @@
77
from odoo.tests.common import TransactionCase, tagged
88
from odoo.tools import DotDict
99

10-
from odoo.addons.website.tools import MockRequest
10+
from odoo.addons.http_routing.tests.common import MockRequest
11+
12+
13+
def _setup_demo_records(env):
14+
"""Create demo records for tests."""
15+
demo_user = env["res.users"].search([("login", "=", "demo")], limit=1)
16+
if not demo_user:
17+
demo_user = env["res.users"].create(
18+
{"login": "demo", "name": "Marc Demo", "group_ids": [(6, 0, [])]}
19+
)
20+
endpoints = env["endpoint.endpoint"]
21+
endpoints += env["endpoint.endpoint"].create(
22+
{
23+
"name": "Demo Endpoint 1",
24+
"route": "/demo/one",
25+
"request_method": "GET",
26+
"exec_mode": "code",
27+
"code_snippet": 'result = {"response": Response("ok")}',
28+
}
29+
)
30+
endpoints += env["endpoint.endpoint"].create(
31+
{
32+
"name": "Demo Endpoint 2",
33+
"route": "/demo/as_demo_user",
34+
"request_method": "GET",
35+
"auth_type": "public",
36+
"exec_as_user_id": demo_user.id,
37+
"exec_mode": "code",
38+
"code_snippet": (
39+
'result = {"response": Response("My name is: " + user.name)}'
40+
),
41+
}
42+
)
43+
endpoints += env["endpoint.endpoint"].create(
44+
{
45+
"name": "Demo Endpoint 3",
46+
"route": "/demo/json_data",
47+
"request_method": "GET",
48+
"auth_type": "public",
49+
"exec_as_user_id": demo_user.id,
50+
"exec_mode": "code",
51+
"code_snippet": 'result = {"payload": {"a": 1, "b": 2}}',
52+
}
53+
)
54+
endpoints += env["endpoint.endpoint"].create(
55+
{
56+
"name": "Demo Endpoint 4",
57+
"route": "/demo/raise_not_found",
58+
"request_method": "GET",
59+
"auth_type": "public",
60+
"exec_as_user_id": demo_user.id,
61+
"exec_mode": "code",
62+
"code_snippet": "raise werkzeug.exceptions.NotFound()",
63+
}
64+
)
65+
endpoints += env["endpoint.endpoint"].create(
66+
{
67+
"name": "Demo Endpoint 5",
68+
"route": "/demo/raise_validation_error",
69+
"request_method": "GET",
70+
"auth_type": "public",
71+
"exec_as_user_id": demo_user.id,
72+
"exec_mode": "code",
73+
"code_snippet": (
74+
'raise exceptions.ValidationError("Sorry, you cannot do this!")'
75+
),
76+
}
77+
)
78+
endpoints += env["endpoint.endpoint"].create(
79+
{
80+
"name": "Demo Endpoint 6",
81+
"route": "/demo/value_from_request",
82+
"request_method": "GET",
83+
"auth_type": "public",
84+
"exec_as_user_id": demo_user.id,
85+
"exec_mode": "code",
86+
"code_snippet": (
87+
'result = {"response": Response(request.params.get("your_name", ""))}'
88+
),
89+
}
90+
)
91+
endpoints += env["endpoint.endpoint"].create(
92+
{
93+
"name": "Demo Endpoint 7",
94+
"route": "/demo/bad_method",
95+
"request_method": "GET",
96+
"auth_type": "public",
97+
"exec_as_user_id": demo_user.id,
98+
"exec_mode": "code",
99+
"code_snippet": (
100+
'result = {"payload": "Method used:" + request.httprequest.method}'
101+
),
102+
}
103+
)
104+
return endpoints
11105

12106

13107
@tagged("-at_install", "post_install")
@@ -31,7 +125,7 @@ def _setup_context(cls):
31125

32126
@classmethod
33127
def _setup_records(cls):
34-
pass
128+
cls.endpoint = _setup_demo_records(cls.env)[0]
35129

36130
@contextlib.contextmanager
37131
def _get_mocked_request(

endpoint/tests/test_endpoint.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
class TestEndpoint(CommonEndpoint):
1919
@classmethod
2020
def _setup_records(cls):
21-
res = super()._setup_records()
22-
cls.endpoint = cls.env.ref("endpoint.endpoint_demo_1")
23-
return res
21+
return super()._setup_records()
2422

2523
@mute_logger("odoo.sql_db")
2624
def test_endpoint_unique(self):

0 commit comments

Comments
 (0)