mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[FIX] 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
This commit is contained in:
committed by
Moises Lopez - https://www.vauxoo.com/
parent
daa7070518
commit
669862aa70
@@ -93,6 +93,12 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
fp.write(ppd_contents)
|
fp.write(ppd_contents)
|
||||||
|
|
||||||
cups.Connection().getPPD3.return_value = (200, 0, file_name)
|
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):
|
def test_print_options(self):
|
||||||
"""
|
"""
|
||||||
@@ -169,11 +175,9 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
"""
|
"""
|
||||||
self.mock_cups_ppd(cups, file_name=False)
|
self.mock_cups_ppd(cups, file_name=False)
|
||||||
|
|
||||||
with mock.patch.object(
|
self.assertEqual(self.printer.name, 'Printer')
|
||||||
self.Model, '_prepare_update_from_cups'
|
|
||||||
) as prepare_update_from_cups:
|
|
||||||
self.ServerModel.update_printers()
|
self.ServerModel.update_printers()
|
||||||
prepare_update_from_cups.assert_called_once()
|
self.assertEqual(self.printer.name, 'info')
|
||||||
|
|
||||||
@mock.patch('%s.cups' % server_model)
|
@mock.patch('%s.cups' % server_model)
|
||||||
def test_prepare_update_from_cups_no_ppd(self, cups):
|
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)
|
self.mock_cups_ppd(cups, file_name=False)
|
||||||
|
|
||||||
connection = cups.Connection()
|
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)
|
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
self.assertFalse('tray_ids' in vals)
|
self.assertFalse('tray_ids' in vals)
|
||||||
@@ -201,7 +205,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
fp.write(ppd_header)
|
fp.write(ppd_header)
|
||||||
|
|
||||||
connection = cups.Connection()
|
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)
|
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
self.assertFalse('tray_ids' in vals)
|
self.assertFalse('tray_ids' in vals)
|
||||||
@@ -218,7 +222,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
self.mock_cups_ppd(cups)
|
self.mock_cups_ppd(cups)
|
||||||
|
|
||||||
connection = cups.Connection()
|
connection = cups.Connection()
|
||||||
cups_printer = connection.getPrinters()
|
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||||
|
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
self.printer._prepare_update_from_cups(connection, cups_printer)
|
self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
@@ -239,7 +243,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
self.mock_cups_ppd(cups)
|
self.mock_cups_ppd(cups)
|
||||||
|
|
||||||
connection = cups.Connection()
|
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)
|
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
||||||
@@ -255,7 +259,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
self.mock_cups_ppd(cups)
|
self.mock_cups_ppd(cups)
|
||||||
|
|
||||||
connection = cups.Connection()
|
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)
|
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
||||||
@@ -273,7 +277,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
])
|
])
|
||||||
|
|
||||||
connection = cups.Connection()
|
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)
|
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||||
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
||||||
@@ -295,7 +299,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
])
|
])
|
||||||
|
|
||||||
connection = cups.Connection()
|
connection = cups.Connection()
|
||||||
cups_printer = connection.getPrinters()
|
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||||
|
|
||||||
# Create a tray which is in the PPD file
|
# Create a tray which is in the PPD file
|
||||||
self.new_tray({'system_name': 'Tray1'})
|
self.new_tray({'system_name': 'Tray1'})
|
||||||
@@ -314,7 +318,7 @@ class TestPrintingPrinter(TransactionCase):
|
|||||||
self.mock_cups_ppd(cups)
|
self.mock_cups_ppd(cups)
|
||||||
|
|
||||||
connection = cups.Connection()
|
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
|
# Create a tray which is absent from the PPD file
|
||||||
tray = self.new_tray()
|
tray = self.new_tray()
|
||||||
|
|||||||
Reference in New Issue
Block a user