odoo-addon-base-report-to-printer 17.0.1.1.1__py3-none-any.whl → 18.0.1.0.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of odoo-addon-base-report-to-printer might be problematic. Click here for more details.

Files changed (54) hide show
  1. odoo/addons/base_report_to_printer/README.rst +52 -45
  2. odoo/addons/base_report_to_printer/__manifest__.py +1 -1
  3. odoo/addons/base_report_to_printer/data/printing_data.xml +5 -11
  4. odoo/addons/base_report_to_printer/i18n/am.po +0 -11
  5. odoo/addons/base_report_to_printer/i18n/base_report_to_printer.pot +1 -12
  6. odoo/addons/base_report_to_printer/i18n/bg.po +0 -11
  7. odoo/addons/base_report_to_printer/i18n/ca.po +0 -11
  8. odoo/addons/base_report_to_printer/i18n/de.po +0 -11
  9. odoo/addons/base_report_to_printer/i18n/el_GR.po +0 -11
  10. odoo/addons/base_report_to_printer/i18n/es.po +0 -11
  11. odoo/addons/base_report_to_printer/i18n/es_AR.po +0 -11
  12. odoo/addons/base_report_to_printer/i18n/es_ES.po +0 -11
  13. odoo/addons/base_report_to_printer/i18n/fi.po +0 -11
  14. odoo/addons/base_report_to_printer/i18n/fr.po +0 -11
  15. odoo/addons/base_report_to_printer/i18n/gl.po +0 -11
  16. odoo/addons/base_report_to_printer/i18n/hr.po +0 -11
  17. odoo/addons/base_report_to_printer/i18n/hr_HR.po +0 -11
  18. odoo/addons/base_report_to_printer/i18n/it.po +1 -12
  19. odoo/addons/base_report_to_printer/i18n/nl.po +0 -11
  20. odoo/addons/base_report_to_printer/i18n/nl_NL.po +0 -11
  21. odoo/addons/base_report_to_printer/i18n/pt.po +0 -11
  22. odoo/addons/base_report_to_printer/i18n/pt_BR.po +0 -11
  23. odoo/addons/base_report_to_printer/i18n/pt_PT.po +0 -11
  24. odoo/addons/base_report_to_printer/i18n/sl.po +0 -11
  25. odoo/addons/base_report_to_printer/i18n/sv.po +0 -11
  26. odoo/addons/base_report_to_printer/i18n/tr.po +0 -11
  27. odoo/addons/base_report_to_printer/i18n/zh_CN.po +0 -11
  28. odoo/addons/base_report_to_printer/models/ir_actions_report.py +6 -5
  29. odoo/addons/base_report_to_printer/models/printing_action.py +2 -2
  30. odoo/addons/base_report_to_printer/models/printing_printer.py +1 -1
  31. odoo/addons/base_report_to_printer/models/printing_report_xml_action.py +1 -1
  32. odoo/addons/base_report_to_printer/models/res_users.py +11 -3
  33. odoo/addons/base_report_to_printer/readme/CONTRIBUTORS.md +1 -0
  34. odoo/addons/base_report_to_printer/readme/CREDITS.md +1 -0
  35. odoo/addons/base_report_to_printer/static/description/index.html +16 -9
  36. odoo/addons/base_report_to_printer/static/src/js/qweb_action_manager.esm.js +2 -2
  37. odoo/addons/base_report_to_printer/tests/test_ir_actions_report.py +121 -86
  38. odoo/addons/base_report_to_printer/tests/test_printing_job.py +16 -9
  39. odoo/addons/base_report_to_printer/tests/test_printing_printer.py +50 -34
  40. odoo/addons/base_report_to_printer/tests/test_printing_printer_tray.py +9 -9
  41. odoo/addons/base_report_to_printer/tests/test_printing_printer_wizard.py +15 -9
  42. odoo/addons/base_report_to_printer/tests/test_printing_server.py +38 -27
  43. odoo/addons/base_report_to_printer/tests/test_report.py +41 -20
  44. odoo/addons/base_report_to_printer/views/printing_job.xml +2 -2
  45. odoo/addons/base_report_to_printer/views/printing_printer.xml +3 -3
  46. odoo/addons/base_report_to_printer/views/printing_report.xml +2 -2
  47. odoo/addons/base_report_to_printer/views/printing_server.xml +3 -3
  48. odoo/addons/base_report_to_printer/wizards/print_attachment_report.xml +2 -2
  49. odoo/addons/base_report_to_printer/wizards/printing_printer_update_wizard.py +1 -1
  50. {odoo_addon_base_report_to_printer-17.0.1.1.1.dist-info → odoo_addon_base_report_to_printer-18.0.1.0.0.4.dist-info}/METADATA +55 -48
  51. odoo_addon_base_report_to_printer-18.0.1.0.0.4.dist-info/RECORD +77 -0
  52. odoo_addon_base_report_to_printer-17.0.1.1.1.dist-info/RECORD +0 -76
  53. {odoo_addon_base_report_to_printer-17.0.1.1.1.dist-info → odoo_addon_base_report_to_printer-18.0.1.0.0.4.dist-info}/WHEEL +0 -0
  54. {odoo_addon_base_report_to_printer-17.0.1.1.1.dist-info → odoo_addon_base_report_to_printer-18.0.1.0.0.4.dist-info}/top_level.txt +0 -0
@@ -2,6 +2,7 @@
2
2
  # Copyright 2016 SYLEAM
3
3
  # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4
4
 
5
+ import logging
5
6
  from unittest import mock
6
7
 
7
8
  from odoo.tests.common import TransactionCase
@@ -57,14 +58,14 @@ class TestIrActionsReportXml(TransactionCase):
57
58
 
58
59
  def test_print_action_for_report_name_gets_report(self):
59
60
  """It should get report by name"""
60
- with mock.patch("%s._get_report_from_name" % model) as mk:
61
+ with mock.patch(f"{model}._get_report_from_name") as mk:
61
62
  expect = "test"
62
63
  self.Model.print_action_for_report_name(expect)
63
64
  mk.assert_called_once_with(expect)
64
65
 
65
66
  def test_print_action_for_report_name_returns_if_no_report(self):
66
67
  """It should return empty dict when no matching report"""
67
- with mock.patch("%s._get_report_from_name" % model) as mk:
68
+ with mock.patch(f"{model}._get_report_from_name") as mk:
68
69
  expect = "test"
69
70
  mk.return_value = False
70
71
  res = self.Model.print_action_for_report_name(expect)
@@ -72,7 +73,7 @@ class TestIrActionsReportXml(TransactionCase):
72
73
 
73
74
  def test_print_action_for_report_name_returns_if_report(self):
74
75
  """It should return correct serializable result for behaviour"""
75
- with mock.patch("%s._get_report_from_name" % model) as mk:
76
+ with mock.patch(f"{model}._get_report_from_name") as mk:
76
77
  res = self.Model.print_action_for_report_name("test")
77
78
  behaviour = mk().behaviour()
78
79
  expect = {
@@ -102,14 +103,19 @@ class TestIrActionsReportXml(TransactionCase):
102
103
  report = self.Model.search([], limit=1)
103
104
  self.env.user.printing_action = "client"
104
105
  self.env.user.printing_printer_id = self.new_printer()
105
- self.assertEqual(
106
- report.behaviour(),
107
- {
108
- "action": "client",
109
- "printer": self.env.user.printing_printer_id,
110
- "tray": False,
111
- },
112
- )
106
+ with (
107
+ self.assertLogs(level=logging.WARNING) as logs,
108
+ ):
109
+ self.assertEqual(
110
+ report.behaviour(),
111
+ {
112
+ "action": "client",
113
+ "printer": self.env.user.printing_printer_id,
114
+ "tray": False,
115
+ },
116
+ )
117
+ self.assertEqual(len(logs.records), 1)
118
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
113
119
 
114
120
  def test_behaviour_report_values(self):
115
121
  """It should return the action and printer from report"""
@@ -117,14 +123,19 @@ class TestIrActionsReportXml(TransactionCase):
117
123
  self.env.user.printing_action = "client"
118
124
  report.property_printing_action_id = self.new_action()
119
125
  report.printing_printer_id = self.new_printer()
120
- self.assertEqual(
121
- report.behaviour(),
122
- {
123
- "action": report.property_printing_action_id.action_type,
124
- "printer": report.printing_printer_id,
125
- "tray": False,
126
- },
127
- )
126
+ with (
127
+ self.assertLogs(level=logging.WARNING) as logs,
128
+ ):
129
+ self.assertEqual(
130
+ report.behaviour(),
131
+ {
132
+ "action": report.property_printing_action_id.action_type,
133
+ "printer": report.printing_printer_id,
134
+ "tray": False,
135
+ },
136
+ )
137
+ self.assertEqual(len(logs.records), 1)
138
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
128
139
 
129
140
  def test_behaviour_user_action(self):
130
141
  """It should return the action and printer from user action"""
@@ -188,14 +199,19 @@ class TestIrActionsReportXml(TransactionCase):
188
199
  printing_action = self.new_printing_action()
189
200
  printing_action.user_id = self.env.user
190
201
  printing_action.printer_id = self.new_printer()
191
- self.assertEqual(
192
- report.behaviour(),
193
- {
194
- "action": printing_action.action,
195
- "printer": printing_action.printer_id,
196
- "tray": False,
197
- },
198
- )
202
+ with (
203
+ self.assertLogs(level=logging.WARNING) as logs,
204
+ ):
205
+ self.assertEqual(
206
+ report.behaviour(),
207
+ {
208
+ "action": printing_action.action,
209
+ "printer": printing_action.printer_id,
210
+ "tray": False,
211
+ },
212
+ )
213
+ self.assertEqual(len(logs.records), 1)
214
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
199
215
 
200
216
  def test_behaviour_printing_action_user_defaults(self):
201
217
  """It should return the action and printer from user with printing
@@ -215,57 +231,71 @@ class TestIrActionsReportXml(TransactionCase):
215
231
  """
216
232
  It should return the correct tray
217
233
  """
218
- report = self.Model.search([], limit=1)
219
- action = self.env["printing.report.xml.action"].create(
220
- {"user_id": self.env.user.id, "report_id": report.id, "action": "server"}
221
- )
222
- printer = self.new_printer()
223
- tray_vals = {"name": "Tray", "system_name": "Tray", "printer_id": printer.id}
224
- user_tray = self.new_tray({"system_name": "User tray"}, tray_vals)
225
- report_tray = self.new_tray({"system_name": "Report tray"}, tray_vals)
226
- action_tray = self.new_tray({"system_name": "Action tray"}, tray_vals)
227
-
228
- # No report passed
229
- self.env.user.printer_tray_id = False
230
- options = printer.print_options()
231
- self.assertFalse("InputSlot" in options)
232
-
233
- # No tray defined
234
- self.env.user.printer_tray_id = False
235
- report.printer_tray_id = False
236
- action.printer_tray_id = False
237
- options = report.behaviour()
238
- self.assertTrue("tray" in options)
239
-
240
- # Only user tray is defined
241
- self.env.user.printer_tray_id = user_tray
242
- report.printer_tray_id = False
243
- action.printer_tray_id = False
244
- self.assertEqual("User tray", report.behaviour()["tray"])
245
-
246
- # Only report tray is defined
247
- self.env.user.printer_tray_id = False
248
- report.printer_tray_id = report_tray
249
- action.printer_tray_id = False
250
- self.assertEqual("Report tray", report.behaviour()["tray"])
251
-
252
- # Only action tray is defined
253
- self.env.user.printer_tray_id = False
254
- report.printer_tray_id = False
255
- action.printer_tray_id = action_tray
256
- self.assertEqual("Action tray", report.behaviour()["tray"])
257
-
258
- # User and report tray defined
259
- self.env.user.printer_tray_id = user_tray
260
- report.printer_tray_id = report_tray
261
- action.printer_tray_id = False
262
- self.assertEqual("Report tray", report.behaviour()["tray"])
263
-
264
- # All trays are defined
265
- self.env.user.printer_tray_id = user_tray
266
- report.printer_tray_id = report_tray
267
- action.printer_tray_id = action_tray
268
- self.assertEqual("Action tray", report.behaviour()["tray"])
234
+ with (
235
+ self.assertLogs(level=logging.WARNING) as logs,
236
+ ):
237
+ report = self.Model.search([], limit=1)
238
+ action = self.env["printing.report.xml.action"].create(
239
+ {
240
+ "user_id": self.env.user.id,
241
+ "report_id": report.id,
242
+ "action": "server",
243
+ }
244
+ )
245
+ printer = self.new_printer()
246
+ tray_vals = {
247
+ "name": "Tray",
248
+ "system_name": "Tray",
249
+ "printer_id": printer.id,
250
+ }
251
+ user_tray = self.new_tray({"system_name": "User tray"}, tray_vals)
252
+ report_tray = self.new_tray({"system_name": "Report tray"}, tray_vals)
253
+ action_tray = self.new_tray({"system_name": "Action tray"}, tray_vals)
254
+
255
+ # No report passed
256
+ self.env.user.printer_tray_id = False
257
+ options = printer.print_options()
258
+ self.assertFalse("InputSlot" in options)
259
+
260
+ # No tray defined
261
+ self.env.user.printer_tray_id = False
262
+ report.printer_tray_id = False
263
+ action.printer_tray_id = False
264
+ options = report.behaviour()
265
+ self.assertTrue("tray" in options)
266
+
267
+ # Only user tray is defined
268
+ self.env.user.printer_tray_id = user_tray
269
+ report.printer_tray_id = False
270
+ action.printer_tray_id = False
271
+ self.assertEqual("User tray", report.behaviour()["tray"])
272
+
273
+ # Only report tray is defined
274
+ self.env.user.printer_tray_id = False
275
+ report.printer_tray_id = report_tray
276
+ action.printer_tray_id = False
277
+ self.assertEqual("Report tray", report.behaviour()["tray"])
278
+
279
+ # Only action tray is defined
280
+ self.env.user.printer_tray_id = False
281
+ report.printer_tray_id = False
282
+ action.printer_tray_id = action_tray
283
+ self.assertEqual("Action tray", report.behaviour()["tray"])
284
+
285
+ # User and report tray defined
286
+ self.env.user.printer_tray_id = user_tray
287
+ report.printer_tray_id = report_tray
288
+ action.printer_tray_id = False
289
+ self.assertEqual("Report tray", report.behaviour()["tray"])
290
+
291
+ # All trays are defined
292
+ self.env.user.printer_tray_id = user_tray
293
+ report.printer_tray_id = report_tray
294
+ action.printer_tray_id = action_tray
295
+ self.assertEqual("Action tray", report.behaviour()["tray"])
296
+ self.assertEqual(len(logs.records), 6)
297
+ for record in logs.records:
298
+ self.assertEqual(record.levelno, logging.WARNING)
269
299
 
270
300
  def test_onchange_printer_tray_id_empty(self):
271
301
  action = self.Model.new({"printer_tray_id": False})
@@ -305,11 +335,16 @@ class TestIrActionsReportXml(TransactionCase):
305
335
  printing_action.user_id = self.env.user
306
336
  printing_action.printer_id = self.new_printer()
307
337
  printing_action.printer_id.multi_thread = True
308
- self.assertEqual(
309
- report.behaviour(),
310
- {
311
- "action": printing_action.action,
312
- "printer": printing_action.printer_id,
313
- "tray": False,
314
- },
315
- )
338
+ with (
339
+ self.assertLogs(level=logging.WARNING) as logs,
340
+ ):
341
+ self.assertEqual(
342
+ report.behaviour(),
343
+ {
344
+ "action": printing_action.action,
345
+ "printer": printing_action.printer_id,
346
+ "tray": False,
347
+ },
348
+ )
349
+ self.assertEqual(len(logs.records), 1)
350
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
@@ -1,6 +1,7 @@
1
1
  # Copyright 2016 LasLabs Inc.
2
2
  # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3
3
 
4
+ import logging
4
5
  from unittest import mock
5
6
 
6
7
  from odoo import fields
@@ -42,17 +43,23 @@ class TestPrintingJob(TransactionCase):
42
43
  values["printer_id"] = printer.id
43
44
  return self.env["printing.job"].create(values)
44
45
 
45
- @mock.patch("%s.cups" % model)
46
- def test_cancel_job_error(self, cups):
46
+ def test_cancel_job_error(self):
47
47
  """It should catch any exception from CUPS and update status"""
48
- cups.Connection.side_effect = Exception
49
- printer = self.new_printer()
50
- job = self.new_job(printer, {"job_id_cups": 2})
51
- job.action_cancel()
52
- cups.Connection.side_effect = None
53
- self.assertEqual(cups.Connection().cancelJob.call_count, 0)
48
+ with (
49
+ mock.patch(f"{model}.cups") as cups,
50
+ self.assertLogs(level=logging.WARNING) as logs,
51
+ ):
52
+ cups.Connection.side_effect = Exception
53
+ printer = self.new_printer()
54
+ job = self.new_job(printer, {"job_id_cups": 2})
55
+ job.action_cancel()
56
+ cups.Connection.side_effect = None
57
+ self.assertEqual(cups.Connection().cancelJob.call_count, 0)
58
+
59
+ self.assertEqual(len(logs.records), 3)
60
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
54
61
 
55
- @mock.patch("%s.cups" % model)
62
+ @mock.patch(f"{model}.cups")
56
63
  def test_cancel_job(self, cups):
57
64
  """It should catch any exception from CUPS and update status"""
58
65
  printer = self.new_printer()
@@ -1,6 +1,7 @@
1
1
  # Copyright 2016 LasLabs Inc.
2
2
  # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3
3
 
4
+ import logging
4
5
  import tempfile
5
6
  from unittest import mock
6
7
 
@@ -79,11 +80,11 @@ class TestPrintingPrinter(TransactionCase):
79
80
  )
80
81
  self.assertTrue("InputSlot" in self.Model.print_options(report, tray="Test"))
81
82
 
82
- @mock.patch("%s.cups" % server_model)
83
+ @mock.patch(f"{server_model}.cups")
83
84
  def test_print_report(self, cups):
84
85
  """It should print a report through CUPS"""
85
86
  fd, file_name = tempfile.mkstemp()
86
- with mock.patch("%s.mkstemp" % model) as mkstemp:
87
+ with mock.patch(f"{model}.mkstemp") as mkstemp:
87
88
  mkstemp.return_value = fd, file_name
88
89
  printer = self.new_record()
89
90
  printer.print_document(self.report, b"content to print", doc_format="pdf")
@@ -91,37 +92,52 @@ class TestPrintingPrinter(TransactionCase):
91
92
  printer.system_name, file_name, file_name, options={}
92
93
  )
93
94
 
94
- @mock.patch("%s.cups" % server_model)
95
- def test_print_report_error(self, cups):
95
+ def test_print_report_error(self):
96
96
  """It should print a report through CUPS"""
97
- cups.Connection.side_effect = Exception
98
- fd, file_name = tempfile.mkstemp()
99
- with mock.patch("%s.mkstemp" % model) as mkstemp:
100
- mkstemp.return_value = fd, file_name
101
- printer = self.new_record()
102
- with self.assertRaises(UserError):
103
- printer.print_document(
104
- self.report, b"content to print", doc_format="pdf"
105
- )
106
-
107
- @mock.patch("%s.cups" % server_model)
108
- def test_print_file(self, cups):
97
+ with (
98
+ mock.patch(f"{model}.cups") as cups,
99
+ self.assertLogs(level=logging.WARNING) as logs,
100
+ ):
101
+ cups.Connection.side_effect = Exception
102
+ fd, file_name = tempfile.mkstemp()
103
+ with mock.patch(f"{model}.mkstemp") as mkstemp:
104
+ mkstemp.return_value = fd, file_name
105
+ printer = self.new_record()
106
+ with self.assertRaises(UserError):
107
+ printer.print_document(
108
+ self.report, b"content to print", doc_format="pdf"
109
+ )
110
+ self.assertEqual(len(logs.records), 1)
111
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
112
+
113
+ def test_print_file(self):
109
114
  """It should print a file through CUPS"""
110
- file_name = "file_name"
111
- printer = self.new_record()
112
- printer.print_file(file_name, "pdf")
113
- cups.Connection().printFile.assert_called_once_with(
114
- printer.system_name, file_name, file_name, options={}
115
- )
115
+ with (
116
+ mock.patch(f"{server_model}.cups") as cups,
117
+ self.assertLogs(level=logging.WARNING) as logs,
118
+ ):
119
+ file_name = "file_name"
120
+ printer = self.new_record()
121
+ printer.print_file(file_name, "pdf")
122
+ cups.Connection().printFile.assert_called_once_with(
123
+ printer.system_name, file_name, file_name, options={}
124
+ )
125
+ self.assertEqual(len(logs.records), 1)
126
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
116
127
 
117
- @mock.patch("%s.cups" % server_model)
118
- def test_print_file_error(self, cups):
128
+ def test_print_file_error(self):
119
129
  """It should print a file through CUPS"""
120
- cups.Connection.side_effect = Exception
121
- file_name = "file_name"
122
- printer = self.new_record()
123
- with self.assertRaises(UserError):
124
- printer.print_file(file_name)
130
+ with (
131
+ mock.patch(f"{server_model}.cups") as cups,
132
+ self.assertLogs(level=logging.WARNING) as logs,
133
+ ):
134
+ cups.Connection.side_effect = Exception
135
+ file_name = "file_name"
136
+ printer = self.new_record()
137
+ with self.assertRaises(UserError):
138
+ printer.print_file(file_name)
139
+ self.assertEqual(len(logs.records), 1)
140
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
125
141
 
126
142
  def test_set_default(self):
127
143
  """It should set a single record as default"""
@@ -142,7 +158,7 @@ class TestPrintingPrinter(TransactionCase):
142
158
  printer.unset_default()
143
159
  self.assertFalse(printer.default)
144
160
 
145
- @mock.patch("%s.cups" % server_model)
161
+ @mock.patch(f"{server_model}.cups")
146
162
  def test_cancel_all_jobs(self, cups):
147
163
  """It should cancel all jobs"""
148
164
  printer = self.new_record()
@@ -151,7 +167,7 @@ class TestPrintingPrinter(TransactionCase):
151
167
  name=printer.system_name, purge_jobs=False
152
168
  )
153
169
 
154
- @mock.patch("%s.cups" % server_model)
170
+ @mock.patch(f"{server_model}.cups")
155
171
  def test_cancel_and_purge_all_jobs(self, cups):
156
172
  """It should cancel all jobs"""
157
173
  printer = self.new_record()
@@ -160,21 +176,21 @@ class TestPrintingPrinter(TransactionCase):
160
176
  name=printer.system_name, purge_jobs=True
161
177
  )
162
178
 
163
- @mock.patch("%s.cups" % server_model)
179
+ @mock.patch(f"{server_model}.cups")
164
180
  def test_enable_printer(self, cups):
165
181
  """It should enable the printer"""
166
182
  printer = self.new_record()
167
183
  printer.enable()
168
184
  cups.Connection().enablePrinter.assert_called_once_with(printer.system_name)
169
185
 
170
- @mock.patch("%s.cups" % server_model)
186
+ @mock.patch(f"{server_model}.cups")
171
187
  def test_disable_printer(self, cups):
172
188
  """It should disable the printer"""
173
189
  printer = self.new_record()
174
190
  printer.disable()
175
191
  cups.Connection().disablePrinter.assert_called_once_with(printer.system_name)
176
192
 
177
- @mock.patch("%s.cups" % server_model)
193
+ @mock.patch(f"{server_model}.cups")
178
194
  def test_print_test_page(self, cups):
179
195
  """It should print a test page"""
180
196
  printer = self.new_record()
@@ -99,7 +99,7 @@ class TestPrintingPrinter(TransactionCase):
99
99
  }
100
100
  }
101
101
 
102
- @mock.patch("%s.cups" % server_model)
102
+ @mock.patch(f"{server_model}.cups")
103
103
  def test_update_printers(self, cups):
104
104
  """
105
105
  Check that the update_printers method calls _prepare_update_from_cups
@@ -111,7 +111,7 @@ class TestPrintingPrinter(TransactionCase):
111
111
  self.ServerModel.update_printers()
112
112
  self.assertEqual(self.printer.name, "My custom name")
113
113
 
114
- @mock.patch("%s.cups" % server_model)
114
+ @mock.patch(f"{server_model}.cups")
115
115
  def test_prepare_update_from_cups_no_ppd(self, cups):
116
116
  """
117
117
  Check that the tray_ids field has no value when no PPD is available
@@ -124,7 +124,7 @@ class TestPrintingPrinter(TransactionCase):
124
124
  vals = self.printer._prepare_update_from_cups(connection, cups_printer)
125
125
  self.assertFalse("tray_ids" in vals)
126
126
 
127
- @mock.patch("%s.cups" % server_model)
127
+ @mock.patch(f"{server_model}.cups")
128
128
  def test_prepare_update_from_cups_empty_ppd(self, cups):
129
129
  """
130
130
  Check that the tray_ids field has no value when the PPD file has
@@ -142,7 +142,7 @@ class TestPrintingPrinter(TransactionCase):
142
142
  vals = self.printer._prepare_update_from_cups(connection, cups_printer)
143
143
  self.assertFalse("tray_ids" in vals)
144
144
 
145
- @mock.patch("%s.cups" % server_model)
145
+ @mock.patch(f"{server_model}.cups")
146
146
  @mock.patch("os.unlink")
147
147
  def test_prepare_update_from_cups_unlink_error(self, os_unlink, cups):
148
148
  """
@@ -159,7 +159,7 @@ class TestPrintingPrinter(TransactionCase):
159
159
  with self.assertRaises(OSError):
160
160
  self.printer._prepare_update_from_cups(connection, cups_printer)
161
161
 
162
- @mock.patch("%s.cups" % server_model)
162
+ @mock.patch(f"{server_model}.cups")
163
163
  @mock.patch("os.unlink")
164
164
  def test_prepare_update_from_cups_unlink_error_enoent(self, os_unlink, cups):
165
165
  """
@@ -181,7 +181,7 @@ class TestPrintingPrinter(TransactionCase):
181
181
  [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
182
182
  )
183
183
 
184
- @mock.patch("%s.cups" % server_model)
184
+ @mock.patch(f"{server_model}.cups")
185
185
  def test_prepare_update_from_cups(self, cups):
186
186
  """
187
187
  Check the return value when adding a single tray
@@ -197,7 +197,7 @@ class TestPrintingPrinter(TransactionCase):
197
197
  [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
198
198
  )
199
199
 
200
- @mock.patch("%s.cups" % server_model)
200
+ @mock.patch(f"{server_model}.cups")
201
201
  def test_prepare_update_from_cups_with_multiple_trays(self, cups):
202
202
  """
203
203
  Check the return value when adding multiple trays at once
@@ -216,7 +216,7 @@ class TestPrintingPrinter(TransactionCase):
216
216
  ],
217
217
  )
218
218
 
219
- @mock.patch("%s.cups" % server_model)
219
+ @mock.patch(f"{server_model}.cups")
220
220
  def test_prepare_update_from_cups_already_known_trays(self, cups):
221
221
  """
222
222
  Check that calling the method twice doesn't create the trays multiple
@@ -236,7 +236,7 @@ class TestPrintingPrinter(TransactionCase):
236
236
  [(0, 0, {"name": "Auto (Default)", "system_name": "Auto"})],
237
237
  )
238
238
 
239
- @mock.patch("%s.cups" % server_model)
239
+ @mock.patch(f"{server_model}.cups")
240
240
  def test_prepare_update_from_cups_unknown_trays(self, cups):
241
241
  """
242
242
  Check that trays which are not in the PPD file are removed from Odoo
@@ -1,6 +1,7 @@
1
1
  # Copyright 2016 LasLabs Inc.
2
2
  # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3
3
 
4
+ import logging
4
5
  from unittest import mock
5
6
 
6
7
  from odoo.exceptions import UserError
@@ -36,7 +37,7 @@ class TestPrintingPrinterWizard(TransactionCase):
36
37
  "uri": self.printer_vals["device-uri"],
37
38
  }
38
39
 
39
- @mock.patch("%s.cups" % model)
40
+ @mock.patch(f"{model}.cups")
40
41
  def test_action_ok_inits_connection(self, cups):
41
42
  """It should initialize CUPS connection"""
42
43
  self.Model.action_ok()
@@ -44,7 +45,7 @@ class TestPrintingPrinterWizard(TransactionCase):
44
45
  host=self.server.address, port=self.server.port
45
46
  )
46
47
 
47
- @mock.patch("%s.cups" % model)
48
+ @mock.patch(f"{model}.cups")
48
49
  def test_action_ok_gets_printers(self, cups):
49
50
  """It should get printers from CUPS"""
50
51
  cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
@@ -52,14 +53,19 @@ class TestPrintingPrinterWizard(TransactionCase):
52
53
  self.Model.action_ok()
53
54
  cups.Connection().getPrinters.assert_called_once_with()
54
55
 
55
- @mock.patch("%s.cups" % model)
56
- def test_action_ok_raises_warning_on_error(self, cups):
56
+ def test_action_ok_raises_warning_on_error(self):
57
57
  """It should raise Warning on any error"""
58
- cups.Connection.side_effect = StopTest
59
- with self.assertRaises(UserError):
60
- self.Model.action_ok()
58
+ with (
59
+ mock.patch(f"{model}.cups") as cups,
60
+ self.assertLogs(level=logging.WARNING) as logs,
61
+ ):
62
+ cups.Connection.side_effect = StopTest
63
+ with self.assertRaises(UserError):
64
+ self.Model.action_ok()
65
+ self.assertEqual(len(logs.records), 1)
66
+ self.assertEqual(logs.records[0].levelno, logging.WARNING)
61
67
 
62
- @mock.patch("%s.cups" % model)
68
+ @mock.patch(f"{model}.cups")
63
69
  def test_action_ok_creates_new_printer(self, cups):
64
70
  """It should create new printer w/ proper vals"""
65
71
  cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}
@@ -75,7 +81,7 @@ class TestPrintingPrinterWizard(TransactionCase):
75
81
 
76
82
  self.assertEqual(val, rec_id[key])
77
83
 
78
- @mock.patch("%s.cups" % model)
84
+ @mock.patch(f"{model}.cups")
79
85
  def test_action_ok_skips_existing_printer(self, cups):
80
86
  """It should not recreate existing printers"""
81
87
  cups.Connection().getPrinters.return_value = {"sys_name": self.printer_vals}