From 690f7c32b2fc5eab137605ef9ef5c88af3cb00c4 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Fri, 6 Dec 2024 15:40:43 +0100 Subject: [PATCH] [FIX] printing_auto_base: use odoo_test_helper --- printing_auto_base/tests/model_test.py | 25 +++---------------- .../tests/test_printing_auto_base.py | 14 ++++++++--- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/printing_auto_base/tests/model_test.py b/printing_auto_base/tests/model_test.py index 3cf729ba9ab..61bac3f916c 100644 --- a/printing_auto_base/tests/model_test.py +++ b/printing_auto_base/tests/model_test.py @@ -1,26 +1,7 @@ -from odoo import fields, models - - -def setup_test_model(env, model_cls): - """Pass a test model class and initialize it. - - Courtesy of SBidoul from https://github.com/OCA/mis-builder :) - """ - model_cls._build_model(env.registry, env.cr) - env.registry.setup_models(env.cr) - env.registry.init_models( - env.cr, [model_cls._name], dict(env.context, update_custom_fields=True) - ) +# Copyright 2023 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -def teardown_test_model(env, model_cls): - """Pass a test model class and deinitialize it. - - Courtesy of SBidoul from https://github.com/OCA/mis-builder :) - """ - if not getattr(model_cls, "_teardown_no_delete", False): - del env.registry.models[model_cls._name] - env.registry.setup_models(env.cr) +from odoo import fields, models class PrintingAutoTesterChild(models.Model): diff --git a/printing_auto_base/tests/test_printing_auto_base.py b/printing_auto_base/tests/test_printing_auto_base.py index c88b10d1318..fce32e202ed 100644 --- a/printing_auto_base/tests/test_printing_auto_base.py +++ b/printing_auto_base/tests/test_printing_auto_base.py @@ -4,10 +4,13 @@ from unittest import mock +from odoo_test_helper import FakeModelLoader + from odoo.exceptions import UserError, ValidationError -from .common import PrintingPrinter, TestPrintingAutoCommon, print_document -from .model_test import PrintingAutoTester, PrintingAutoTesterChild, setup_test_model +from odoo.addons.base_report_to_printer.models.printing_printer import PrintingPrinter + +from .common import TestPrintingAutoCommon, print_document @mock.patch.object(PrintingPrinter, "print_document", print_document) @@ -15,8 +18,11 @@ class TestPrintingAutoBase(TestPrintingAutoCommon): @classmethod def setUpClass(cls): super().setUpClass() - setup_test_model(cls.env, PrintingAutoTesterChild) - setup_test_model(cls.env, PrintingAutoTester) + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .model_test import PrintingAutoTester, PrintingAutoTesterChild + + cls.loader.update_registry((PrintingAutoTesterChild, PrintingAutoTester)) def test_check_data_source(self): with self.assertRaises(UserError):