[IMP] base_report_to_printer: Fix XMLRPC calls and tests

- When added the patch to be able to configure report copies by report object, the expected signature changed to expect a report object. That can't work through the XMLRPC interface, so we revert it to what it was before: expecting the report name.
- Some tests that were producing warnings are muted now.
- The tests that had been changed went back to normal too.
- Current implementation didn't produce the expected results when actually forcing to print 1 copy.
- Added a demo report to test, since searching the database for the 1st unkonwn report found is not very deterministic and can lead to problems, like those addressed in #122 and #123.
- Finally, this update requires a database upgrade, so I pushed correctly the manifest version too.
This commit is contained in:
Jairo Llopis
2018-04-09 09:53:41 +01:00
committed by Jairo Llopis
parent a946a2a570
commit 3eb0c70acb
9 changed files with 70 additions and 16 deletions

View File

@@ -6,6 +6,9 @@ import mock
from odoo import fields
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
from ..models import printing_server
model = 'odoo.addons.base_report_to_printer.models.printing_server'
@@ -45,6 +48,7 @@ class TestPrintingJob(TransactionCase):
values['printer_id'] = printer.id
return self.env['printing.job'].create(values)
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % model)
def test_cancel_job_error(self, cups):
""" It should catch any exception from CUPS and update status """

View File

@@ -8,6 +8,9 @@ import mock
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
from ..models import printing_server
model = 'odoo.addons.base_report_to_printer.models.printing_printer'
@@ -32,9 +35,7 @@ class TestPrintingPrinter(TransactionCase):
'location': 'Location',
'uri': 'URI',
}
self.report = self.env['ir.actions.report.xml'].search([
('report_type', '=', 'qweb-pdf'),
], limit=1)
self.report = self.env.ref("base_report_to_printer.action_report_1")
def new_record(self):
return self.Model.create(self.printer_vals)
@@ -59,13 +60,18 @@ 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, 'content to print', 'pdf')
printer.print_document(
self.report.report_name,
'content to print',
'pdf',
)
cups.Connection().printFile.assert_called_once_with(
printer.system_name,
file_name,
file_name,
options={})
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % server_model)
def test_print_report_error(self, cups):
""" It should print a report through CUPS """
@@ -76,7 +82,10 @@ class TestPrintingPrinter(TransactionCase):
printer = self.new_record()
with self.assertRaises(UserError):
printer.print_document(
self.report, 'content to print', 'pdf')
self.report.report_name,
'content to print',
'pdf',
)
@mock.patch('%s.cups' % server_model)
def test_print_file(self, cups):
@@ -90,6 +99,7 @@ class TestPrintingPrinter(TransactionCase):
file_name,
options={})
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % server_model)
def test_print_file_error(self, cups):
""" It should print a file through CUPS """

View File

@@ -6,6 +6,9 @@ import mock
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
from odoo.tools import mute_logger
from ..models import printing_server
model = 'odoo.addons.base_report_to_printer.models.printing_server'
@@ -55,6 +58,7 @@ class TestPrintingPrinterWizard(TransactionCase):
self.Model.action_ok()
cups.Connection().getPrinters.assert_called_once_with()
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % model)
def test_action_ok_raises_warning_on_error(self, cups):
""" It should raise Warning on any error """

View File

@@ -6,6 +6,9 @@ import mock
from odoo import fields
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
from ..models import printing_server
model = 'odoo.addons.base_report_to_printer.models.printing_server'
@@ -45,6 +48,7 @@ class TestPrintingServer(TransactionCase):
values['printer_id'] = printer.id
return self.env['printing.job'].create(values)
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % model)
def test_update_printers_error(self, cups):
""" It should catch any exception from CUPS and update status """
@@ -140,6 +144,7 @@ class TestPrintingServer(TransactionCase):
],
)
@mute_logger(printing_server.__name__)
@mock.patch('%s.cups' % model)
def test_update_jobs_error(self, cups):
""" It should catch any exception from CUPS and update status """

View File

@@ -104,7 +104,7 @@ class TestReport(common.HttpCase):
document = self.Model.get_pdf(
self.partners.ids, self.report.report_name)
print_document.assert_called_once_with(
self.report, document, self.report.report_type)
self.report.report_name, document, self.report.report_type)
def test_print_document_not_printable(self):
""" It should print the report, regardless of the defined behaviour """