From 2830a940e3e0481b1656ce23d92ff4a9a32715cb Mon Sep 17 00:00:00 2001 From: "matthieu.saison" Date: Mon, 11 Sep 2023 14:32:19 +0200 Subject: [PATCH 1/2] fix authenticated_partner_impl when no partner --- fastapi/tests/common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fastapi/tests/common.py b/fastapi/tests/common.py index 50b8c689..0072e44c 100644 --- a/fastapi/tests/common.py +++ b/fastapi/tests/common.py @@ -1,7 +1,6 @@ # Copyright 2023 ACSONE SA/NV # License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). from contextlib import contextmanager -from functools import partial from typing import Any, Callable, Dict from odoo.api import Environment @@ -94,8 +93,7 @@ def _create_test_client( if user: env = env(user=user) partner = partner or self.default_fastapi_authenticated_partner - if partner: - dependencies[authenticated_partner_impl] = partial(lambda a: a, partner) + dependencies[authenticated_partner_impl] = lambda: partner app = app or self.default_fastapi_app or FastAPI() router = router or self.default_fastapi_router if router: From aba642fad4a041a4923d28a289273cca1fc511ce Mon Sep 17 00:00:00 2001 From: "matthieu.saison" Date: Mon, 25 Sep 2023 09:42:37 +0200 Subject: [PATCH 2/2] review change --- fastapi/tests/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fastapi/tests/common.py b/fastapi/tests/common.py index 0072e44c..80e70cfc 100644 --- a/fastapi/tests/common.py +++ b/fastapi/tests/common.py @@ -1,6 +1,7 @@ # Copyright 2023 ACSONE SA/NV # License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). from contextlib import contextmanager +from functools import partial from typing import Any, Callable, Dict from odoo.api import Environment @@ -92,8 +93,12 @@ def _create_test_client( dependencies.update(dependency_overrides) if user: env = env(user=user) - partner = partner or self.default_fastapi_authenticated_partner - dependencies[authenticated_partner_impl] = lambda: partner + partner = ( + partner + or self.default_fastapi_authenticated_partner + or self.env["res.partner"] + ) + dependencies[authenticated_partner_impl] = partial(lambda a: a, partner) app = app or self.default_fastapi_app or FastAPI() router = router or self.default_fastapi_router if router: