Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / tests / test_note_validation.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:15 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 18:15 +0000
1from odoo import Command
3from .test_provider_upgrade_base import TestProviderUpgradeCommon
6class TestCustomerNoteValidation(TestProviderUpgradeCommon):
7 """
8 Test customer note validation workflow using existing test data.
9 """
11 @classmethod
12 def setUpClass(cls):
13 super().setUpClass()
15 # Create upgrade line with customer note validation
16 cls.validation_upgrade_line = cls.env["saas.upgrade.line"].create(
17 {
18 "name": "[Test] Customer Note Validation",
19 "upgrade_type_ids": [Command.link(cls.upgrade_type.id)],
20 "type": "0_on_create",
21 "state": "approved",
22 "customer_note_validation": True,
23 "customer_note_validation_script": """
24if not customer_note.description or not str(customer_note.description).strip():
25 result = 'Customer note cannot be closed without description'
26""",
27 "message": "<div>Test validation message</div>",
28 "title": "Validation Test",
29 "adhoc_product_id": cls.env.ref("saas_provider_adhoc.adhoc_product_actualizacion_actualizacion").id,
30 }
31 )
33 def test_customer_note_validation_flow(self):
34 """Test customer note validation with empty and filled description."""
35 # Create customer note with empty description
36 customer_note = self.env["helpdesk.ticket.customer_note"].create(
37 {
38 "title": "Test Validation Note",
39 "description": "", # Empty to trigger validation
40 "ticket_id": self.upgrade_ticket.id,
41 "upgrade_type_id": self.upgrade_type.id,
42 "upgrade_line_id": self.validation_upgrade_line.id,
43 "status": "ongoing",
44 }
45 )
47 # Create test request required for validation (use helper to avoid invalid initial states)
48 test_request = self.env["helpdesk.ticket.upgrade.request"]._create_request(
49 self.upgrade_ticket.id, "test", automatic=True, hide_from_portal=False, bypass=True
50 )
52 # Ensure test request is available for validation
53 self.upgrade_ticket.last_test_request_line_id = test_request
55 initial_status = customer_note.status
57 # Test validation failure with empty description
58 action_result = customer_note.action_toggle_status()
60 # Verify status unchanged on validation failure
61 self.assertEqual(customer_note.status, initial_status, "Status should not change when validation fails")
63 # Verify validation error notification
64 self.assertIsNotNone(action_result, "Should return validation error action")
65 # Validation script failed so we get a 'warning' notification, not a 'danger' for missing request
66 self.assertEqual(action_result.get("params", {}).get("type"), "warning", "Notification type should be warning")
67 self.assertIn(
68 "Cannot close Customer Note",
69 action_result.get("params", {}).get("title", ""),
70 "Title should indicate customer note cannot be closed",
71 )
73 # Test validation success with description
74 customer_note.description = "Valid description content"
76 action_result = customer_note.action_toggle_status()
78 # Verify description updated (HTML field returns Markup object)
79 self.assertIn("Valid description content", str(customer_note.description), "Description should be updated")
81 # Verify status changed to done
82 self.assertEqual(customer_note.status, "done", "Status should change to done when validation passes")
84 # Verify no error action on success
85 self.assertIsNone(action_result, "Should not return error action when validation passes")