[MIG] base_report_to_printer: Migrate to v11.0

This commit is contained in:
Sylvain GARANCHER
2017-10-03 17:14:08 +02:00
committed by hda
parent 713218f4a7
commit 44f6d9d82b
23 changed files with 182 additions and 481 deletions

View File

@@ -7,6 +7,6 @@ from . import test_printing_printer
from . import test_printing_server
from . import test_report
from . import test_res_users
from . import test_ir_actions_report_xml
from . import test_ir_actions_report
from . import test_printing_printer_wizard
from . import test_printing_report_xml_action

View File

@@ -12,10 +12,10 @@ class TestIrActionsReportXml(TransactionCase):
def setUp(self):
super(TestIrActionsReportXml, self).setUp()
self.Model = self.env['ir.actions.report.xml']
self.Model = self.env['ir.actions.report']
self.vals = {}
self.report = self.env['ir.actions.report.xml'].search([], limit=1)
self.report = self.env['ir.actions.report'].search([], limit=1)
self.server = self.env['printing.server'].create({})
def new_action(self):
@@ -46,18 +46,18 @@ class TestIrActionsReportXml(TransactionCase):
def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """
with mock.patch.object(self.Model, 'env') as mk:
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
expect = 'test'
self.Model.print_action_for_report_name(expect)
mk['report']._get_report_from_name.assert_called_once_with(
mk.assert_called_once_with(
expect
)
def test_print_action_for_report_name_returns_if_no_report(self):
""" It should return empty dict when no matching report """
with mock.patch.object(self.Model, 'env') as mk:
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
expect = 'test'
mk['report']._get_report_from_name.return_value = False
mk.return_value = False
res = self.Model.print_action_for_report_name(expect)
self.assertDictEqual(
{}, res,
@@ -65,11 +65,9 @@ class TestIrActionsReportXml(TransactionCase):
def test_print_action_for_report_name_returns_if_report(self):
""" It should return correct serializable result for behaviour """
with mock.patch.object(self.Model, 'env') as mk:
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
res = self.Model.print_action_for_report_name('test')
behaviour = mk['report']._get_report_from_name().behaviour()[
mk['report']._get_report_from_name().id
]
behaviour = mk().behaviour()[mk()]
expect = {
'action': behaviour['action'],
'printer_name': behaviour['printer'].name,
@@ -87,7 +85,7 @@ class TestIrActionsReportXml(TransactionCase):
report.property_printing_action_id = False
report.printing_printer_id = False
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': self.env['printing.printer'],
},
@@ -99,7 +97,7 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
self.env.user.printing_printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': self.env.user.printing_printer_id,
},
@@ -112,7 +110,7 @@ class TestIrActionsReportXml(TransactionCase):
report.property_printing_action_id = self.new_action()
report.printing_printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': report.property_printing_action_id.action_type,
'printer': report.printing_printer_id,
},
@@ -124,7 +122,7 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
report.property_printing_action_id.action_type = 'user_default'
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -140,7 +138,7 @@ class TestIrActionsReportXml(TransactionCase):
('id', '!=', self.env.user.id),
], limit=1)
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -153,11 +151,11 @@ class TestIrActionsReportXml(TransactionCase):
self.env.user.printing_action = 'client'
printing_action = self.new_printing_action()
printing_action.user_id = self.env.user
printing_action.report_id = self.env['ir.actions.report.xml'].search([
printing_action.report_id = self.env['ir.actions.report'].search([
('id', '!=', report.id),
], limit=1)
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},
@@ -172,7 +170,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.report_id = report
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': printing_action.action,
'printer': report.printing_printer_id,
},
@@ -186,7 +184,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.printer_id = self.new_printer()
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': printing_action.action,
'printer': printing_action.printer_id,
},
@@ -201,7 +199,7 @@ class TestIrActionsReportXml(TransactionCase):
printing_action.user_id = self.env.user
printing_action.action = 'user_default'
self.assertEqual(report.behaviour(), {
report.id: {
report: {
'action': 'client',
'printer': report.printing_printer_id,
},

View File

@@ -53,7 +53,7 @@ class TestPrintingJob(TransactionCase):
job = self.new_job(printer, {'job_id_cups': 2})
job.action_cancel()
cups.Connection.side_effect = None
self.assertEquals(cups.Connection().cancelJob.call_count, 0)
self.assertEqual(cups.Connection().cancelJob.call_count, 0)
@mock.patch('%s.cups' % model)
def test_cancel_job(self, cups):

View File

@@ -37,13 +37,13 @@ class TestPrintingPrinter(TransactionCase):
def test_printing_options(self):
""" It should generate the right options dictionnary """
self.assertEquals(self.Model.print_options('report', 'raw'), {
self.assertEqual(self.Model.print_options('report', 'raw'), {
'raw': 'True',
})
self.assertEquals(self.Model.print_options('report', 'pdf', 2), {
self.assertEqual(self.Model.print_options('report', 'pdf', 2), {
'copies': '2',
})
self.assertEquals(self.Model.print_options('report', 'raw', 2), {
self.assertEqual(self.Model.print_options('report', 'raw', 2), {
'raw': 'True',
'copies': '2',
})
@@ -55,7 +55,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', 'content to print', 'pdf')
printer.print_document('report_name', b'content to print', 'pdf')
cups.Connection().printFile.assert_called_once_with(
printer.system_name,
file_name,
@@ -72,7 +72,7 @@ class TestPrintingPrinter(TransactionCase):
printer = self.new_record()
with self.assertRaises(UserError):
printer.print_document(
'report_name', 'content to print', 'pdf')
'report_name', b'content to print', 'pdf')
@mock.patch('%s.cups' % server_model)
def test_print_file(self, cups):
@@ -105,7 +105,14 @@ class TestPrintingPrinter(TransactionCase):
self.assertTrue(other_printer.default)
# Check that calling the method on an empty recordset does nothing
self.Model.set_default()
self.assertEquals(other_printer, self.Model.get_default())
self.assertEqual(other_printer, self.Model.get_default())
def test_unset_default(self):
""" It should unset the default state of the printer """
printer = self.new_record()
self.assertTrue(printer.default)
printer.unset_default()
self.assertFalse(printer.default)
@mock.patch('%s.cups' % server_model)
def test_cancel_all_jobs(self, cups):

View File

@@ -75,7 +75,7 @@ class TestPrintingPrinterWizard(TransactionCase):
limit=1,
)
self.assertTrue(rec_id)
for key, val in self._record_vals().iteritems():
for key, val in self._record_vals().items():
if rec_id._fields[key].type == 'many2one':
val = self.env[rec_id._fields[key].comodel_name].browse(val)

View File

@@ -11,7 +11,7 @@ class TestPrintingReportXmlAction(TransactionCase):
super(TestPrintingReportXmlAction, self).setUp()
self.Model = self.env['printing.report.xml.action']
self.report = self.env['ir.actions.report.xml'].search([], limit=1)
self.report = self.env['ir.actions.report'].search([], limit=1)
self.server = self.env['printing.server'].create({})
self.report_vals = {

View File

@@ -15,9 +15,13 @@ class TestReport(HttpCase):
def setUp(self):
super(TestReport, self).setUp()
self.Model = self.env['report']
self.Model = self.env['ir.actions.report']
self.server = self.env['printing.server'].create({})
self.report_vals = {}
self.report_vals = {
'name': 'Test Report',
'model': 'ir.actions.report',
'report_name': 'Test Report',
}
def new_record(self):
return self.Model.create(self.report_vals)
@@ -59,39 +63,38 @@ class TestReport(HttpCase):
)
self.assertFalse(res)
def test_get_pdf_not_printable(self):
def test_render_qweb_pdf_not_printable(self):
""" It should print the report, only if it is printable
"""
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
records = self.env[report.model].search([], limit=5)
self.env['report'].get_pdf(records.ids, report.report_name)
report.render_qweb_pdf(records.ids)
print_document.assert_not_called()
def test_get_pdf_printable(self):
def test_render_qweb_pdf_printable(self):
""" It should print the report, only if it is printable
"""
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.property_printing_action_id.action_type = 'server'
report.printing_printer_id = self.new_printer()
records = self.env[report.model].search([], limit=5)
document = self.env['report'].get_pdf(
records.ids, report.report_name)
document, doc_format = report.render_qweb_pdf(records.ids)
print_document.assert_called_once_with(
report, document, report.report_type)
def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.printing_printer_id = self.new_printer()
@@ -100,12 +103,12 @@ class TestReport(HttpCase):
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)
print_document.assert_called_once()
def test_print_document_printable(self):
""" It should print the report, regardless of the defined behaviour """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
report.property_printing_action_id.action_type = 'server'
@@ -115,15 +118,15 @@ class TestReport(HttpCase):
with mock.patch('odoo.addons.base_report_to_printer.models.'
'printing_printer.PrintingPrinter.'
'print_document') as print_document:
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)
print_document.assert_called_once()
def test_print_document_no_printer(self):
""" It should raise an error """
report = self.env['ir.actions.report.xml'].search([
report = self.env['ir.actions.report'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
records = self.env[report.model].search([], limit=5)
with self.assertRaises(exceptions.UserError):
self.env['report'].print_document(records.ids, report.report_name)
report.print_document(records.ids)