Skip to content

Commit

Permalink
[FIX] printing_auto_base: use odoo_test_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Dec 11, 2024
1 parent 221d2f8 commit 690f7c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
25 changes: 3 additions & 22 deletions printing_auto_base/tests/model_test.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
14 changes: 10 additions & 4 deletions printing_auto_base/tests/test_printing_auto_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@

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)
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):
Expand Down

0 comments on commit 690f7c3

Please sign in to comment.