mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[FIX] Update tests to new return signature of behaviour
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -145,7 +145,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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -40,16 +40,16 @@ class TestPrintingPrinter(TransactionCase):
|
||||
""" 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
|
||||
self.assertEqual(self.Model.print_options(None, 'raw'), {
|
||||
'raw': 'True',
|
||||
})
|
||||
self.assertEqual(self.Model.print_options(None, 'pdf', 2), {
|
||||
'copies': '2',
|
||||
})
|
||||
self.assertEqual(self.Model.print_options(None, 'raw', 2), {
|
||||
'raw': 'True',
|
||||
'copies': '2',
|
||||
})
|
||||
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):
|
||||
@@ -58,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(self.report, 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,
|
||||
@@ -75,7 +76,7 @@ class TestPrintingPrinter(TransactionCase):
|
||||
printer = self.new_record()
|
||||
with self.assertRaises(UserError):
|
||||
printer.print_document(
|
||||
self.report, 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):
|
||||
|
||||
@@ -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',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user