Reformatted after template update

This commit is contained in:
Enric Tobella
2022-09-01 11:04:43 +02:00
parent 479efcaa46
commit 0203e5b621
25 changed files with 136 additions and 126 deletions

View File

@@ -35,12 +35,12 @@ class IrActionsReport(models.Model):
@api.onchange("printing_printer_id")
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
"""Reset the tray when the printer is changed"""
self.printer_tray_id = False
@api.model
def print_action_for_report_name(self, report_name):
""" Returns if the action is a direct print or pdf
"""Returns if the action is a direct print or pdf
Called from js
"""
@@ -99,7 +99,7 @@ class IrActionsReport(models.Model):
return result
def print_document(self, record_ids, data=None):
""" Print a document, do not return the document file """
"""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)
@@ -143,7 +143,7 @@ class IrActionsReport(models.Model):
return res
def render_qweb_pdf(self, res_ids=None, data=None):
""" Generate a PDF and returns it.
"""Generate a PDF and returns it.
If the action configured on the report is server, it prints the
generated document as well.

View File

@@ -132,7 +132,7 @@ class PrintingPrinter(models.Model):
return vals
def print_document(self, report, content, **print_opts):
""" Print a file
"""Print a file
Format could be pdf, qweb-pdf, raw, ...
"""
self.ensure_one()
@@ -173,7 +173,7 @@ class PrintingPrinter(models.Model):
return options
def print_file(self, file_name, report=None, **print_opts):
""" Print a file """
"""Print a file"""
self.ensure_one()
title = print_opts.pop("title", file_name)
connection = self.server_id._open_connection(raise_on_error=True)

View File

@@ -35,7 +35,7 @@ class PrintingReportXmlAction(models.Model):
@api.onchange("printer_id")
def onchange_printer_id(self):
""" Reset the tray when the printer is changed """
"""Reset the tray when the printer is changed"""
self.printer_tray_id = False
def behaviour(self):

View File

@@ -38,5 +38,5 @@ class ResUsers(models.Model):
@api.onchange("printing_printer_id")
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
"""Reset the tray when the printer is changed"""
self.printer_tray_id = False

View File

@@ -52,14 +52,14 @@ class TestIrActionsReportXml(TransactionCase):
return self.env["printing.tray"].create(values)
def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """
"""It should get report by name"""
with mock.patch.object(self.Model, "_get_report_from_name") 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 """
"""It should return empty dict when no matching report"""
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
expect = "test"
mk.return_value = False
@@ -67,7 +67,7 @@ class TestIrActionsReportXml(TransactionCase):
self.assertDictEqual({}, res)
def test_print_action_for_report_name_returns_if_report(self):
""" It should return correct serializable result for behaviour """
"""It should return correct serializable result for behaviour"""
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
res = self.Model.print_action_for_report_name("test")
behaviour = mk().behaviour()
@@ -78,7 +78,7 @@ class TestIrActionsReportXml(TransactionCase):
self.assertDictEqual(expect, res, "Expect {}, Got {}".format(expect, res))
def test_behaviour_default_values(self):
""" It should return the default action and printer """
"""It should return the default action and printer"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = False
self.env.user.printing_printer_id = False
@@ -94,7 +94,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_user_values(self):
""" It should return the action and printer from user """
"""It should return the action and printer from user"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
self.env.user.printing_printer_id = self.new_printer()
@@ -108,7 +108,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_report_values(self):
""" It should return the action and printer from report """
"""It should return the action and printer from report"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
report.property_printing_action_id = self.new_action()
@@ -123,7 +123,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_user_action(self):
""" It should return the action and printer from user action"""
"""It should return the action and printer from user action"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
report.property_printing_action_id.action_type = "user_default"
@@ -133,8 +133,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_printing_action_on_wrong_user(self):
""" It should return the action and printer ignoring printing action
"""
"""It should return the action and printer ignoring printing action"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
printing_action = self.new_printing_action()
@@ -147,8 +146,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_printing_action_on_wrong_report(self):
""" It should return the action and printer ignoring printing action
"""
"""It should return the action and printer ignoring printing action"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
printing_action = self.new_printing_action()
@@ -162,8 +160,8 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_printing_action_with_no_printer(self):
""" It should return the action from printing action and printer from
other
"""It should return the action from printing action and printer from
other
"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
@@ -180,7 +178,7 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_printing_action_with_printer(self):
""" It should return the action and printer from printing action """
"""It should return the action and printer from printing action"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"
printing_action = self.new_printing_action()
@@ -196,8 +194,8 @@ class TestIrActionsReportXml(TransactionCase):
)
def test_behaviour_printing_action_user_defaults(self):
""" It should return the action and printer from user with printing
action
"""It should return the action and printer from user with printing
action
"""
report = self.Model.search([], limit=1)
self.env.user.printing_action = "client"

View File

@@ -44,7 +44,7 @@ class TestPrintingJob(TransactionCase):
@mock.patch("%s.cups" % model)
def test_cancel_job_error(self, cups):
""" It should catch any exception from CUPS and update status """
"""It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception
printer = self.new_printer()
job = self.new_job(printer, {"job_id_cups": 2})
@@ -54,7 +54,7 @@ class TestPrintingJob(TransactionCase):
@mock.patch("%s.cups" % model)
def test_cancel_job(self, cups):
""" It should catch any exception from CUPS and update status """
"""It should catch any exception from CUPS and update status"""
printer = self.new_printer()
job = self.new_job(printer)
job.cancel()

View File

@@ -65,7 +65,7 @@ class TestPrintingPrinter(TransactionCase):
self.assertEqual(self.Model._set_option_format(None, "pdf"), {})
def test_print_options(self):
""" It should generate the right options dictionnary """
"""It should generate the right options dictionnary"""
# TODO: None here used as report - tests here should be merged
# with tests in test_printing_printer_tray from when modules merged
report = self.env["ir.actions.report"].search([], limit=1)
@@ -82,7 +82,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_print_report(self, cups):
""" It should print a report through CUPS """
"""It should print a report through CUPS"""
fd, file_name = tempfile.mkstemp()
with mock.patch("%s.mkstemp" % model) as mkstemp:
mkstemp.return_value = fd, file_name
@@ -94,7 +94,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_print_report_error(self, cups):
""" It should print a report through CUPS """
"""It should print a report through CUPS"""
cups.Connection.side_effect = Exception
fd, file_name = tempfile.mkstemp()
with mock.patch("%s.mkstemp" % model) as mkstemp:
@@ -107,7 +107,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_print_file(self, cups):
""" It should print a file through CUPS """
"""It should print a file through CUPS"""
file_name = "file_name"
printer = self.new_record()
printer.print_file(file_name, "pdf")
@@ -117,7 +117,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_print_file_error(self, cups):
""" It should print a file through CUPS """
"""It should print a file through CUPS"""
cups.Connection.side_effect = Exception
file_name = "file_name"
printer = self.new_record()
@@ -125,7 +125,7 @@ class TestPrintingPrinter(TransactionCase):
printer.print_file(file_name)
def test_set_default(self):
""" It should set a single record as default """
"""It should set a single record as default"""
printer = self.new_record()
self.assertTrue(printer.default)
other_printer = self.new_record()
@@ -137,7 +137,7 @@ class TestPrintingPrinter(TransactionCase):
self.assertEqual(other_printer, self.Model.get_default())
def test_unset_default(self):
""" It should unset the default state of the printer """
"""It should unset the default state of the printer"""
printer = self.new_record()
self.assertTrue(printer.default)
printer.unset_default()
@@ -145,7 +145,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_cancel_all_jobs(self, cups):
""" It should cancel all jobs """
"""It should cancel all jobs"""
printer = self.new_record()
printer.action_cancel_all_jobs()
cups.Connection().cancelAllJobs.assert_called_once_with(
@@ -154,7 +154,7 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_cancel_and_purge_all_jobs(self, cups):
""" It should cancel all jobs """
"""It should cancel all jobs"""
printer = self.new_record()
printer.cancel_all_jobs(purge_jobs=True)
cups.Connection().cancelAllJobs.assert_called_once_with(
@@ -163,14 +163,14 @@ class TestPrintingPrinter(TransactionCase):
@mock.patch("%s.cups" % server_model)
def test_enable_printer(self, cups):
""" It should enable the printer """
"""It should enable the printer"""
printer = self.new_record()
printer.enable()
cups.Connection().enablePrinter.assert_called_once_with(printer.system_name)
@mock.patch("%s.cups" % server_model)
def test_disable_printer(self, cups):
""" It should disable the printer """
"""It should disable the printer"""
printer = self.new_record()
printer.disable()
cups.Connection().disablePrinter.assert_called_once_with(printer.system_name)

View File

@@ -38,7 +38,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model)
def test_action_ok_inits_connection(self, cups):
""" It should initialize CUPS connection """
"""It should initialize CUPS connection"""
self.Model.action_ok()
cups.Connection.assert_called_once_with(
host=self.server.address, port=self.server.port
@@ -46,7 +46,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model)
def test_action_ok_gets_printers(self, cups):
""" It should get printers from CUPS """
"""It should get printers from CUPS"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "")
self.Model.action_ok()
@@ -54,14 +54,14 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model)
def test_action_ok_raises_warning_on_error(self, cups):
""" It should raise Warning on any error """
"""It should raise Warning on any error"""
cups.Connection.side_effect = StopTest
with self.assertRaises(UserError):
self.Model.action_ok()
@mock.patch("%s.cups" % model)
def test_action_ok_creates_new_printer(self, cups):
""" It should create new printer w/ proper vals """
"""It should create new printer w/ proper vals"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "")
self.Model.action_ok()
@@ -77,7 +77,7 @@ class TestPrintingPrinterWizard(TransactionCase):
@mock.patch("%s.cups" % model)
def test_action_ok_skips_existing_printer(self, cups):
""" It should not recreate existing printers """
"""It should not recreate existing printers"""
cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
cups.Connection().getPPD3.return_value = (200, 0, "")
self.env["printing.printer"].create(self._record_vals())

View File

@@ -41,8 +41,8 @@ class TestPrintingReportXmlAction(TransactionCase):
)
def test_behaviour(self):
""" It should return some action's data, unless called on empty
recordset
"""It should return some action's data, unless called on empty
recordset
"""
xml_action = self.new_record()
self.assertEqual(

View File

@@ -44,7 +44,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_printers_error(self, cups):
""" It should catch any exception from CUPS and update status """
"""It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception
rec_id = self.new_printer()
self.Model.update_printers()
@@ -52,7 +52,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_printers_inits_cups(self, cups):
""" It should init CUPS connection """
"""It should init CUPS connection"""
self.new_printer()
self.Model.update_printers()
cups.Connection.assert_called_once_with(
@@ -61,21 +61,21 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_printers_gets_all_printers(self, cups):
""" It should get all printers from CUPS server """
"""It should get all printers from CUPS server"""
self.new_printer()
self.Model.update_printers()
cups.Connection().getPrinters.assert_called_once_with()
@mock.patch("%s.cups" % model)
def test_update_printers_search(self, cups):
""" It should search all when no domain """
"""It should search all when no domain"""
with mock.patch.object(self.Model, "search") 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 """
"""It should use specific domain for search"""
with mock.patch.object(self.Model, "search") as search:
expect = [("id", ">", 0)]
self.Model.update_printers(expect)
@@ -83,7 +83,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_printers_update_unavailable(self, cups):
""" It should update status when printer is unavailable """
"""It should update status when printer is unavailable"""
rec_id = self.new_printer()
cups.Connection().getPrinters().get.return_value = False
self.Model.action_update_printers()
@@ -91,19 +91,20 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_archived_printers(self, cups):
""" It should update status even if printer is archived """
"""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,
"unavailable",
rec_id.status,
)
@mock.patch("%s.cups" % model)
def test_update_jobs_cron(self, cups):
""" It should get all jobs from CUPS server """
"""It should get all jobs from CUPS server"""
self.new_printer()
self.Model.action_update_jobs()
cups.Connection().getPrinters.assert_called_once_with()
@@ -125,7 +126,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_jobs_button(self, cups):
""" It should get all jobs from CUPS server """
"""It should get all jobs from CUPS server"""
self.new_printer()
self.server.action_update_jobs()
cups.Connection().getPrinters.assert_called_once_with()
@@ -147,7 +148,7 @@ class TestPrintingServer(TransactionCase):
@mock.patch("%s.cups" % model)
def test_update_jobs_error(self, cups):
""" It should catch any exception from CUPS and update status """
"""It should catch any exception from CUPS and update status"""
cups.Connection.side_effect = Exception
self.new_printer()
self.server.update_jobs()

View File

@@ -34,7 +34,7 @@ class TestPrintingTray(TransactionCase):
return self.env["printing.tray"].create(self.tray_vals)
def test_report_behaviour(self):
""" It should add the selected tray in the report data """
"""It should add the selected tray in the report data"""
ir_report = self.env["ir.actions.report"].search([], limit=1)
report = self.env["printing.report.xml.action"].create(
{"user_id": self.env.user.id, "report_id": ir_report.id, "action": "server"}

View File

@@ -66,24 +66,23 @@ class TestReport(common.HttpCase):
)
def test_can_print_report_context_skip(self):
""" It should return False based on context """
"""It should return False based on context"""
rec_id = self.new_record().with_context(must_skip_send_to_printer=True)
res = rec_id._can_print_report({"action": "server"}, True, True)
self.assertFalse(res)
def test_can_print_report_true(self):
""" It should return True when server print allowed """
"""It should return True when server print allowed"""
res = self.new_record()._can_print_report({"action": "server"}, True, True)
self.assertTrue(res)
def test_can_print_report_false(self):
""" It should return False when server print not allowed """
"""It should return False when server print not allowed"""
res = self.new_record()._can_print_report({"action": "server"}, True, False)
self.assertFalse(res)
def test_render_qweb_pdf_not_printable(self):
""" It should print the report, only if it is printable
"""
"""It should print the report, only if it is printable"""
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
@@ -93,8 +92,7 @@ class TestReport(common.HttpCase):
print_document.assert_not_called()
def test_render_qweb_pdf_printable(self):
""" It should print the report, only if it is printable
"""
"""It should print the report, only if it is printable"""
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
@@ -112,7 +110,7 @@ class TestReport(common.HttpCase):
)
def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """
"""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."
@@ -123,7 +121,7 @@ class TestReport(common.HttpCase):
print_document.assert_called_once()
def test_print_document_printable(self):
""" It should print the report, regardless of the defined behaviour """
"""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(
@@ -135,6 +133,6 @@ class TestReport(common.HttpCase):
print_document.assert_called_once()
def test_print_document_no_printer(self):
""" It should raise an error """
"""It should raise an error"""
with self.assertRaises(exceptions.UserError):
self.report.print_document(self.partners.ids)

View File

@@ -15,13 +15,13 @@ class TestResUsers(common.TransactionCase):
return self.env["res.users"].create(self.user_vals)
def test_available_action_types_excludes_user_default(self):
""" It should not contain `user_default` in avail actions """
"""It should not contain `user_default` in avail actions"""
self.user_vals["printing_action"] = "user_default"
with self.assertRaises(ValueError):
self.new_record()
def test_available_action_types_includes_something_else(self):
""" It should still contain other valid keys """
"""It should still contain other valid keys"""
self.user_vals["printing_action"] = "server"
self.assertTrue(self.new_record())