Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Nov 19, 2024
1 parent 4fd9a30 commit efb17dd
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions base_report_to_printer/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from unittest import mock

from odoo import exceptions
Expand Down Expand Up @@ -128,11 +129,14 @@ def test_render_qweb_pdf_not_printable(self):

def test_render_qweb_pdf_printable(self):
"""It should print the report, only if it is printable"""
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document:
with (
mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document,
self.assertLogs(level=logging.WARNING) as logs,
):
self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer()
document = self.report._render_qweb_pdf(
Expand All @@ -145,14 +149,19 @@ def test_render_qweb_pdf_printable(self):
doc_format="qweb-pdf",
tray=False,
)
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)

def test_render_qweb_text_printable(self):
"""It should print the report, only if it is printable"""
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document:
with (
mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document,
self.assertLogs(level=logging.WARNING) as logs,
):
self.report_text.property_printing_action_id.action_type = "server"
self.report_text.printing_printer_id = self.new_printer()
document = self.report_text._render_qweb_text(
Expand All @@ -165,29 +174,41 @@ def test_render_qweb_text_printable(self):
doc_format="qweb-text",
tray=False,
)
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)

def test_print_document_not_printable(self):
"""It should print the report, regardless of the defined behaviour"""
self.report.printing_printer_id = self.new_printer()
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document:
with (
mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document,
self.assertLogs(level=logging.WARNING) as logs,
):
self.report.print_document(self.partners.ids)
print_document.assert_called_once()
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)

def test_print_document_printable(self):
"""It should print the report, regardless of the defined behaviour"""
self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer()
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document:
with (
mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_document"
) as print_document,
self.assertLogs(level=logging.WARNING) as logs,
):
self.report.print_document(self.partners.ids)
print_document.assert_called_once()
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)

def test_print_document_no_printer(self):
"""It should raise an error"""
Expand Down

0 comments on commit efb17dd

Please sign in to comment.