|
4 | 4 |
|
5 | 5 |
|
6 | 6 | @tagged("post_install", "-at_install") |
7 | | -class TestDocumentLayoutWizard(TransactionCase): |
| 7 | +class TestDocumentLayoutOnchange(TransactionCase): |
8 | 8 | @classmethod |
9 | 9 | def setUpClass(cls): |
10 | 10 | super().setUpClass() |
11 | 11 | cls.Company = cls.env["res.company"] |
12 | 12 | cls.company = cls.Company.create({"name": "WZ Co", "report_font_size": "11"}) |
13 | 13 | cls.Wizard = cls.env["base.document.layout"] |
14 | 14 |
|
15 | | - def test_wizard_default_inherits_company_value(self): |
| 15 | + def test_onchange_when_compute_preview_absent_does_nothing(self): |
16 | 16 | wiz = self.Wizard.with_company(self.company.id).create( |
17 | 17 | {"company_id": self.company.id} |
18 | 18 | ) |
19 | | - self.assertEqual(wiz.report_font_size, "11") |
| 19 | + prev = getattr(wiz, "preview", None) |
| 20 | + wiz.report_font_size = "10" |
20 | 21 |
|
21 | | - def test_onchange_updates_wizard_field_without_crash(self): |
22 | | - wiz = self.Wizard.with_company(self.company.id).create( |
23 | | - {"company_id": self.company.id} |
24 | | - ) |
25 | | - wiz.report_font_size = "14" |
26 | | - if hasattr(wiz, "_onchange_report_font_size"): |
| 22 | + with patch.object(type(wiz), "_compute_preview", new=None, create=True): |
27 | 23 | wiz._onchange_report_font_size() |
28 | | - self.assertEqual(wiz.report_font_size, "14") |
29 | 24 |
|
30 | | - def test_apply_wizard_persists_on_company_via_fallback(self): |
31 | | - wiz = self.Wizard.with_company(self.company.id).create( |
32 | | - {"company_id": self.company.id} |
33 | | - ) |
34 | | - wiz.report_font_size = "12" |
35 | | - self.company.write({"report_font_size": wiz.report_font_size}) |
36 | | - self.assertEqual(self.company.report_font_size, "12") |
37 | | - |
38 | | - def test_apply_uses_action_apply_when_present(self): |
39 | | - wiz = self.Wizard.with_company(self.company.id).create( |
40 | | - {"company_id": self.company.id} |
41 | | - ) |
42 | | - wiz.report_font_size = "13" |
43 | | - |
44 | | - def _fake_action_apply(self): |
45 | | - self.company_id.report_font_size = self.report_font_size |
46 | | - |
47 | | - with patch.object(type(wiz), "action_apply", _fake_action_apply, create=True): |
48 | | - wiz.action_apply() |
49 | | - |
50 | | - self.assertEqual(self.company.report_font_size, "13") |
| 25 | + self.assertEqual(getattr(wiz, "preview", None), prev) |
51 | 26 |
|
52 | 27 | def test_onchange_handles_compute_exception_sets_preview_false(self): |
53 | 28 | wiz = self.Wizard.with_company(self.company.id).create( |
54 | 29 | {"company_id": self.company.id} |
55 | 30 | ) |
56 | 31 | self.assertIn("preview", wiz._fields) |
57 | | - |
58 | 32 | wiz.report_font_size = "14" |
| 33 | + |
59 | 34 | with patch.object( |
60 | 35 | type(wiz), "_compute_preview", side_effect=Exception("boom"), create=True |
61 | 36 | ): |
62 | 37 | wiz._onchange_report_font_size() |
63 | 38 |
|
64 | 39 | self.assertFalse(bool(wiz.preview)) |
| 40 | + |
| 41 | + def test_onchange_updates_wizard_field_without_crash(self): |
| 42 | + wiz = self.Wizard.with_company(self.company.id).create( |
| 43 | + {"company_id": self.company.id} |
| 44 | + ) |
| 45 | + wiz.report_font_size = "14" |
| 46 | + wiz._onchange_report_font_size() |
| 47 | + self.assertEqual(wiz.report_font_size, "14") |
0 commit comments