From d592c4e05dd9a003e878892ed81bdd77e520f970 Mon Sep 17 00:00:00 2001 From: Sylvain Garancher Date: Wed, 12 Jul 2017 23:47:23 +0200 Subject: [PATCH] printer_tray: Fix mocking in unit tests (#97) The mocking was bad, and this bug has been revealed by the usage of mock 2.0.0 OCA Transbot updated translations from Transifex --- printer_tray/i18n/hr.po | 29 ++++++++++---------- printer_tray/tests/test_printing_printer.py | 30 ++++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/printer_tray/i18n/hr.po b/printer_tray/i18n/hr.po index 8eded74..97af203 100644 --- a/printer_tray/i18n/hr.po +++ b/printer_tray/i18n/hr.po @@ -4,13 +4,14 @@ # # Translators: # OCA Transbot , 2017 +# Bole , 2017 msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-04-24 02:40+0000\n" -"PO-Revision-Date: 2017-04-24 02:40+0000\n" -"Last-Translator: OCA Transbot , 2017\n" +"POT-Creation-Date: 2017-07-12 21:51+0000\n" +"PO-Revision-Date: 2017-07-12 21:51+0000\n" +"Last-Translator: Bole , 2017\n" "Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -31,7 +32,7 @@ msgstr "Kreirano" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_res_users_printer_tray_id msgid "Default Printer Paper Source" -msgstr "" +msgstr "Zadani izvor papria na printeru" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_printing_tray_display_name @@ -61,51 +62,51 @@ msgstr "Zadnje ažuriranje" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_printing_tray_name msgid "Name" -msgstr "" +msgstr "Naziv" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_ir_act_report_xml_printer_tray_id #: model:ir.model.fields,field_description:printer_tray.field_printing_report_xml_action_printer_tray_id msgid "Paper Source" -msgstr "" +msgstr "Izvor papira" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_printing_printer_tray_ids msgid "Paper Sources" -msgstr "" +msgstr "Izvori papira" #. module: printer_tray #: model:ir.model,name:printer_tray.model_printing_printer #: model:ir.model.fields,field_description:printer_tray.field_printing_tray_printer_id msgid "Printer" -msgstr "" +msgstr "Pisač" #. module: printer_tray #: model:ir.model,name:printer_tray.model_printing_tray msgid "Printer Tray" -msgstr "" +msgstr "Ladica pisača" #. module: printer_tray #: model:ir.model,name:printer_tray.model_printing_report_xml_action msgid "Printing Report Printing Actions" -msgstr "" +msgstr "Akcije ispisa izvještaja na pisač" #. module: printer_tray #: model:ir.model.fields,field_description:printer_tray.field_printing_tray_system_name msgid "System name" -msgstr "" +msgstr "Sistemski naziv" #. module: printer_tray #: model:ir.ui.view,arch_db:printer_tray.printing_printer_view_form msgid "Trays" -msgstr "" +msgstr "Ladice" #. module: printer_tray #: model:ir.model,name:printer_tray.model_res_users msgid "Users" -msgstr "" +msgstr "Korisnici" #. module: printer_tray #: model:ir.model,name:printer_tray.model_ir_actions_report_xml msgid "ir.actions.report.xml" -msgstr "" +msgstr "ir.actions.report.xml" diff --git a/printer_tray/tests/test_printing_printer.py b/printer_tray/tests/test_printing_printer.py index 25826db..d40951d 100644 --- a/printer_tray/tests/test_printing_printer.py +++ b/printer_tray/tests/test_printing_printer.py @@ -93,6 +93,12 @@ class TestPrintingPrinter(TransactionCase): fp.write(ppd_contents) cups.Connection().getPPD3.return_value = (200, 0, file_name) + cups.Connection().getPrinters.return_value = { + self.printer.system_name: { + 'printer-info': 'info', + 'printer-uri-supported': 'uri', + }, + } def test_print_options(self): """ @@ -169,11 +175,9 @@ class TestPrintingPrinter(TransactionCase): """ self.mock_cups_ppd(cups, file_name=False) - with mock.patch.object( - self.Model, '_prepare_update_from_cups' - ) as prepare_update_from_cups: - self.ServerModel.update_printers() - prepare_update_from_cups.assert_called_once() + self.assertEqual(self.printer.name, 'Printer') + self.ServerModel.update_printers() + self.assertEqual(self.printer.name, 'info') @mock.patch('%s.cups' % server_model) def test_prepare_update_from_cups_no_ppd(self, cups): @@ -183,7 +187,7 @@ class TestPrintingPrinter(TransactionCase): self.mock_cups_ppd(cups, file_name=False) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] vals = self.printer._prepare_update_from_cups(connection, cups_printer) self.assertFalse('tray_ids' in vals) @@ -201,7 +205,7 @@ class TestPrintingPrinter(TransactionCase): fp.write(ppd_header) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] vals = self.printer._prepare_update_from_cups(connection, cups_printer) self.assertFalse('tray_ids' in vals) @@ -218,7 +222,7 @@ class TestPrintingPrinter(TransactionCase): self.mock_cups_ppd(cups) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] with self.assertRaises(OSError): self.printer._prepare_update_from_cups(connection, cups_printer) @@ -239,7 +243,7 @@ class TestPrintingPrinter(TransactionCase): self.mock_cups_ppd(cups) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] vals = self.printer._prepare_update_from_cups(connection, cups_printer) self.assertEqual(vals['tray_ids'], [(0, 0, { @@ -255,7 +259,7 @@ class TestPrintingPrinter(TransactionCase): self.mock_cups_ppd(cups) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] vals = self.printer._prepare_update_from_cups(connection, cups_printer) self.assertEqual(vals['tray_ids'], [(0, 0, { @@ -273,7 +277,7 @@ class TestPrintingPrinter(TransactionCase): ]) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] vals = self.printer._prepare_update_from_cups(connection, cups_printer) self.assertEqual(vals['tray_ids'], [(0, 0, { @@ -295,7 +299,7 @@ class TestPrintingPrinter(TransactionCase): ]) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] # Create a tray which is in the PPD file self.new_tray({'system_name': 'Tray1'}) @@ -314,7 +318,7 @@ class TestPrintingPrinter(TransactionCase): self.mock_cups_ppd(cups) connection = cups.Connection() - cups_printer = connection.getPrinters() + cups_printer = connection.getPrinters()[self.printer.system_name] # Create a tray which is absent from the PPD file tray = self.new_tray()