Skip to content

Commit

Permalink
[FIX] base_report_to_printer: Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 authored and flachica committed Oct 1, 2022
1 parent 689502d commit 181f484
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 49 deletions.
10 changes: 5 additions & 5 deletions base_report_to_printer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Report to printer
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github
:target: https://github.com/OCA/report-print-send/tree/13.0/base_report_to_printer
:target: https://github.com/OCA/report-print-send/tree/14.0/base_report_to_printer
:alt: OCA/report-print-send
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/report-print-send-13-0/report-print-send-13-0-base_report_to_printer
:target: https://translation.odoo-community.org/projects/report-print-send-14-0/report-print-send-14-0-base_report_to_printer
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/144/13.0
:target: https://runbot.odoo-community.org/runbot/144/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -113,7 +113,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/report-print-send/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -159,6 +159,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/report-print-send <https://github.com/OCA/report-print-send/tree/13.0/base_report_to_printer>`_ project on GitHub.
This module is part of the `OCA/report-print-send <https://github.com/OCA/report-print-send/tree/14.0/base_report_to_printer>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
23 changes: 15 additions & 8 deletions base_report_to_printer/i18n/base_report_to_printer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -35,6 +35,7 @@ msgstr ""

#. module: base_report_to_printer
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_job__active
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer__active
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_server__active
msgid "Active"
msgstr ""
Expand All @@ -44,6 +45,11 @@ msgstr ""
msgid "Address"
msgstr ""

#. module: base_report_to_printer
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.printing_printer_view_search
msgid "Archived"
msgstr ""

#. module: base_report_to_printer
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.printing_printer_view_form
msgid "Are you sure to want to cancel all jobs of this printer?"
Expand Down Expand Up @@ -224,13 +230,15 @@ msgid "Disable"
msgstr ""

#. module: base_report_to_printer
#: model:ir.model.fields,field_description:base_report_to_printer.field_ir_actions_report__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_action__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_job__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer_update_wizard__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_report_xml_action__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_server__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_tray__display_name
#: model:ir.model.fields,field_description:base_report_to_printer.field_res_users__display_name
msgid "Display Name"
msgstr ""

Expand Down Expand Up @@ -292,13 +300,15 @@ msgid "Held because the printer is offline"
msgstr ""

#. module: base_report_to_printer
#: model:ir.model.fields,field_description:base_report_to_printer.field_ir_actions_report__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_action__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_job__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer_update_wizard__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_report_xml_action__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_server__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_tray__id
#: model:ir.model.fields,field_description:base_report_to_printer.field_res_users__id
msgid "ID"
msgstr ""

Expand Down Expand Up @@ -339,13 +349,15 @@ msgid "Jobs printed on this printer."
msgstr ""

#. module: base_report_to_printer
#: model:ir.model.fields,field_description:base_report_to_printer.field_ir_actions_report____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_action____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_job____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_printer_update_wizard____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_report_xml_action____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_server____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_printing_tray____last_update
#: model:ir.model.fields,field_description:base_report_to_printer.field_res_users____last_update
msgid "Last Modified on"
msgstr ""

Expand Down Expand Up @@ -522,7 +534,6 @@ msgstr ""
#: model:ir.model.fields.selection,name:base_report_to_printer.selection__printing_printer__status__printing
#: model:ir.ui.menu,name:base_report_to_printer.printing_menu
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.view_users_form
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.view_users_form_simple_modif
msgid "Printing"
msgstr ""

Expand Down Expand Up @@ -703,7 +714,8 @@ msgstr ""
#. module: base_report_to_printer
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.printer_update_wizard
msgid ""
"This process will create all missing printers from the current CUPS server."
"This process will create all missing printers from the current CUPS "
"server.\""
msgstr ""

#. module: base_report_to_printer
Expand Down Expand Up @@ -795,8 +807,3 @@ msgstr ""
#: model:ir.model,name:base_report_to_printer.model_res_users
msgid "Users"
msgstr ""

#. module: base_report_to_printer
#: model_terms:ir.ui.view,arch_db:base_report_to_printer.printer_update_wizard
msgid "or"
msgstr ""
6 changes: 3 additions & 3 deletions base_report_to_printer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def print_document(self, record_ids, data=None):
""" Print a document, do not return the document file """
document, doc_format = self.with_context(
must_skip_send_to_printer=True
).render_qweb_pdf(record_ids, data=data)
)._render_qweb_pdf(record_ids, data=data)
behaviour = self.behaviour()
printer = behaviour.pop("printer", None)

Expand Down Expand Up @@ -129,13 +129,13 @@ def report_action(self, docids, data=None, config=True):
res["id"] = self.id
return res

def render_qweb_pdf(self, res_ids=None, data=None):
def _render_qweb_pdf(self, res_ids=None, data=None):
"""Generate a PDF and returns it.
If the action configured on the report is server, it prints the
generated document as well.
"""
document, doc_format = super().render_qweb_pdf(res_ids=res_ids, data=data)
document, doc_format = super()._render_qweb_pdf(res_ids=res_ids, data=data)

behaviour = self.behaviour()
printer = behaviour.pop("printer", None)
Expand Down
5 changes: 2 additions & 3 deletions base_report_to_printer/models/printing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_printers(self, domain=None, raise_on_error=False):
servers = self.search(domain)

res = True
for server in servers:
for server in servers.with_context(active_test=False):
connection = server._open_connection(raise_on_error=raise_on_error)
if not connection:
server.printer_ids.write({"status": "server-error"})
Expand All @@ -71,8 +71,7 @@ def update_printers(self, domain=None, raise_on_error=False):
# Update Printers
printers = connection.getPrinters()
existing_printers = {
printer.system_name: printer
for printer in server.with_context(active_test=False).printer_ids
printer.system_name: printer for printer in server.printer_ids
}
updated_printers = []
for name, printer_info in printers.items():
Expand Down
6 changes: 3 additions & 3 deletions base_report_to_printer/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Report to printer</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/report-print-send/tree/13.0/base_report_to_printer"><img alt="OCA/report-print-send" src="https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/report-print-send-13-0/report-print-send-13-0-base_report_to_printer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/144/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/report-print-send/tree/14.0/base_report_to_printer"><img alt="OCA/report-print-send" src="https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/report-print-send-14-0/report-print-send-14-0-base_report_to_printer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/144/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows users to send reports to a printer attached to the server.</p>
<p>It adds an optional behaviour on reports to send it directly to a printer.</p>
<ul class="simple">
Expand Down Expand Up @@ -467,7 +467,7 @@ <h1><a class="toc-backref" href="#id9">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/report-print-send/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -507,7 +507,7 @@ <h2><a class="toc-backref" href="#id13">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/report-print-send/tree/13.0/base_report_to_printer">OCA/report-print-send</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/report-print-send/tree/14.0/base_report_to_printer">OCA/report-print-send</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions base_report_to_printer/tests/test_ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -53,22 +55,22 @@ def new_tray(self, vals=None, defaults=None):

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)
self.assertDictEqual({}, res)

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 = {
Expand Down
2 changes: 1 addition & 1 deletion base_report_to_printer/tests/test_printing_job.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions base_report_to_printer/tests/test_printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions base_report_to_printer/tests/test_printing_printer_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import errno
import tempfile

import mock
from unittest import mock

from odoo.tests.common import TransactionCase

Expand Down
4 changes: 2 additions & 2 deletions base_report_to_printer/tests/test_printing_printer_wizard.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = {
Expand Down
20 changes: 17 additions & 3 deletions base_report_to_printer/tests/test_printing_server.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -69,14 +70,14 @@ def test_update_printers_gets_all_printers(self, cups):
@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)
Expand All @@ -89,6 +90,19 @@ def test_update_printers_update_unavailable(self, cups):
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 """
Expand Down
Loading

0 comments on commit 181f484

Please sign in to comment.