From dc8a09cfb1ae78eb1673bf0838af2d95b9787472 Mon Sep 17 00:00:00 2001 From: Olivier Nibart Date: Wed, 21 Aug 2024 17:15:29 +0200 Subject: [PATCH] [ADD] add tests --- helpdesk_mgmt_reopen/tests/__init__.py | 1 + .../tests/test_helpdesk_ticket.py | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 helpdesk_mgmt_reopen/tests/__init__.py create mode 100644 helpdesk_mgmt_reopen/tests/test_helpdesk_ticket.py diff --git a/helpdesk_mgmt_reopen/tests/__init__.py b/helpdesk_mgmt_reopen/tests/__init__.py new file mode 100644 index 0000000000..5b420011e0 --- /dev/null +++ b/helpdesk_mgmt_reopen/tests/__init__.py @@ -0,0 +1 @@ +from . import test_helpdesk_ticket diff --git a/helpdesk_mgmt_reopen/tests/test_helpdesk_ticket.py b/helpdesk_mgmt_reopen/tests/test_helpdesk_ticket.py new file mode 100644 index 0000000000..30dc88bc57 --- /dev/null +++ b/helpdesk_mgmt_reopen/tests/test_helpdesk_ticket.py @@ -0,0 +1,83 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Olivier Nibart +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from unittest import mock + +from odoo.tests.common import SavepointCase + + +class TestMailMessage(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.MailMessage = cls.env["mail.message"] + + cls.stage_new = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") + cls.stage_in_progress = cls.env.ref( + "helpdesk_mgmt.helpdesk_ticket_stage_in_progress" + ) + cls.stage_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done") + + cls.ticket = cls.env["helpdesk.ticket"].create( + { + "name": "Test Ticket", + "description": "Description", + } + ) + + def test_is_reopener_message(self): + vals = { + "model": "not helpdesk.ticket", + "message_type": "not comment or notification", + } + self.assertFalse(self.MailMessage.is_reopener_message(vals)) + vals = { + "model": "helpdesk.ticket", + "message_type": "notification", + } + self.assertFalse(self.MailMessage.is_reopener_message(vals)) + vals = { + "model": "helpdesk.ticket", + "message_type": "comment", + } + # type comment in production is not a reopener + self.assertTrue(self.MailMessage.is_production_env()) + self.assertFalse(self.MailMessage.is_reopener_message(vals)) + # type comment not in production is a reopener + with mock.patch.object( + type(self.MailMessage), + "is_production_env", + return_value=False, + ): + self.assertFalse(self.MailMessage.is_production_env()) + self.assertTrue(self.MailMessage.is_reopener_message(vals)) + vals = { + "model": "helpdesk.ticket", + "message_type": "not comment or notification", + } + self.assertTrue(self.MailMessage.is_reopener_message(vals)) + + def test_helpdesk_ticket_new_reopen(self): + self.assertEqual(self.ticket.stage_id, self.stage_new) + self.ticket.message_post( + body="Test message of type email", + message_type="email", + ) + self.assertEqual(self.ticket.stage_id, self.stage_new) + + def test_helpdesk_ticket_in_progress_reopen(self): + self.ticket.stage_id = self.stage_in_progress + self.ticket.message_post( + body="Test message of type email", + message_type="email", + ) + self.assertEqual(self.ticket.stage_id, self.stage_in_progress) + + def test_helpdesk_ticket_closed_reopen(self): + self.ticket.stage_id = self.stage_closed + self.ticket.message_post( + body="Test message of type email", + message_type="email", + ) + self.assertEqual(self.ticket.stage_id, self.stage_new)