mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[FIX] printing_auto_base: use odoo_test_helper
This commit is contained in:
@@ -1,28 +1,9 @@
|
|||||||
|
# Copyright 2023 Camptocamp
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import fields, models
|
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class PrintingAutoTesterChild(models.Model):
|
class PrintingAutoTesterChild(models.Model):
|
||||||
_name = "printingauto.tester.child"
|
_name = "printingauto.tester.child"
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
from odoo_test_helper import FakeModelLoader
|
||||||
|
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
|
|
||||||
from .common import PrintingPrinter, TestPrintingAutoCommon, print_document
|
from odoo.addons.base_report_to_printer.models.printing_printer import PrintingPrinter
|
||||||
from .model_test import PrintingAutoTester, PrintingAutoTesterChild, setup_test_model
|
|
||||||
|
from .common import TestPrintingAutoCommon, print_document
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(PrintingPrinter, "print_document", print_document)
|
@mock.patch.object(PrintingPrinter, "print_document", print_document)
|
||||||
@@ -15,8 +18,11 @@ class TestPrintingAutoBase(TestPrintingAutoCommon):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
setup_test_model(cls.env, PrintingAutoTesterChild)
|
cls.loader = FakeModelLoader(cls.env, cls.__module__)
|
||||||
setup_test_model(cls.env, PrintingAutoTester)
|
cls.loader.backup_registry()
|
||||||
|
from .model_test import PrintingAutoTester, PrintingAutoTesterChild
|
||||||
|
|
||||||
|
cls.loader.update_registry((PrintingAutoTesterChild, PrintingAutoTester))
|
||||||
|
|
||||||
def test_check_data_source(self):
|
def test_check_data_source(self):
|
||||||
with self.assertRaises(UserError):
|
with self.assertRaises(UserError):
|
||||||
|
|||||||
1
test-requirements.txt
Normal file
1
test-requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
odoo-test-helper
|
||||||
Reference in New Issue
Block a user