mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[PORT] Finalize move of printer_tray to base_report_to_printer,
fix tests as report param is not a string but recordset
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# Copyright 2016 SYLEAM
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
@@ -67,7 +66,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,10 +84,8 @@ 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'],
|
||||
})
|
||||
|
||||
def test_behaviour_user_values(self):
|
||||
@@ -97,10 +94,8 @@ 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,
|
||||
})
|
||||
|
||||
def test_behaviour_report_values(self):
|
||||
@@ -110,10 +105,8 @@ 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,
|
||||
},
|
||||
})
|
||||
|
||||
def test_behaviour_user_action(self):
|
||||
@@ -122,10 +115,8 @@ 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,
|
||||
},
|
||||
})
|
||||
|
||||
def test_behaviour_printing_action_on_wrong_user(self):
|
||||
@@ -138,10 +129,8 @@ 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,
|
||||
})
|
||||
|
||||
def test_behaviour_printing_action_on_wrong_report(self):
|
||||
@@ -155,10 +144,8 @@ 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,
|
||||
})
|
||||
|
||||
def test_behaviour_printing_action_with_no_printer(self):
|
||||
@@ -170,10 +157,8 @@ 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,
|
||||
},
|
||||
})
|
||||
|
||||
def test_behaviour_printing_action_with_printer(self):
|
||||
@@ -184,10 +169,8 @@ 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,
|
||||
})
|
||||
|
||||
def test_behaviour_printing_action_user_defaults(self):
|
||||
@@ -199,10 +182,8 @@ 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,
|
||||
},
|
||||
})
|
||||
|
||||
def test_onchange_printer_tray_id_empty(self):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
@@ -31,19 +30,22 @@ class TestPrintingPrinter(TransactionCase):
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
}
|
||||
self.report = self.env['ir.actions.report'].search([], limit=1)
|
||||
|
||||
def new_record(self):
|
||||
return self.Model.create(self.printer_vals)
|
||||
|
||||
def test_printing_options(self):
|
||||
""" It should generate the right options dictionnary """
|
||||
self.assertEqual(self.Model.print_options('report', 'raw'), {
|
||||
# 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('report', 'pdf', 2), {
|
||||
self.assertEqual(self.Model.print_options(None, 'pdf', 2), {
|
||||
'copies': '2',
|
||||
})
|
||||
self.assertEqual(self.Model.print_options('report', 'raw', 2), {
|
||||
self.assertEqual(self.Model.print_options(None, 'raw', 2), {
|
||||
'raw': 'True',
|
||||
'copies': '2',
|
||||
})
|
||||
@@ -55,7 +57,7 @@ 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', 'pdf')
|
||||
cups.Connection().printFile.assert_called_once_with(
|
||||
printer.system_name,
|
||||
file_name,
|
||||
@@ -72,14 +74,14 @@ 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', 'pdf')
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
def test_print_file(self, cups):
|
||||
""" It should print a file through CUPS """
|
||||
file_name = 'file_name'
|
||||
printer = self.new_record()
|
||||
printer.print_file(file_name, 'pdf')
|
||||
printer.print_file(file_name, report=self.report, format='pdf')
|
||||
cups.Connection().printFile.assert_called_once_with(
|
||||
printer.system_name,
|
||||
file_name,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
@@ -26,6 +25,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
'printer-make-and-model': 'Make and Model',
|
||||
'printer-location': "location",
|
||||
'device-uri': 'URI',
|
||||
'printer-uri-supported': 'uri'
|
||||
}
|
||||
|
||||
def _record_vals(self, sys_name='sys_name'):
|
||||
@@ -52,6 +52,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.Model.action_ok()
|
||||
cups.Connection().getPrinters.assert_called_once_with()
|
||||
|
||||
@@ -68,6 +69,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.Model.action_ok()
|
||||
rec_id = self.env['printing.printer'].search([
|
||||
('system_name', '=', 'sys_name')
|
||||
@@ -89,6 +91,7 @@ class TestPrintingPrinterWizard(TransactionCase):
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
self.env['printing.printer'].create(
|
||||
self._record_vals()
|
||||
)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 SYLEAM
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
@@ -47,12 +46,14 @@ class TestPrintingReportXmlAction(TransactionCase):
|
||||
self.assertEqual(xml_action.behaviour(), {
|
||||
'action': xml_action.action,
|
||||
'printer': xml_action.printer_id,
|
||||
'tray': False,
|
||||
})
|
||||
|
||||
xml_action = self.new_record({'printer_id': self.new_printer().id})
|
||||
self.assertEqual(xml_action.behaviour(), {
|
||||
'action': xml_action.action,
|
||||
'printer': xml_action.printer_id,
|
||||
'tray': False,
|
||||
})
|
||||
|
||||
self.assertEqual(self.Model.behaviour(), {})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user