[FIX] base_report_to_printer: Fixed tests

This commit is contained in:
Carlos Roca
2021-01-12 10:51:52 +01:00
parent 89d3a6c564
commit 943c59b2be
11 changed files with 46 additions and 33 deletions

View File

@@ -2,10 +2,12 @@
# Copyright 2016 SYLEAM
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock
from odoo.tests.common import TransactionCase
model = "odoo.addons.base.models.ir_actions_report.IrActionsReport"
class TestIrActionsReportXml(TransactionCase):
def setUp(self):
@@ -53,14 +55,14 @@ class TestIrActionsReportXml(TransactionCase):
def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
with mock.patch("%s._get_report_from_name" % model) as mk:
expect = "test"
self.Model.print_action_for_report_name(expect)
mk.assert_called_once_with(expect)
def test_print_action_for_report_name_returns_if_no_report(self):
""" It should return empty dict when no matching report """
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
with mock.patch("%s._get_report_from_name" % model) as mk:
expect = "test"
mk.return_value = False
res = self.Model.print_action_for_report_name(expect)
@@ -68,7 +70,7 @@ class TestIrActionsReportXml(TransactionCase):
def test_print_action_for_report_name_returns_if_report(self):
""" It should return correct serializable result for behaviour """
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
with mock.patch("%s._get_report_from_name" % model) as mk:
res = self.Model.print_action_for_report_name("test")
behaviour = mk().behaviour()
expect = {

View File

@@ -1,7 +1,7 @@
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock
from odoo import fields
from odoo.tests.common import TransactionCase

View File

@@ -2,8 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import tempfile
import mock
from unittest import mock
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase

View File

@@ -3,8 +3,7 @@
import errno
import tempfile
import mock
from unittest import mock
from odoo.tests.common import TransactionCase

View File

@@ -1,7 +1,7 @@
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
@@ -15,7 +15,7 @@ class StopTest(Exception):
class TestPrintingPrinterWizard(TransactionCase):
def setUp(self):
super(TestPrintingPrinterWizard, self).setUp()
super().setUp()
self.Model = self.env["printing.printer.update.wizard"]
self.server = self.env["printing.server"].create({})
self.printer_vals = {

View File

@@ -1,12 +1,13 @@
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock
from odoo import fields
from odoo.tests.common import TransactionCase
model = "odoo.addons.base_report_to_printer.models.printing_server"
model_base = "odoo.models.BaseModel"
class TestPrintingServer(TransactionCase):
@@ -69,14 +70,14 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_printers_search(self, cups):
""" It should search all when no domain """
with mock.patch.object(self.Model, "search") as search:
with mock.patch("%s.search" % model_base) as search:
self.Model.update_printers()
search.assert_called_once_with([])
@mock.patch("%s.cups" % model)
def test_update_printers_search_domain(self, cups):
""" It should use specific domain for search """
with mock.patch.object(self.Model, "search") as search:
with mock.patch("%s.search" % model_base) as search:
expect = [("id", ">", 0)]
self.Model.update_printers(expect)
search.assert_called_once_with(expect)
@@ -89,6 +90,19 @@ class TestPrintingServer(TransactionCase):
self.Model.action_update_printers()
self.assertEqual("unavailable", rec_id.status)
@mock.patch("%s.cups" % model)
def test_update_archived_printers(self, cups):
""" It should update status even if printer is archived """
rec_id = self.new_printer()
rec_id.toggle_active()
self.server.refresh()
cups.Connection().getPrinters().get.return_value = False
self.Model.action_update_printers()
self.assertEqual(
"unavailable",
rec_id.status,
)
@mock.patch("%s.cups" % model)
def test_update_jobs_cron(self, cups):
""" It should get all jobs from CUPS server """

View File

@@ -2,14 +2,12 @@
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from unittest import mock
from odoo import exceptions
from odoo.tests import common
@common.at_install(False)
@common.post_install(True)
class TestReport(common.HttpCase):
def setUp(self):
super(TestReport, self).setUp()
@@ -20,21 +18,23 @@ class TestReport(common.HttpCase):
"model": "ir.actions.report",
"report_name": "Test Report",
}
self.report_imd = self.env["ir.model.data"].create(
{"name": "test", "module": "base_report_to_printer", "model": "ir.ui.view"}
)
self.report_view = self.env["ir.ui.view"].create(
{
"name": "Test",
"type": "qweb",
"xml_id": "base_report_to_printer.test",
"model_data_id": self.report_imd.id,
"arch": """<t t-name="base_report_to_printer.test">
<div>Test</div>
</t>""",
}
)
self.report_imd.res_id = self.report_view.id
self.report_imd = self.env["ir.model.data"].create(
{
"name": "test",
"module": "base_report_to_printer",
"model": "ir.ui.view",
"res_id": self.report_view.id,
}
)
self.report = self.Model.create(
{
"name": "Test",
@@ -88,7 +88,7 @@ class TestReport(common.HttpCase):
"printing_printer.PrintingPrinter."
"print_document"
) as print_document:
self.report.render_qweb_pdf(self.partners.ids)
self.report._render_qweb_pdf(self.partners.ids)
print_document.assert_not_called()
def test_render_qweb_pdf_printable(self):
@@ -100,7 +100,7 @@ class TestReport(common.HttpCase):
) as print_document:
self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer()
document = self.report.render_qweb_pdf(self.partners.ids)
document = self.report._render_qweb_pdf(self.partners.ids)
print_document.assert_called_once_with(
self.report,
document[0],

View File

@@ -4,8 +4,6 @@
from odoo.tests import common
@common.at_install(False)
@common.post_install(True)
class TestResUsers(common.TransactionCase):
def setUp(self):
super(TestResUsers, self).setUp()