Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / tests / test_confirm_upgrade_version_with_notification.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:24 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:24 +0000
1from datetime import date, timedelta
3from .test_provider_upgrade_base import TestProviderUpgradeCommon
6class TestConfirmUpgradeVersionWithNotification(TestProviderUpgradeCommon):
7 """Unit test to validate backend logic associated with confirming
8 an upgrade order and the subsequent automatic generation
9 of a message or chatter event with the confirmed upgrade date."""
11 def setUp(self):
12 super().setUp()
14 # Test user with sufficient rights
15 self.admin_user = self.env.user
17 # Test upgrade date (5 days in the future)
18 self.upgrade_date = date.today() + timedelta(days=5)
20 # Create confirmation stage and mail template for the upgrade_type
21 self.confirm_stage = self.env["helpdesk.stage"].create(
22 {
23 "name": "Confirmed Stage",
24 "team_ids": [(4, self.upgrade_team.id)],
25 }
26 )
28 self.confirm_mail_template = self.env["mail.template"].create(
29 {
30 "name": "Confirmation Template",
31 "model_id": self.env.ref("helpdesk.model_helpdesk_ticket").id,
32 "subject": "Upgrade confirmed",
33 "body_html": "<p>Your upgrade has been confirmed for date: {{ object.deadline_upgrade }}</p>",
34 }
35 )
37 # Configure the upgrade_type with stage and confirmation template
38 self.upgrade_type.write(
39 {
40 "confirm_stage_id": self.confirm_stage.id,
41 "confirm_mail_template_id": self.confirm_mail_template.id,
42 }
43 )
45 # Use the upgrade ticket from base class and update it with necessary data
46 self.upgrade_record = self.upgrade_ticket
47 self.upgrade_record.write(
48 {
49 "deadline_upgrade": self.upgrade_date,
50 }
51 )
53 # Create a production request to activate the confirmation button
54 self.production_request = self.env["helpdesk.ticket.upgrade.request"]._create_request(
55 self.upgrade_record.id,
56 "production",
57 date_start=self.upgrade_date,
58 automatic=True,
59 )
61 # Manually change state to 'done' after creation
63 def test_confirm_upgrade_version_with_notification(self):
64 """Main test that validates upgrade confirmation and message generation"""
66 # Initial verification: The initial state should allow confirmation
67 self.assertFalse(
68 self.upgrade_record.confirm_production_sent,
69 "The confirm_production_sent field should be False initially",
70 )
72 # Initial verification: The upgrade date should be configured
73 self.assertEqual(
74 self.upgrade_record.deadline_upgrade,
75 self.upgrade_date,
76 "The upgrade date should maintain the value configured in setup",
77 )
79 # Call confirmation action - simulates clicking "Confirm"
80 result = self.upgrade_record.action_confirm_production()
82 # State change validation: The confirm_production_sent field should change to True
83 self.assertTrue(
84 self.upgrade_record.confirm_production_sent,
85 "The confirmation state should have changed to True after confirmation",
86 )
88 # Date validation: The date should remain unchanged
89 self.assertEqual(
90 self.upgrade_record.deadline_upgrade,
91 self.upgrade_date,
92 "The upgrade date should maintain the original value after confirmation",
93 )
95 # Stage change validation: Should change to confirmation stage
96 self.assertEqual(
97 self.upgrade_record.stage_id,
98 self.confirm_stage,
99 "The ticket stage should have changed to the confirmation stage",
100 )
102 # Message content validation: The last message should contain confirmation information
103 last_message = self.upgrade_record.message_ids[0] # Messages are ordered by date desc
104 self.assertIn(
105 "confirm",
106 last_message.body.lower(),
107 "The message body should contain text related to confirmation",
108 )
110 # Message type validation: Should be of appropriate type
111 self.assertIn(
112 last_message.message_type, ["notification", "comment"], "The message type should be notification or comment"
113 )
115 # Action return validation: Should return a success notification
116 self.assertEqual(result.get("type"), "ir.actions.client", "The action should return a client notification")
117 self.assertEqual(result.get("tag"), "display_notification", "Should return a display notification")