|
1 | 1 | # Copyright 2021 ACSONE SA/NV |
2 | 2 | # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). |
3 | 3 | from odoo.addons.component.core import Component |
4 | | -from odoo.addons.website.tools import MockRequest |
| 4 | +from odoo.addons.http_routing.tests.common import MockRequest |
5 | 5 |
|
6 | 6 | from .. import restapi |
7 | 7 | from .common import BaseRestCase, TransactionRestServiceRegistryCase |
@@ -79,25 +79,37 @@ class TestServiceNewApi(Component): |
79 | 79 | _collection = self._collection_name |
80 | 80 | _description = "test" |
81 | 81 |
|
| 82 | + def _get_partner_schema(self): |
| 83 | + return {"name": {"type": "string", "required": True}} |
| 84 | + |
82 | 85 | @restapi.method( |
83 | 86 | [(["/<int:id>/get", "/<int:id>"], "GET")], |
84 | 87 | output_param=restapi.CerberusValidator("_get_partner_schema"), |
85 | 88 | auth="public", |
86 | 89 | ) |
87 | 90 | def get(self, _id): |
88 | | - return {"name": self.env["res.partner"].browse(_id).name} |
| 91 | + return {"name": self.env["res.partner"].browse(_id).exists().name} |
89 | 92 |
|
90 | 93 | self._build_components(TestComponentContextprovider) |
91 | 94 | self._build_services(self, TestServiceNewApi) |
92 | 95 | controller = self._get_controller_for(TestServiceNewApi) |
93 | | - service_component = controller().service_component |
| 96 | + controller_instance = controller() |
| 97 | + service_component = controller_instance.service_component |
94 | 98 | with ( |
95 | | - MockRequest(self.env), |
| 99 | + self.with_user("admin"), |
| 100 | + MockRequest(self.env) as request, |
96 | 101 | service_component(service_name="partner") as service, |
97 | 102 | ): |
| 103 | + # Required for logging REST methods. |
| 104 | + request.httprequest.headers = {} |
98 | 105 | self.assertEqual( |
99 | 106 | service.work.authenticated_partner_id, self.env.user.partner_id.id |
100 | 107 | ) |
| 108 | + # Actually testing if the rules are computed correctly by calling |
| 109 | + # the controller method itself. |
| 110 | + controller_instance._process_method( |
| 111 | + "partner", "get", self.env.user.company_id.partner_id.id |
| 112 | + ) |
101 | 113 |
|
102 | 114 | def test_03(self): |
103 | 115 | """Test authenticated_partner_id |
@@ -147,4 +159,4 @@ def get(self, _id): |
147 | 159 | class CommonCase(BaseRestCase): |
148 | 160 | # dummy test method to pass codecov |
149 | 161 | def test_04(self): |
150 | | - self.assertEqual(self.registry.test_cr, self.cr) |
| 162 | + self.assertEqual(self.registry.db_name, self.cr.dbname) |
0 commit comments