[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:
Sylvain Garancher
2017-07-12 23:47:23 +02:00
committed by Moises Lopez - https://www.vauxoo.com/
parent daa7070518
commit 669862aa70

View File

@@ -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()