mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[FIX] .travis.yml: Update definition
This commit is contained in:
@@ -8,79 +8,74 @@ from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestIrActionsReportXml(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestIrActionsReportXml, self).setUp()
|
||||
self.Model = self.env['ir.actions.report']
|
||||
self.Model = self.env["ir.actions.report"]
|
||||
self.vals = {}
|
||||
|
||||
self.report = self.env['ir.actions.report'].search([], limit=1)
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.report = self.env["ir.actions.report"].search([], limit=1)
|
||||
self.server = self.env["printing.server"].create({})
|
||||
|
||||
def new_action(self):
|
||||
return self.env['printing.action'].create({
|
||||
'name': 'Printing Action',
|
||||
'action_type': 'server',
|
||||
})
|
||||
return self.env["printing.action"].create(
|
||||
{"name": "Printing Action", "action_type": "server"}
|
||||
)
|
||||
|
||||
def new_printing_action(self):
|
||||
return self.env['printing.report.xml.action'].create({
|
||||
'report_id': self.report.id,
|
||||
'user_id': self.env.ref('base.user_demo').id,
|
||||
'action': 'server',
|
||||
})
|
||||
return self.env["printing.report.xml.action"].create(
|
||||
{
|
||||
"report_id": self.report.id,
|
||||
"user_id": self.env.ref("base.user_demo").id,
|
||||
"action": "server",
|
||||
}
|
||||
)
|
||||
|
||||
def new_printer(self):
|
||||
return self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
return self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
|
||||
def new_tray(self, vals=None, defaults=None):
|
||||
values = dict(defaults)
|
||||
if vals is not None:
|
||||
values.update(vals)
|
||||
return self.env['printing.tray'].create(values)
|
||||
return self.env["printing.tray"].create(values)
|
||||
|
||||
def test_print_action_for_report_name_gets_report(self):
|
||||
""" It should get report by name """
|
||||
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
|
||||
expect = 'test'
|
||||
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
|
||||
expect = "test"
|
||||
self.Model.print_action_for_report_name(expect)
|
||||
mk.assert_called_once_with(
|
||||
expect
|
||||
)
|
||||
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, '_get_report_from_name') as mk:
|
||||
expect = 'test'
|
||||
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
|
||||
expect = "test"
|
||||
mk.return_value = False
|
||||
res = self.Model.print_action_for_report_name(expect)
|
||||
self.assertDictEqual(
|
||||
{}, res,
|
||||
)
|
||||
self.assertDictEqual({}, res)
|
||||
|
||||
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, '_get_report_from_name') as mk:
|
||||
res = self.Model.print_action_for_report_name('test')
|
||||
with mock.patch.object(self.Model, "_get_report_from_name") as mk:
|
||||
res = self.Model.print_action_for_report_name("test")
|
||||
behaviour = mk().behaviour()
|
||||
expect = {
|
||||
'action': behaviour['action'],
|
||||
'printer_name': behaviour['printer'].name,
|
||||
"action": behaviour["action"],
|
||||
"printer_name": behaviour["printer"].name,
|
||||
}
|
||||
self.assertDictEqual(
|
||||
expect, res,
|
||||
'Expect %s, Got %s' % (expect, res),
|
||||
)
|
||||
self.assertDictEqual(expect, res, "Expect {}, Got {}".format(expect, res))
|
||||
|
||||
def test_behaviour_default_values(self):
|
||||
""" It should return the default action and printer """
|
||||
@@ -89,81 +84,81 @@ class TestIrActionsReportXml(TransactionCase):
|
||||
self.env.user.printing_printer_id = False
|
||||
report.property_printing_action_id = False
|
||||
report.printing_printer_id = False
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': self.env['printing.printer'],
|
||||
'tray': False,
|
||||
},
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{
|
||||
"action": "client",
|
||||
"printer": self.env["printing.printer"],
|
||||
"tray": False,
|
||||
},
|
||||
)
|
||||
|
||||
def test_behaviour_user_values(self):
|
||||
""" It should return the action and printer from user """
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
self.env.user.printing_printer_id = self.new_printer()
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': self.env.user.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{
|
||||
"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 """
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
report.property_printing_action_id = self.new_action()
|
||||
report.printing_printer_id = self.new_printer()
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': report.property_printing_action_id.action_type,
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{
|
||||
"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"""
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
report.property_printing_action_id.action_type = 'user_default'
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
self.env.user.printing_action = "client"
|
||||
report.property_printing_action_id.action_type = "user_default"
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{"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
|
||||
"""
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
printing_action = self.new_printing_action()
|
||||
printing_action.user_id = self.env['res.users'].search([
|
||||
('id', '!=', self.env.user.id),
|
||||
], limit=1)
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
printing_action.user_id = self.env["res.users"].search(
|
||||
[("id", "!=", self.env.user.id)], limit=1
|
||||
)
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{"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
|
||||
"""
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
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'].search([
|
||||
('id', '!=', report.id),
|
||||
], limit=1)
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
printing_action.report_id = self.env["ir.actions.report"].search(
|
||||
[("id", "!=", report.id)], limit=1
|
||||
)
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{"action": "client", "printer": report.printing_printer_id, "tray": False},
|
||||
)
|
||||
|
||||
def test_behaviour_printing_action_with_no_printer(self):
|
||||
@@ -171,29 +166,33 @@ class TestIrActionsReportXml(TransactionCase):
|
||||
other
|
||||
"""
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
printing_action = self.new_printing_action()
|
||||
printing_action.user_id = self.env.user
|
||||
printing_action.report_id = report
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': printing_action.action,
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{
|
||||
"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 """
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
printing_action = self.new_printing_action()
|
||||
printing_action.user_id = self.env.user
|
||||
printing_action.printer_id = self.new_printer()
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': printing_action.action,
|
||||
'printer': printing_action.printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{
|
||||
"action": printing_action.action,
|
||||
"printer": printing_action.printer_id,
|
||||
"tray": False,
|
||||
},
|
||||
)
|
||||
|
||||
def test_behaviour_printing_action_user_defaults(self):
|
||||
@@ -201,106 +200,96 @@ class TestIrActionsReportXml(TransactionCase):
|
||||
action
|
||||
"""
|
||||
report = self.Model.search([], limit=1)
|
||||
self.env.user.printing_action = 'client'
|
||||
self.env.user.printing_action = "client"
|
||||
printing_action = self.new_printing_action()
|
||||
printing_action.user_id = self.env.user
|
||||
printing_action.action = 'user_default'
|
||||
self.assertEqual(report.behaviour(), {
|
||||
'action': 'client',
|
||||
'printer': report.printing_printer_id,
|
||||
'tray': False,
|
||||
},
|
||||
printing_action.action = "user_default"
|
||||
self.assertEqual(
|
||||
report.behaviour(),
|
||||
{"action": "client", "printer": report.printing_printer_id, "tray": False},
|
||||
)
|
||||
|
||||
def test_print_tray_behaviour(self):
|
||||
"""
|
||||
It should return the correct tray
|
||||
"""
|
||||
report = self.env['ir.actions.report'].search([], limit=1)
|
||||
action = self.env['printing.report.xml.action'].create({
|
||||
'user_id': self.env.user.id,
|
||||
'report_id': report.id,
|
||||
'action': 'server',
|
||||
})
|
||||
report = self.env["ir.actions.report"].search([], limit=1)
|
||||
action = self.env["printing.report.xml.action"].create(
|
||||
{"user_id": self.env.user.id, "report_id": report.id, "action": "server"}
|
||||
)
|
||||
printer = self.new_printer()
|
||||
tray_vals = {
|
||||
'name': 'Tray',
|
||||
'system_name': 'Tray',
|
||||
'printer_id': printer.id,
|
||||
}
|
||||
user_tray = self.new_tray({'system_name': 'User tray'}, tray_vals)
|
||||
report_tray = self.new_tray({'system_name': 'Report tray'}, tray_vals)
|
||||
action_tray = self.new_tray({'system_name': 'Action tray'}, tray_vals)
|
||||
tray_vals = {"name": "Tray", "system_name": "Tray", "printer_id": printer.id}
|
||||
user_tray = self.new_tray({"system_name": "User tray"}, tray_vals)
|
||||
report_tray = self.new_tray({"system_name": "Report tray"}, tray_vals)
|
||||
action_tray = self.new_tray({"system_name": "Action tray"}, tray_vals)
|
||||
|
||||
# No report passed
|
||||
self.env.user.printer_tray_id = False
|
||||
options = printer.print_options()
|
||||
self.assertFalse('InputSlot' in options)
|
||||
self.assertFalse("InputSlot" in options)
|
||||
|
||||
# No tray defined
|
||||
self.env.user.printer_tray_id = False
|
||||
report.printer_tray_id = False
|
||||
action.printer_tray_id = False
|
||||
options = report.behaviour()
|
||||
self.assertTrue('tray' in options)
|
||||
self.assertTrue("tray" 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
|
||||
self.assertEqual('User tray', report.behaviour()['tray'])
|
||||
self.assertEqual("User tray", report.behaviour()["tray"])
|
||||
|
||||
# Only report tray is defined
|
||||
self.env.user.printer_tray_id = False
|
||||
report.printer_tray_id = report_tray
|
||||
action.printer_tray_id = False
|
||||
self.assertEqual('Report tray', report.behaviour()['tray'])
|
||||
self.assertEqual("Report tray", report.behaviour()["tray"])
|
||||
|
||||
# Only action tray is defined
|
||||
self.env.user.printer_tray_id = False
|
||||
report.printer_tray_id = False
|
||||
action.printer_tray_id = action_tray
|
||||
self.assertEqual('Action tray', report.behaviour()['tray'])
|
||||
self.assertEqual("Action tray", report.behaviour()["tray"])
|
||||
|
||||
# User and report tray defined
|
||||
self.env.user.printer_tray_id = user_tray
|
||||
report.printer_tray_id = report_tray
|
||||
action.printer_tray_id = False
|
||||
self.assertEqual('Report tray', report.behaviour()['tray'])
|
||||
self.assertEqual("Report tray", report.behaviour()["tray"])
|
||||
|
||||
# All trays are defined
|
||||
self.env.user.printer_tray_id = user_tray
|
||||
report.printer_tray_id = report_tray
|
||||
action.printer_tray_id = action_tray
|
||||
self.assertEqual('Action tray', report.behaviour()['tray'])
|
||||
self.assertEqual("Action tray", report.behaviour()["tray"])
|
||||
|
||||
def test_onchange_printer_tray_id_empty(self):
|
||||
action = self.env['ir.actions.report'].new(
|
||||
{'printer_tray_id': False})
|
||||
action = self.env["ir.actions.report"].new({"printer_tray_id": False})
|
||||
action.onchange_printing_printer_id()
|
||||
self.assertFalse(action.printer_tray_id)
|
||||
|
||||
def test_onchange_printer_tray_id_not_empty(self):
|
||||
server = self.env['printing.server'].create({})
|
||||
printer = self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
tray = self.env['printing.tray'].create({
|
||||
'name': 'Tray',
|
||||
'system_name': 'TrayName',
|
||||
'printer_id': printer.id,
|
||||
})
|
||||
server = self.env["printing.server"].create({})
|
||||
printer = self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
tray = self.env["printing.tray"].create(
|
||||
{"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
|
||||
)
|
||||
|
||||
action = self.env['ir.actions.report'].new(
|
||||
{'printer_tray_id': tray.id})
|
||||
action = self.env["ir.actions.report"].new({"printer_tray_id": tray.id})
|
||||
self.assertEqual(action.printer_tray_id, tray)
|
||||
action.onchange_printing_printer_id()
|
||||
self.assertFalse(action.printer_tray_id)
|
||||
|
||||
@@ -6,60 +6,58 @@ import mock
|
||||
from odoo import fields
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
|
||||
class TestPrintingJob(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingJob, self).setUp()
|
||||
self.Model = self.env['printing.server']
|
||||
self.Model = self.env["printing.server"]
|
||||
self.server = self.Model.create({})
|
||||
self.printer_vals = {
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
self.job_vals = {
|
||||
'server_id': self.server.id,
|
||||
'job_id_cups': 1,
|
||||
'job_media_progress': 0,
|
||||
'time_at_creation': fields.Datetime.now(),
|
||||
"server_id": self.server.id,
|
||||
"job_id_cups": 1,
|
||||
"job_media_progress": 0,
|
||||
"time_at_creation": fields.Datetime.now(),
|
||||
}
|
||||
|
||||
def new_printer(self):
|
||||
return self.env['printing.printer'].create(self.printer_vals)
|
||||
return self.env["printing.printer"].create(self.printer_vals)
|
||||
|
||||
def new_job(self, printer, vals=None):
|
||||
values = self.job_vals
|
||||
if vals is not None:
|
||||
values.update(vals)
|
||||
values['printer_id'] = printer.id
|
||||
return self.env['printing.job'].create(values)
|
||||
values["printer_id"] = printer.id
|
||||
return self.env["printing.job"].create(values)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_cancel_job_error(self, cups):
|
||||
""" It should catch any exception from CUPS and update status """
|
||||
cups.Connection.side_effect = Exception
|
||||
printer = self.new_printer()
|
||||
job = self.new_job(printer, {'job_id_cups': 2})
|
||||
job = self.new_job(printer, {"job_id_cups": 2})
|
||||
job.action_cancel()
|
||||
cups.Connection.side_effect = None
|
||||
self.assertEqual(cups.Connection().cancelJob.call_count, 0)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_cancel_job(self, cups):
|
||||
""" It should catch any exception from CUPS and update status """
|
||||
printer = self.new_printer()
|
||||
job = self.new_job(printer)
|
||||
job.cancel()
|
||||
cups.Connection().cancelJob.assert_called_once_with(
|
||||
job.job_id_cups, purge_job=False,
|
||||
job.job_id_cups, purge_job=False
|
||||
)
|
||||
|
||||
@@ -2,35 +2,34 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import tempfile
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_printer'
|
||||
server_model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_printer"
|
||||
server_model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
|
||||
class TestPrintingPrinter(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingPrinter, self).setUp()
|
||||
self.Model = self.env['printing.printer']
|
||||
self.ServerModel = self.env['printing.server']
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.Model = self.env["printing.printer"]
|
||||
self.ServerModel = self.env["printing.server"]
|
||||
self.server = self.env["printing.server"].create({})
|
||||
self.printer_vals = {
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
self.report = self.env['ir.actions.report'].search([], limit=1)
|
||||
self.report = self.env["ir.actions.report"].search([], limit=1)
|
||||
|
||||
def new_record(self):
|
||||
return self.Model.create(self.printer_vals)
|
||||
@@ -39,94 +38,88 @@ class TestPrintingPrinter(TransactionCase):
|
||||
"""
|
||||
It should put the value in InputSlot
|
||||
"""
|
||||
self.assertEqual(self.Model._set_option_tray(None, 'Test Tray'),
|
||||
{'InputSlot': 'Test Tray'})
|
||||
self.assertEqual(self.Model._set_option_tray(None, False),
|
||||
{})
|
||||
self.assertEqual(
|
||||
self.Model._set_option_tray(None, "Test Tray"), {"InputSlot": "Test Tray"}
|
||||
)
|
||||
self.assertEqual(self.Model._set_option_tray(None, False), {})
|
||||
|
||||
def test_option_noops(self):
|
||||
"""
|
||||
Noops should return an empty dict
|
||||
"""
|
||||
self.assertEqual(self.Model._set_option_action(None, 'printer'), {})
|
||||
self.assertEqual(self.Model._set_option_action(None, "printer"), {})
|
||||
self.assertEqual(self.Model._set_option_printer(None, self.Model), {})
|
||||
|
||||
def test_option_doc_format(self):
|
||||
"""
|
||||
Raw documents should set raw boolean.
|
||||
"""
|
||||
self.assertEqual(self.Model._set_option_doc_format(None, 'raw'),
|
||||
{'raw': 'True'})
|
||||
self.assertEqual(
|
||||
self.Model._set_option_doc_format(None, "raw"), {"raw": "True"}
|
||||
)
|
||||
# Deprecate _set_option_format in v12.
|
||||
self.assertEqual(self.Model._set_option_format(None, 'raw'),
|
||||
{'raw': 'True'})
|
||||
self.assertEqual(self.Model._set_option_format(None, "raw"), {"raw": "True"})
|
||||
|
||||
self.assertEqual(self.Model._set_option_doc_format(None, 'pdf'), {})
|
||||
self.assertEqual(self.Model._set_option_doc_format(None, "pdf"), {})
|
||||
# Deprecate _set_option_format in v12.
|
||||
self.assertEqual(self.Model._set_option_format(None, 'pdf'), {})
|
||||
self.assertEqual(self.Model._set_option_format(None, "pdf"), {})
|
||||
|
||||
def test_print_options(self):
|
||||
""" 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
|
||||
report = self.env['ir.actions.report'].search([], limit=1)
|
||||
self.assertEqual(self.Model.print_options(
|
||||
doc_format='raw'), {'raw': 'True'}
|
||||
report = self.env["ir.actions.report"].search([], limit=1)
|
||||
self.assertEqual(self.Model.print_options(doc_format="raw"), {"raw": "True"})
|
||||
self.assertEqual(
|
||||
self.Model.print_options(report, doc_format="pdf", copies=2),
|
||||
{"copies": "2"},
|
||||
)
|
||||
self.assertEqual(self.Model.print_options(
|
||||
report, doc_format='pdf', copies=2), {'copies': '2'}
|
||||
self.assertEqual(
|
||||
self.Model.print_options(report, doc_format="raw", copies=2),
|
||||
{"raw": "True", "copies": "2"},
|
||||
)
|
||||
self.assertEqual(self.Model.print_options(
|
||||
report, doc_format='raw', copies=2),
|
||||
{'raw': 'True', 'copies': '2'}
|
||||
)
|
||||
self.assertTrue('InputSlot' in self.Model.print_options(report,
|
||||
tray='Test'))
|
||||
self.assertTrue("InputSlot" in self.Model.print_options(report, tray="Test"))
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_print_report(self, cups):
|
||||
""" It should print a report through CUPS """
|
||||
fd, file_name = tempfile.mkstemp()
|
||||
with mock.patch('%s.mkstemp' % model) as mkstemp:
|
||||
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',
|
||||
doc_format='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,
|
||||
file_name,
|
||||
options={})
|
||||
printer.system_name, file_name, file_name, options={}
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_print_report_error(self, cups):
|
||||
""" It should print a report through CUPS """
|
||||
cups.Connection.side_effect = Exception
|
||||
fd, file_name = tempfile.mkstemp()
|
||||
with mock.patch('%s.mkstemp' % model) as mkstemp:
|
||||
with mock.patch("%s.mkstemp" % model) as mkstemp:
|
||||
mkstemp.return_value = fd, file_name
|
||||
printer = self.new_record()
|
||||
with self.assertRaises(UserError):
|
||||
printer.print_document(
|
||||
self.report, b'content to print', doc_format='pdf')
|
||||
self.report, b"content to print", doc_format="pdf"
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_print_file(self, cups):
|
||||
""" It should print a file through CUPS """
|
||||
file_name = 'file_name'
|
||||
file_name = "file_name"
|
||||
printer = self.new_record()
|
||||
printer.print_file(file_name, 'pdf')
|
||||
printer.print_file(file_name, "pdf")
|
||||
cups.Connection().printFile.assert_called_once_with(
|
||||
printer.system_name,
|
||||
file_name,
|
||||
file_name,
|
||||
options={})
|
||||
printer.system_name, file_name, file_name, options={}
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_print_file_error(self, cups):
|
||||
""" It should print a file through CUPS """
|
||||
cups.Connection.side_effect = Exception
|
||||
file_name = 'file_name'
|
||||
file_name = "file_name"
|
||||
printer = self.new_record()
|
||||
with self.assertRaises(UserError):
|
||||
printer.print_file(file_name)
|
||||
@@ -150,38 +143,34 @@ class TestPrintingPrinter(TransactionCase):
|
||||
printer.unset_default()
|
||||
self.assertFalse(printer.default)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_cancel_all_jobs(self, cups):
|
||||
""" It should cancel all jobs """
|
||||
printer = self.new_record()
|
||||
printer.action_cancel_all_jobs()
|
||||
cups.Connection().cancelAllJobs.assert_called_once_with(
|
||||
name=printer.system_name,
|
||||
purge_jobs=False,
|
||||
name=printer.system_name, purge_jobs=False
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_cancel_and_purge_all_jobs(self, cups):
|
||||
""" It should cancel all jobs """
|
||||
printer = self.new_record()
|
||||
printer.cancel_all_jobs(purge_jobs=True)
|
||||
cups.Connection().cancelAllJobs.assert_called_once_with(
|
||||
name=printer.system_name,
|
||||
purge_jobs=True,
|
||||
name=printer.system_name, purge_jobs=True
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_enable_printer(self, cups):
|
||||
""" It should enable the printer """
|
||||
printer = self.new_record()
|
||||
printer.enable()
|
||||
cups.Connection().enablePrinter.assert_called_once_with(
|
||||
printer.system_name)
|
||||
cups.Connection().enablePrinter.assert_called_once_with(printer.system_name)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_disable_printer(self, cups):
|
||||
""" It should disable the printer """
|
||||
printer = self.new_record()
|
||||
printer.disable()
|
||||
cups.Connection().disablePrinter.assert_called_once_with(
|
||||
printer.system_name)
|
||||
cups.Connection().disablePrinter.assert_called_once_with(printer.system_name)
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import errno
|
||||
import mock
|
||||
import tempfile
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_printer'
|
||||
server_model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_printer"
|
||||
server_model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
ppd_header = '*PPD-Adobe: "4.3"'
|
||||
ppd_input_slot_header = """
|
||||
@@ -33,34 +34,35 @@ ppd_input_slot_footer = """
|
||||
|
||||
|
||||
class TestPrintingPrinter(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingPrinter, self).setUp()
|
||||
self.Model = self.env['printing.printer']
|
||||
self.ServerModel = self.env['printing.server']
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.printer = self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
self.Model = self.env["printing.printer"]
|
||||
self.ServerModel = self.env["printing.server"]
|
||||
self.server = self.env["printing.server"].create({})
|
||||
self.printer = self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
self.tray_vals = {
|
||||
'name': 'Tray',
|
||||
'system_name': 'TrayName',
|
||||
'printer_id': self.printer.id,
|
||||
"name": "Tray",
|
||||
"system_name": "TrayName",
|
||||
"printer_id": self.printer.id,
|
||||
}
|
||||
|
||||
def new_tray(self, vals=None):
|
||||
values = self.tray_vals
|
||||
if vals is not None:
|
||||
values.update(vals)
|
||||
return self.env['printing.tray'].create(values)
|
||||
return self.env["printing.tray"].create(values)
|
||||
|
||||
def build_ppd(self, input_slots=None):
|
||||
"""
|
||||
@@ -71,8 +73,7 @@ class TestPrintingPrinter(TransactionCase):
|
||||
if input_slots is not None:
|
||||
for input_slot in input_slots:
|
||||
ppd_contents += ppd_input_slot_body.format(
|
||||
name=input_slot['name'],
|
||||
text=input_slot['text'],
|
||||
name=input_slot["name"], text=input_slot["text"]
|
||||
)
|
||||
ppd_contents += ppd_input_slot_footer
|
||||
|
||||
@@ -88,29 +89,29 @@ class TestPrintingPrinter(TransactionCase):
|
||||
|
||||
if file_name:
|
||||
ppd_contents = self.build_ppd(input_slots=input_slots)
|
||||
with open(file_name, 'w') as fp:
|
||||
with open(file_name, "w") as fp:
|
||||
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',
|
||||
},
|
||||
"printer-info": "info",
|
||||
"printer-uri-supported": "uri",
|
||||
}
|
||||
}
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_update_printers(self, cups):
|
||||
"""
|
||||
Check that the update_printers method calls _prepare_update_from_cups
|
||||
"""
|
||||
self.mock_cups_ppd(cups, file_name=False)
|
||||
|
||||
self.assertEqual(self.printer.name, 'Printer')
|
||||
self.assertEqual(self.printer.name, "Printer")
|
||||
self.ServerModel.update_printers()
|
||||
self.assertEqual(self.printer.name, 'info')
|
||||
self.assertEqual(self.printer.name, "info")
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups_no_ppd(self, cups):
|
||||
"""
|
||||
Check that the tray_ids field has no value when no PPD is available
|
||||
@@ -121,9 +122,9 @@ class TestPrintingPrinter(TransactionCase):
|
||||
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||
|
||||
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
self.assertFalse('tray_ids' in vals)
|
||||
self.assertFalse("tray_ids" in vals)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups_empty_ppd(self, cups):
|
||||
"""
|
||||
Check that the tray_ids field has no value when the PPD file has
|
||||
@@ -132,23 +133,23 @@ class TestPrintingPrinter(TransactionCase):
|
||||
fd, file_name = tempfile.mkstemp()
|
||||
self.mock_cups_ppd(cups, file_name=file_name)
|
||||
# Replace the ppd file's contents by an empty file
|
||||
with open(file_name, 'w') as fp:
|
||||
with open(file_name, "w") as fp:
|
||||
fp.write(ppd_header)
|
||||
|
||||
connection = cups.Connection()
|
||||
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||
|
||||
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
self.assertFalse('tray_ids' in vals)
|
||||
self.assertFalse("tray_ids" in vals)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
@mock.patch("os.unlink")
|
||||
def test_prepare_update_from_cups_unlink_error(self, os_unlink, cups):
|
||||
"""
|
||||
When OSError other than ENOENT is encountered, the exception is raised
|
||||
"""
|
||||
# Break os.unlink
|
||||
os_unlink.side_effect = OSError(errno.EIO, 'Error')
|
||||
os_unlink.side_effect = OSError(errno.EIO, "Error")
|
||||
|
||||
self.mock_cups_ppd(cups)
|
||||
|
||||
@@ -158,17 +159,16 @@ class TestPrintingPrinter(TransactionCase):
|
||||
with self.assertRaises(OSError):
|
||||
self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch('os.unlink')
|
||||
def test_prepare_update_from_cups_unlink_error_enoent(
|
||||
self, os_unlink, cups):
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
@mock.patch("os.unlink")
|
||||
def test_prepare_update_from_cups_unlink_error_enoent(self, os_unlink, cups):
|
||||
"""
|
||||
When a ENOENT error is encountered, the file has already been unlinked
|
||||
This is not an issue, as we were trying to delete the file.
|
||||
The update can continue.
|
||||
"""
|
||||
# Break os.unlink
|
||||
os_unlink.side_effect = OSError(errno.ENOENT, 'Error')
|
||||
os_unlink.side_effect = OSError(errno.ENOENT, "Error")
|
||||
|
||||
self.mock_cups_ppd(cups)
|
||||
|
||||
@@ -176,12 +176,12 @@ class TestPrintingPrinter(TransactionCase):
|
||||
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, {
|
||||
'name': 'Auto (Default)',
|
||||
'system_name': 'Auto',
|
||||
})])
|
||||
self.assertEqual(
|
||||
vals["tray_ids"],
|
||||
[(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups(self, cups):
|
||||
"""
|
||||
Check the return value when adding a single tray
|
||||
@@ -192,55 +192,51 @@ class TestPrintingPrinter(TransactionCase):
|
||||
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, {
|
||||
'name': 'Auto (Default)',
|
||||
'system_name': 'Auto',
|
||||
})])
|
||||
self.assertEqual(
|
||||
vals["tray_ids"],
|
||||
[(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups_with_multiple_trays(self, cups):
|
||||
"""
|
||||
Check the return value when adding multiple trays at once
|
||||
"""
|
||||
self.mock_cups_ppd(cups, input_slots=[
|
||||
{'name': 'Tray1', 'text': 'Tray 1'},
|
||||
])
|
||||
self.mock_cups_ppd(cups, input_slots=[{"name": "Tray1", "text": "Tray 1"}])
|
||||
|
||||
connection = cups.Connection()
|
||||
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||
|
||||
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
self.assertItemsEqual(vals['tray_ids'], [(0, 0, {
|
||||
'name': 'Auto (Default)',
|
||||
'system_name': 'Auto',
|
||||
}), (0, 0, {
|
||||
'name': 'Tray 1',
|
||||
'system_name': 'Tray1',
|
||||
})])
|
||||
self.assertItemsEqual(
|
||||
vals["tray_ids"],
|
||||
[
|
||||
(0, 0, {"name": "Auto (Default)", "system_name": "Auto"}),
|
||||
(0, 0, {"name": "Tray 1", "system_name": "Tray1"}),
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups_already_known_trays(self, cups):
|
||||
"""
|
||||
Check that calling the method twice doesn't create the trays multiple
|
||||
times
|
||||
"""
|
||||
self.mock_cups_ppd(cups, input_slots=[
|
||||
{'name': 'Tray1', 'text': 'Tray 1'},
|
||||
])
|
||||
self.mock_cups_ppd(cups, input_slots=[{"name": "Tray1", "text": "Tray 1"}])
|
||||
|
||||
connection = cups.Connection()
|
||||
cups_printer = connection.getPrinters()[self.printer.system_name]
|
||||
|
||||
# Create a tray which is in the PPD file
|
||||
self.new_tray({'system_name': 'Tray1'})
|
||||
self.new_tray({"system_name": "Tray1"})
|
||||
|
||||
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
||||
'name': 'Auto (Default)',
|
||||
'system_name': 'Auto',
|
||||
})])
|
||||
self.assertEqual(
|
||||
vals["tray_ids"],
|
||||
[(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % server_model)
|
||||
@mock.patch("%s.cups" % server_model)
|
||||
def test_prepare_update_from_cups_unknown_trays(self, cups):
|
||||
"""
|
||||
Check that trays which are not in the PPD file are removed from Odoo
|
||||
@@ -254,7 +250,7 @@ class TestPrintingPrinter(TransactionCase):
|
||||
tray = self.new_tray()
|
||||
|
||||
vals = self.printer._prepare_update_from_cups(connection, cups_printer)
|
||||
self.assertEqual(vals['tray_ids'], [(0, 0, {
|
||||
'name': 'Auto (Default)',
|
||||
'system_name': 'Auto',
|
||||
}), (2, tray.id)])
|
||||
self.assertEqual(
|
||||
vals["tray_ids"],
|
||||
[(0, 0, {"name": "Auto (Default)", "system_name": "Auto"}), (2, tray.id)],
|
||||
)
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
|
||||
class StopTest(Exception):
|
||||
@@ -15,90 +14,75 @@ class StopTest(Exception):
|
||||
|
||||
|
||||
class TestPrintingPrinterWizard(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingPrinterWizard, self).setUp()
|
||||
self.Model = self.env['printing.printer.update.wizard']
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.Model = self.env["printing.printer.update.wizard"]
|
||||
self.server = self.env["printing.server"].create({})
|
||||
self.printer_vals = {
|
||||
'printer-info': 'Info',
|
||||
'printer-make-and-model': 'Make and Model',
|
||||
'printer-location': "location",
|
||||
'device-uri': 'URI',
|
||||
'printer-uri-supported': 'uri'
|
||||
"printer-info": "Info",
|
||||
"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'):
|
||||
def _record_vals(self, sys_name="sys_name"):
|
||||
return {
|
||||
'name': self.printer_vals['printer-info'],
|
||||
'server_id': self.server.id,
|
||||
'system_name': sys_name,
|
||||
'model': self.printer_vals['printer-make-and-model'],
|
||||
'location': self.printer_vals['printer-location'],
|
||||
'uri': self.printer_vals['device-uri'],
|
||||
"name": self.printer_vals["printer-info"],
|
||||
"server_id": self.server.id,
|
||||
"system_name": sys_name,
|
||||
"model": self.printer_vals["printer-make-and-model"],
|
||||
"location": self.printer_vals["printer-location"],
|
||||
"uri": self.printer_vals["device-uri"],
|
||||
}
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_action_ok_inits_connection(self, cups):
|
||||
""" It should initialize CUPS connection """
|
||||
self.Model.action_ok()
|
||||
cups.Connection.assert_called_once_with(
|
||||
host=self.server.address, port=self.server.port,
|
||||
host=self.server.address, port=self.server.port
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_action_ok_gets_printers(self, cups):
|
||||
""" It should get printers from CUPS """
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
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()
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_action_ok_raises_warning_on_error(self, cups):
|
||||
""" It should raise Warning on any error """
|
||||
cups.Connection.side_effect = StopTest
|
||||
with self.assertRaises(UserError):
|
||||
self.Model.action_ok()
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_action_ok_creates_new_printer(self, cups):
|
||||
""" It should create new printer w/ proper vals """
|
||||
cups.Connection().getPrinters.return_value = {
|
||||
'sys_name': self.printer_vals,
|
||||
}
|
||||
cups.Connection().getPPD3.return_value = (200, 0, '')
|
||||
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')
|
||||
],
|
||||
limit=1,
|
||||
rec_id = self.env["printing.printer"].search(
|
||||
[("system_name", "=", "sys_name")], limit=1
|
||||
)
|
||||
self.assertTrue(rec_id)
|
||||
for key, val in self._record_vals().items():
|
||||
if rec_id._fields[key].type == 'many2one':
|
||||
if rec_id._fields[key].type == "many2one":
|
||||
val = self.env[rec_id._fields[key].comodel_name].browse(val)
|
||||
|
||||
self.assertEqual(
|
||||
val, rec_id[key],
|
||||
)
|
||||
self.assertEqual(val, rec_id[key])
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_action_ok_skips_existing_printer(self, cups):
|
||||
""" It should not recreate existing printers """
|
||||
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()
|
||||
)
|
||||
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())
|
||||
self.Model.action_ok()
|
||||
res_ids = self.env['printing.printer'].search([
|
||||
('system_name', '=', 'sys_name')
|
||||
])
|
||||
self.assertEqual(
|
||||
1, len(res_ids),
|
||||
res_ids = self.env["printing.printer"].search(
|
||||
[("system_name", "=", "sys_name")]
|
||||
)
|
||||
self.assertEqual(1, len(res_ids))
|
||||
|
||||
@@ -5,18 +5,17 @@ from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestPrintingReportXmlAction(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingReportXmlAction, self).setUp()
|
||||
self.Model = self.env['printing.report.xml.action']
|
||||
self.Model = self.env["printing.report.xml.action"]
|
||||
|
||||
self.report = self.env['ir.actions.report'].search([], limit=1)
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.report = self.env["ir.actions.report"].search([], limit=1)
|
||||
self.server = self.env["printing.server"].create({})
|
||||
|
||||
self.report_vals = {
|
||||
'report_id': self.report.id,
|
||||
'user_id': self.env.ref('base.user_demo').id,
|
||||
'action': 'server',
|
||||
"report_id": self.report.id,
|
||||
"user_id": self.env.ref("base.user_demo").id,
|
||||
"action": "server",
|
||||
}
|
||||
|
||||
def new_record(self, vals=None):
|
||||
@@ -27,65 +26,73 @@ class TestPrintingReportXmlAction(TransactionCase):
|
||||
return self.Model.create(values)
|
||||
|
||||
def new_printer(self):
|
||||
return self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
return self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
|
||||
def test_behaviour(self):
|
||||
""" It should return some action's data, unless called on empty
|
||||
recordset
|
||||
"""
|
||||
xml_action = self.new_record()
|
||||
self.assertEqual(xml_action.behaviour(), {
|
||||
'action': xml_action.action,
|
||||
'printer': xml_action.printer_id,
|
||||
'tray': False,
|
||||
})
|
||||
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,
|
||||
})
|
||||
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(), {})
|
||||
|
||||
def test_onchange_printer_tray_id_empty(self):
|
||||
action = self.env['printing.report.xml.action'].new(
|
||||
{'printer_tray_id': False})
|
||||
action = self.env["printing.report.xml.action"].new({"printer_tray_id": False})
|
||||
action.onchange_printer_id()
|
||||
self.assertFalse(action.printer_tray_id)
|
||||
|
||||
def test_onchange_printer_tray_id_not_empty(self):
|
||||
server = self.env['printing.server'].create({})
|
||||
printer = self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
tray = self.env['printing.tray'].create({
|
||||
'name': 'Tray',
|
||||
'system_name': 'TrayName',
|
||||
'printer_id': printer.id,
|
||||
})
|
||||
server = self.env["printing.server"].create({})
|
||||
printer = self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
tray = self.env["printing.tray"].create(
|
||||
{"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
|
||||
)
|
||||
|
||||
action = self.env['printing.report.xml.action'].new(
|
||||
{'printer_tray_id': tray.id})
|
||||
action = self.env["printing.report.xml.action"].new(
|
||||
{"printer_tray_id": tray.id}
|
||||
)
|
||||
self.assertEqual(action.printer_tray_id, tray)
|
||||
action.onchange_printer_id()
|
||||
self.assertFalse(action.printer_tray_id)
|
||||
|
||||
@@ -6,207 +6,189 @@ import mock
|
||||
from odoo import fields
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
|
||||
class TestPrintingServer(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingServer, self).setUp()
|
||||
self.Model = self.env['printing.server']
|
||||
self.Model = self.env["printing.server"]
|
||||
self.server = self.Model.create({})
|
||||
self.printer_vals = {
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
self.job_vals = {
|
||||
'server_id': self.server.id,
|
||||
'job_id_cups': 1,
|
||||
'job_media_progress': 0,
|
||||
'time_at_creation': fields.Datetime.now(),
|
||||
"server_id": self.server.id,
|
||||
"job_id_cups": 1,
|
||||
"job_media_progress": 0,
|
||||
"time_at_creation": fields.Datetime.now(),
|
||||
}
|
||||
|
||||
def new_printer(self):
|
||||
return self.env['printing.printer'].create(self.printer_vals)
|
||||
return self.env["printing.printer"].create(self.printer_vals)
|
||||
|
||||
def new_job(self, printer, vals=None):
|
||||
values = self.job_vals
|
||||
if vals is not None:
|
||||
values.update(vals)
|
||||
values['printer_id'] = printer.id
|
||||
return self.env['printing.job'].create(values)
|
||||
values["printer_id"] = printer.id
|
||||
return self.env["printing.job"].create(values)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_error(self, cups):
|
||||
""" It should catch any exception from CUPS and update status """
|
||||
cups.Connection.side_effect = Exception
|
||||
rec_id = self.new_printer()
|
||||
self.Model.update_printers()
|
||||
self.assertEqual(
|
||||
'server-error', rec_id.status,
|
||||
)
|
||||
self.assertEqual("server-error", rec_id.status)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_inits_cups(self, cups):
|
||||
""" It should init CUPS connection """
|
||||
self.new_printer()
|
||||
self.Model.update_printers()
|
||||
cups.Connection.assert_called_once_with(
|
||||
host=self.server.address, port=self.server.port,
|
||||
host=self.server.address, port=self.server.port
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_gets_all_printers(self, cups):
|
||||
""" It should get all printers from CUPS server """
|
||||
self.new_printer()
|
||||
self.Model.update_printers()
|
||||
cups.Connection().getPrinters.assert_called_once_with()
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_search(self, cups):
|
||||
""" It should search all when no domain """
|
||||
with mock.patch.object(self.Model, 'search') as search:
|
||||
with mock.patch.object(self.Model, "search") as search:
|
||||
self.Model.update_printers()
|
||||
search.assert_called_once_with([])
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_search_domain(self, cups):
|
||||
""" It should use specific domain for search """
|
||||
with mock.patch.object(self.Model, 'search') as search:
|
||||
expect = [('id', '>', 0)]
|
||||
with mock.patch.object(self.Model, "search") as search:
|
||||
expect = [("id", ">", 0)]
|
||||
self.Model.update_printers(expect)
|
||||
search.assert_called_once_with(expect)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_printers_update_unavailable(self, cups):
|
||||
""" It should update status when printer is unavailable """
|
||||
rec_id = self.new_printer()
|
||||
cups.Connection().getPrinters().get.return_value = False
|
||||
self.Model.action_update_printers()
|
||||
self.assertEqual(
|
||||
'unavailable', rec_id.status,
|
||||
)
|
||||
self.assertEqual("unavailable", rec_id.status)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_jobs_cron(self, cups):
|
||||
""" It should get all jobs from CUPS server """
|
||||
self.new_printer()
|
||||
self.Model.action_update_jobs()
|
||||
cups.Connection().getPrinters.assert_called_once_with()
|
||||
cups.Connection().getJobs.assert_called_once_with(
|
||||
which_jobs='all',
|
||||
which_jobs="all",
|
||||
first_job_id=-1,
|
||||
requested_attributes=[
|
||||
'job-name',
|
||||
'job-id',
|
||||
'printer-uri',
|
||||
'job-media-progress',
|
||||
'time-at-creation',
|
||||
'job-state',
|
||||
'job-state-reasons',
|
||||
'time-at-processing',
|
||||
'time-at-completed',
|
||||
"job-name",
|
||||
"job-id",
|
||||
"printer-uri",
|
||||
"job-media-progress",
|
||||
"time-at-creation",
|
||||
"job-state",
|
||||
"job-state-reasons",
|
||||
"time-at-processing",
|
||||
"time-at-completed",
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_jobs_button(self, cups):
|
||||
""" It should get all jobs from CUPS server """
|
||||
self.new_printer()
|
||||
self.server.action_update_jobs()
|
||||
cups.Connection().getPrinters.assert_called_once_with()
|
||||
cups.Connection().getJobs.assert_called_once_with(
|
||||
which_jobs='all',
|
||||
which_jobs="all",
|
||||
first_job_id=-1,
|
||||
requested_attributes=[
|
||||
'job-name',
|
||||
'job-id',
|
||||
'printer-uri',
|
||||
'job-media-progress',
|
||||
'time-at-creation',
|
||||
'job-state',
|
||||
'job-state-reasons',
|
||||
'time-at-processing',
|
||||
'time-at-completed',
|
||||
"job-name",
|
||||
"job-id",
|
||||
"printer-uri",
|
||||
"job-media-progress",
|
||||
"time-at-creation",
|
||||
"job-state",
|
||||
"job-state-reasons",
|
||||
"time-at-processing",
|
||||
"time-at-completed",
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_jobs_error(self, cups):
|
||||
""" It should catch any exception from CUPS and update status """
|
||||
cups.Connection.side_effect = Exception
|
||||
self.new_printer()
|
||||
self.server.update_jobs()
|
||||
cups.Connection.assert_called_with(
|
||||
host=self.server.address, port=self.server.port,
|
||||
host=self.server.address, port=self.server.port
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_jobs_uncompleted(self, cups):
|
||||
"""
|
||||
It should search which jobs have been completed since last update
|
||||
"""
|
||||
printer = self.new_printer()
|
||||
self.new_job(printer, vals={'job_state': 'completed'})
|
||||
self.new_job(printer, vals={
|
||||
'job_id_cups': 2,
|
||||
'job_state': 'processing',
|
||||
})
|
||||
self.server.update_jobs(which='not-completed')
|
||||
self.new_job(printer, vals={"job_state": "completed"})
|
||||
self.new_job(printer, vals={"job_id_cups": 2, "job_state": "processing"})
|
||||
self.server.update_jobs(which="not-completed")
|
||||
cups.Connection().getJobs.assert_any_call(
|
||||
which_jobs='completed', first_job_id=2,
|
||||
which_jobs="completed",
|
||||
first_job_id=2,
|
||||
requested_attributes=[
|
||||
'job-name',
|
||||
'job-id',
|
||||
'printer-uri',
|
||||
'job-media-progress',
|
||||
'time-at-creation',
|
||||
'job-state',
|
||||
'job-state-reasons',
|
||||
'time-at-processing',
|
||||
'time-at-completed',
|
||||
"job-name",
|
||||
"job-id",
|
||||
"printer-uri",
|
||||
"job-media-progress",
|
||||
"time-at-creation",
|
||||
"job-state",
|
||||
"job-state-reasons",
|
||||
"time-at-processing",
|
||||
"time-at-completed",
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch('%s.cups' % model)
|
||||
@mock.patch("%s.cups" % model)
|
||||
def test_update_jobs(self, cups):
|
||||
"""
|
||||
It should update all jobs, known or not
|
||||
"""
|
||||
printer = self.new_printer()
|
||||
printer_uri = 'hostname:port/' + printer.system_name
|
||||
printer_uri = "hostname:port/" + printer.system_name
|
||||
cups.Connection().getJobs.return_value = {
|
||||
1: {
|
||||
'printer-uri': printer_uri,
|
||||
},
|
||||
2: {
|
||||
'printer-uri': printer_uri,
|
||||
'job-state': 9,
|
||||
},
|
||||
4: {
|
||||
'printer-uri': printer_uri,
|
||||
'job-state': 5,
|
||||
},
|
||||
1: {"printer-uri": printer_uri},
|
||||
2: {"printer-uri": printer_uri, "job-state": 9},
|
||||
4: {"printer-uri": printer_uri, "job-state": 5},
|
||||
}
|
||||
self.new_job(printer, vals={'job_state': 'completed'})
|
||||
completed_job = self.new_job(printer, vals={
|
||||
'job_id_cups': 2,
|
||||
'job_state': 'processing',
|
||||
})
|
||||
purged_job = self.new_job(printer, vals={
|
||||
'job_id_cups': 3,
|
||||
'job_state': 'processing',
|
||||
})
|
||||
self.new_job(printer, vals={"job_state": "completed"})
|
||||
completed_job = self.new_job(
|
||||
printer, vals={"job_id_cups": 2, "job_state": "processing"}
|
||||
)
|
||||
purged_job = self.new_job(
|
||||
printer, vals={"job_id_cups": 3, "job_state": "processing"}
|
||||
)
|
||||
self.server.update_jobs()
|
||||
new_job = self.env['printing.job'].search([('job_id_cups', '=', 4)])
|
||||
self.assertEqual(completed_job.job_state, 'completed')
|
||||
new_job = self.env["printing.job"].search([("job_id_cups", "=", 4)])
|
||||
self.assertEqual(completed_job.job_state, "completed")
|
||||
self.assertEqual(purged_job.active, False)
|
||||
self.assertEqual(new_job.job_state, 'processing')
|
||||
self.assertEqual(new_job.job_state, "processing")
|
||||
|
||||
@@ -3,49 +3,47 @@
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
model = 'odoo.addons.base_report_to_printer.models.printing_server'
|
||||
model = "odoo.addons.base_report_to_printer.models.printing_server"
|
||||
|
||||
|
||||
class TestPrintingTray(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrintingTray, self).setUp()
|
||||
self.Model = self.env['printing.tray']
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.printer = self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
self.Model = self.env["printing.tray"]
|
||||
self.server = self.env["printing.server"].create({})
|
||||
self.printer = self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
self.tray_vals = {
|
||||
'name': 'Tray',
|
||||
'system_name': 'TrayName',
|
||||
'printer_id': self.printer.id,
|
||||
"name": "Tray",
|
||||
"system_name": "TrayName",
|
||||
"printer_id": self.printer.id,
|
||||
}
|
||||
|
||||
def new_tray(self):
|
||||
return self.env['printing.tray'].create(self.tray_vals)
|
||||
return self.env["printing.tray"].create(self.tray_vals)
|
||||
|
||||
def test_report_behaviour(self):
|
||||
""" It should add the selected tray in the report data """
|
||||
ir_report = self.env['ir.actions.report'].search([], limit=1)
|
||||
report = self.env['printing.report.xml.action'].create({
|
||||
'user_id': self.env.user.id,
|
||||
'report_id': ir_report.id,
|
||||
'action': 'server',
|
||||
})
|
||||
ir_report = self.env["ir.actions.report"].search([], limit=1)
|
||||
report = self.env["printing.report.xml.action"].create(
|
||||
{"user_id": self.env.user.id, "report_id": ir_report.id, "action": "server"}
|
||||
)
|
||||
report.printer_tray_id = False
|
||||
behaviour = report.behaviour()
|
||||
self.assertEqual(behaviour['tray'], False)
|
||||
self.assertEqual(behaviour["tray"], False)
|
||||
|
||||
# Check that we have te right value
|
||||
report.printer_tray_id = self.new_tray()
|
||||
behaviour = report.behaviour()
|
||||
self.assertEqual(behaviour['tray'], report.printer_tray_id.system_name)
|
||||
self.assertEqual(behaviour["tray"], report.printer_tray_id.system_name)
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import mock
|
||||
from odoo.tests import common
|
||||
|
||||
from odoo import exceptions
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
@common.at_install(False)
|
||||
@@ -12,118 +13,124 @@ from odoo import exceptions
|
||||
class TestReport(common.HttpCase):
|
||||
def setUp(self):
|
||||
super(TestReport, self).setUp()
|
||||
self.Model = self.env['ir.actions.report']
|
||||
self.server = self.env['printing.server'].create({})
|
||||
self.Model = self.env["ir.actions.report"]
|
||||
self.server = self.env["printing.server"].create({})
|
||||
self.report_vals = {
|
||||
'name': 'Test Report',
|
||||
'model': 'ir.actions.report',
|
||||
'report_name': 'Test Report',
|
||||
"name": "Test Report",
|
||||
"model": "ir.actions.report",
|
||||
"report_name": "Test Report",
|
||||
}
|
||||
self.report_imd = self.env["ir.model.data"].create({
|
||||
"name": "test",
|
||||
"module": "base_report_to_printer",
|
||||
"model": "ir.ui.view",
|
||||
})
|
||||
self.report_view = self.env["ir.ui.view"].create({
|
||||
"name": "Test",
|
||||
"type": "qweb",
|
||||
"xml_id": "base_report_to_printer.test",
|
||||
"model_data_id": self.report_imd.id,
|
||||
"arch": """<t t-name="base_report_to_printer.test">
|
||||
self.report_imd = self.env["ir.model.data"].create(
|
||||
{"name": "test", "module": "base_report_to_printer", "model": "ir.ui.view"}
|
||||
)
|
||||
self.report_view = self.env["ir.ui.view"].create(
|
||||
{
|
||||
"name": "Test",
|
||||
"type": "qweb",
|
||||
"xml_id": "base_report_to_printer.test",
|
||||
"model_data_id": self.report_imd.id,
|
||||
"arch": """<t t-name="base_report_to_printer.test">
|
||||
<div>Test</div>
|
||||
</t>""",
|
||||
})
|
||||
}
|
||||
)
|
||||
self.report_imd.res_id = self.report_view.id
|
||||
self.report = self.Model.create({
|
||||
"name": "Test",
|
||||
"report_type": "qweb-pdf",
|
||||
"model": "res.partner",
|
||||
"report_name": "base_report_to_printer.test",
|
||||
})
|
||||
self.report = self.Model.create(
|
||||
{
|
||||
"name": "Test",
|
||||
"report_type": "qweb-pdf",
|
||||
"model": "res.partner",
|
||||
"report_name": "base_report_to_printer.test",
|
||||
}
|
||||
)
|
||||
self.partners = self.env["res.partner"]
|
||||
for n in range(5):
|
||||
self.partners += self.env["res.partner"].create({
|
||||
"name": "Test %d" % n,
|
||||
})
|
||||
self.partners += self.env["res.partner"].create({"name": "Test %d" % n})
|
||||
|
||||
def new_record(self):
|
||||
return self.Model.create(self.report_vals)
|
||||
|
||||
def new_printer(self):
|
||||
return self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': self.server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
return self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": self.server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
|
||||
def test_can_print_report_context_skip(self):
|
||||
""" It should return False based on context """
|
||||
rec_id = self.new_record().with_context(
|
||||
must_skip_send_to_printer=True
|
||||
)
|
||||
res = rec_id._can_print_report(
|
||||
{'action': 'server'}, True, True
|
||||
)
|
||||
rec_id = self.new_record().with_context(must_skip_send_to_printer=True)
|
||||
res = rec_id._can_print_report({"action": "server"}, True, True)
|
||||
self.assertFalse(res)
|
||||
|
||||
def test_can_print_report_true(self):
|
||||
""" It should return True when server print allowed """
|
||||
res = self.new_record()._can_print_report(
|
||||
{'action': 'server'}, True, True
|
||||
)
|
||||
res = self.new_record()._can_print_report({"action": "server"}, True, True)
|
||||
self.assertTrue(res)
|
||||
|
||||
def test_can_print_report_false(self):
|
||||
""" It should return False when server print not allowed """
|
||||
res = self.new_record()._can_print_report(
|
||||
{'action': 'server'}, True, False
|
||||
)
|
||||
res = self.new_record()._can_print_report({"action": "server"}, True, False)
|
||||
self.assertFalse(res)
|
||||
|
||||
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:
|
||||
with mock.patch(
|
||||
"odoo.addons.base_report_to_printer.models."
|
||||
"printing_printer.PrintingPrinter."
|
||||
"print_document"
|
||||
) as print_document:
|
||||
self.report.render_qweb_pdf(self.partners.ids)
|
||||
print_document.assert_not_called()
|
||||
|
||||
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:
|
||||
self.report.property_printing_action_id.action_type = 'server'
|
||||
with mock.patch(
|
||||
"odoo.addons.base_report_to_printer.models."
|
||||
"printing_printer.PrintingPrinter."
|
||||
"print_document"
|
||||
) as print_document:
|
||||
self.report.property_printing_action_id.action_type = "server"
|
||||
self.report.printing_printer_id = self.new_printer()
|
||||
document = self.report.render_qweb_pdf(self.partners.ids)
|
||||
print_document.assert_called_once_with(
|
||||
self.report, document[0],
|
||||
action='server', doc_format='qweb-pdf', tray=False)
|
||||
self.report,
|
||||
document[0],
|
||||
action="server",
|
||||
doc_format="qweb-pdf",
|
||||
tray=False,
|
||||
)
|
||||
|
||||
def test_print_document_not_printable(self):
|
||||
""" It should print the report, regardless of the defined behaviour """
|
||||
self.report.printing_printer_id = self.new_printer()
|
||||
with mock.patch('odoo.addons.base_report_to_printer.models.'
|
||||
'printing_printer.PrintingPrinter.'
|
||||
'print_document') as print_document:
|
||||
with mock.patch(
|
||||
"odoo.addons.base_report_to_printer.models."
|
||||
"printing_printer.PrintingPrinter."
|
||||
"print_document"
|
||||
) as print_document:
|
||||
self.report.print_document(self.partners.ids)
|
||||
print_document.assert_called_once()
|
||||
|
||||
def test_print_document_printable(self):
|
||||
""" It should print the report, regardless of the defined behaviour """
|
||||
self.report.property_printing_action_id.action_type = 'server'
|
||||
self.report.property_printing_action_id.action_type = "server"
|
||||
self.report.printing_printer_id = self.new_printer()
|
||||
with mock.patch('odoo.addons.base_report_to_printer.models.'
|
||||
'printing_printer.PrintingPrinter.'
|
||||
'print_document') as print_document:
|
||||
with mock.patch(
|
||||
"odoo.addons.base_report_to_printer.models."
|
||||
"printing_printer.PrintingPrinter."
|
||||
"print_document"
|
||||
) as print_document:
|
||||
self.report.print_document(self.partners.ids)
|
||||
print_document.assert_called_once()
|
||||
|
||||
|
||||
@@ -7,54 +7,49 @@ from odoo.tests import common
|
||||
@common.at_install(False)
|
||||
@common.post_install(True)
|
||||
class TestResUsers(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestResUsers, self).setUp()
|
||||
self.user_vals = {'name': 'Test',
|
||||
'login': 'login',
|
||||
}
|
||||
self.user_vals = {"name": "Test", "login": "login"}
|
||||
|
||||
def new_record(self):
|
||||
return self.env['res.users'].create(self.user_vals)
|
||||
return self.env["res.users"].create(self.user_vals)
|
||||
|
||||
def test_available_action_types_excludes_user_default(self):
|
||||
""" It should not contain `user_default` in avail actions """
|
||||
self.user_vals['printing_action'] = 'user_default'
|
||||
self.user_vals["printing_action"] = "user_default"
|
||||
with self.assertRaises(ValueError):
|
||||
self.new_record()
|
||||
|
||||
def test_available_action_types_includes_something_else(self):
|
||||
""" It should still contain other valid keys """
|
||||
self.user_vals['printing_action'] = 'server'
|
||||
self.user_vals["printing_action"] = "server"
|
||||
self.assertTrue(self.new_record())
|
||||
|
||||
def test_onchange_printer_tray_id_empty(self):
|
||||
user = self.env['res.users'].new(
|
||||
{'printer_tray_id': False})
|
||||
user = self.env["res.users"].new({"printer_tray_id": False})
|
||||
user.onchange_printing_printer_id()
|
||||
self.assertFalse(user.printer_tray_id)
|
||||
|
||||
def test_onchange_printer_tray_id_not_empty(self):
|
||||
server = self.env['printing.server'].create({})
|
||||
printer = self.env['printing.printer'].create({
|
||||
'name': 'Printer',
|
||||
'server_id': server.id,
|
||||
'system_name': 'Sys Name',
|
||||
'default': True,
|
||||
'status': 'unknown',
|
||||
'status_message': 'Msg',
|
||||
'model': 'res.users',
|
||||
'location': 'Location',
|
||||
'uri': 'URI',
|
||||
})
|
||||
tray = self.env['printing.tray'].create({
|
||||
'name': 'Tray',
|
||||
'system_name': 'TrayName',
|
||||
'printer_id': printer.id,
|
||||
})
|
||||
server = self.env["printing.server"].create({})
|
||||
printer = self.env["printing.printer"].create(
|
||||
{
|
||||
"name": "Printer",
|
||||
"server_id": server.id,
|
||||
"system_name": "Sys Name",
|
||||
"default": True,
|
||||
"status": "unknown",
|
||||
"status_message": "Msg",
|
||||
"model": "res.users",
|
||||
"location": "Location",
|
||||
"uri": "URI",
|
||||
}
|
||||
)
|
||||
tray = self.env["printing.tray"].create(
|
||||
{"name": "Tray", "system_name": "TrayName", "printer_id": printer.id}
|
||||
)
|
||||
|
||||
user = self.env['res.users'].new(
|
||||
{'printer_tray_id': tray.id})
|
||||
user = self.env["res.users"].new({"printer_tray_id": tray.id})
|
||||
self.assertEqual(user.printer_tray_id, tray)
|
||||
user.onchange_printing_printer_id()
|
||||
self.assertFalse(user.printer_tray_id)
|
||||
|
||||
Reference in New Issue
Block a user