From 64c5800d1189cbfcf497a2e8fc1fb807ac5aef06 Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 8 Oct 2017 19:46:52 +1300 Subject: [PATCH] [FIX] Update tests to new return signature of behaviour --- .../models/ir_actions_report.py | 2 +- .../models/printing_printer.py | 2 +- .../tests/test_ir_actions_report.py | 92 +++++++++---------- .../tests/test_printing_printer.py | 26 +++--- .../tests/test_printing_printer_tray.py | 10 +- 5 files changed, 68 insertions(+), 64 deletions(-) diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 0caed4a..104fae0 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -63,7 +63,7 @@ class IrActionsReport(models.Model): action=user.printing_action or 'client', printer=user.printing_printer_id or printer_obj.get_default(), tray=str(user.printer_tray_id.system_name) if - user.printer_tray_id else False + user.printer_tray_id else False ) @api.multi diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index 81c28c5..7fc2c96 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -153,7 +153,7 @@ class PrintingPrinter(models.Model): def _set_option_tray(self, report, value): """Note we use self here as some older PPD use tray rather than InputSlot so we may need to query printer in override""" - return {'InputSlot': str(value)} + return {'InputSlot': str(value)} if value else {} @staticmethod def _set_option_noop(report, value): diff --git a/base_report_to_printer/tests/test_ir_actions_report.py b/base_report_to_printer/tests/test_ir_actions_report.py index 172b804..0b98ebd 100644 --- a/base_report_to_printer/tests/test_ir_actions_report.py +++ b/base_report_to_printer/tests/test_ir_actions_report.py @@ -67,7 +67,7 @@ class TestIrActionsReportXml(TransactionCase): """ 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()[mk()] + behaviour = mk().behaviour() expect = { 'action': behaviour['action'], 'printer_name': behaviour['printer'].name, @@ -85,11 +85,11 @@ class TestIrActionsReportXml(TransactionCase): report.property_printing_action_id = False report.printing_printer_id = False self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': self.env['printing.printer'], - }, - }) + 'action': 'client', + 'printer': self.env['printing.printer'], + 'tray': False, + }, + ) def test_behaviour_user_values(self): """ It should return the action and printer from user """ @@ -97,11 +97,11 @@ class TestIrActionsReportXml(TransactionCase): self.env.user.printing_action = 'client' self.env.user.printing_printer_id = self.new_printer() self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': self.env.user.printing_printer_id, - }, - }) + 'action': 'client', + 'printer': self.env.user.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_report_values(self): """ It should return the action and printer from report """ @@ -110,11 +110,11 @@ class TestIrActionsReportXml(TransactionCase): report.property_printing_action_id = self.new_action() report.printing_printer_id = self.new_printer() self.assertEqual(report.behaviour(), { - report: { - 'action': report.property_printing_action_id.action_type, - 'printer': report.printing_printer_id, - }, - }) + 'action': report.property_printing_action_id.action_type, + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_user_action(self): """ It should return the action and printer from user action""" @@ -122,11 +122,11 @@ class TestIrActionsReportXml(TransactionCase): self.env.user.printing_action = 'client' report.property_printing_action_id.action_type = 'user_default' self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': report.printing_printer_id, - }, - }) + 'action': 'client', + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_printing_action_on_wrong_user(self): """ It should return the action and printer ignoring printing action @@ -138,11 +138,11 @@ class TestIrActionsReportXml(TransactionCase): ('id', '!=', self.env.user.id), ], limit=1) self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': report.printing_printer_id, - }, - }) + 'action': 'client', + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_printing_action_on_wrong_report(self): """ It should return the action and printer ignoring printing action @@ -155,11 +155,11 @@ class TestIrActionsReportXml(TransactionCase): ('id', '!=', report.id), ], limit=1) self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': report.printing_printer_id, - }, - }) + 'action': 'client', + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_printing_action_with_no_printer(self): """ It should return the action from printing action and printer from other @@ -170,11 +170,11 @@ class TestIrActionsReportXml(TransactionCase): printing_action.user_id = self.env.user printing_action.report_id = report self.assertEqual(report.behaviour(), { - report: { - 'action': printing_action.action, - 'printer': report.printing_printer_id, - }, - }) + 'action': printing_action.action, + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_behaviour_printing_action_with_printer(self): """ It should return the action and printer from printing action """ @@ -184,11 +184,11 @@ class TestIrActionsReportXml(TransactionCase): printing_action.user_id = self.env.user printing_action.printer_id = self.new_printer() self.assertEqual(report.behaviour(), { - report: { - 'action': printing_action.action, - 'printer': printing_action.printer_id, - }, - }) + 'action': printing_action.action, + 'printer': printing_action.printer_id, + 'tray': False, + }, + ) def test_behaviour_printing_action_user_defaults(self): """ It should return the action and printer from user with printing action @@ -199,11 +199,11 @@ class TestIrActionsReportXml(TransactionCase): printing_action.user_id = self.env.user printing_action.action = 'user_default' self.assertEqual(report.behaviour(), { - report: { - 'action': 'client', - 'printer': report.printing_printer_id, - }, - }) + 'action': 'client', + 'printer': report.printing_printer_id, + 'tray': False, + }, + ) def test_onchange_printer_tray_id_empty(self): action = self.env['ir.actions.report'].new( diff --git a/base_report_to_printer/tests/test_printing_printer.py b/base_report_to_printer/tests/test_printing_printer.py index 26043c7..7f9c27b 100644 --- a/base_report_to_printer/tests/test_printing_printer.py +++ b/base_report_to_printer/tests/test_printing_printer.py @@ -37,16 +37,19 @@ class TestPrintingPrinter(TransactionCase): def test_printing_options(self): """ It should generate the right options dictionnary """ - self.assertEqual(self.Model.print_options('report', 'raw'), { - 'raw': 'True', - }) - self.assertEqual(self.Model.print_options('report', 'pdf', 2), { 'copies': '2', - }) - self.assertEqual(self.Model.print_options('report', 'raw', 2), { - 'raw': 'True', - 'copies': '2', - }) + # TODO: None here used as report - tests here should be merged + # with tests in test_printing_printer_tray from when modules merged + self.assertEqual(self.Model.print_options( + None, doc_format='raw'), {'raw': 'True',} + ) + self.assertEqual(self.Model.print_options( + None, doc_format='pdf', copies=2), {'copies': '2',} + ) + self.assertEqual(self.Model.print_options( + None, doc_format='raw', copies=2), + {'raw': 'True', 'copies': '2',} + ) @mock.patch('%s.cups' % server_model) def test_print_report(self, cups): @@ -55,7 +58,8 @@ class TestPrintingPrinter(TransactionCase): with mock.patch('%s.mkstemp' % model) as mkstemp: mkstemp.return_value = fd, file_name printer = self.new_record() - printer.print_document('report_name', b'content to print', 'pdf') + printer.print_document(self.report, b'content to print', + doc_format='pdf') cups.Connection().printFile.assert_called_once_with( printer.system_name, file_name, @@ -72,7 +76,7 @@ class TestPrintingPrinter(TransactionCase): printer = self.new_record() with self.assertRaises(UserError): printer.print_document( - 'report_name', b'content to print', 'pdf') + self.report, b'content to print', doc_format='pdf') @mock.patch('%s.cups' % server_model) def test_print_file(self, cups): diff --git a/base_report_to_printer/tests/test_printing_printer_tray.py b/base_report_to_printer/tests/test_printing_printer_tray.py index 7fe7dcb..badde3e 100644 --- a/base_report_to_printer/tests/test_printing_printer_tray.py +++ b/base_report_to_printer/tests/test_printing_printer_tray.py @@ -129,14 +129,14 @@ class TestPrintingPrinter(TransactionCase): self.env.user.printer_tray_id = False report.printer_tray_id = False action.printer_tray_id = False - options = self.Model.print_options(report, 'pdf') + options = self.Model.print_options(report, doc_format='pdf') self.assertFalse('InputSlot' in options) # Only user tray is defined self.env.user.printer_tray_id = user_tray report.printer_tray_id = False action.printer_tray_id = False - options = self.Model.print_options(report, 'pdf') + options = self.Model.print_options(report, doc_format='pdf') self.assertEquals(options, { 'InputSlot': 'User tray', }) @@ -145,7 +145,7 @@ class TestPrintingPrinter(TransactionCase): self.env.user.printer_tray_id = False report.printer_tray_id = report_tray action.printer_tray_id = False - options = self.Model.print_options(report, 'pdf') + options = self.Model.print_options(report, doc_format='pdf') self.assertEquals(options, { 'InputSlot': 'Report tray', }) @@ -154,7 +154,7 @@ class TestPrintingPrinter(TransactionCase): self.env.user.printer_tray_id = False report.printer_tray_id = False action.printer_tray_id = action_tray - options = self.Model.print_options(report, 'pdf') + options = self.Model.print_options(report, doc_format='pdf') self.assertEquals(options, { 'InputSlot': 'Action tray', }) @@ -163,7 +163,7 @@ class TestPrintingPrinter(TransactionCase): self.env.user.printer_tray_id = user_tray report.printer_tray_id = report_tray action.printer_tray_id = action_tray - options = self.Model.print_options(report, 'pdf') + options = self.Model.print_options(report, doc_format='pdf') self.assertEquals(options, { 'InputSlot': 'Action tray', })