From a513d1eb09521fc8557b54ce4b9c4461701532d2 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 30 Jul 2020 12:11:00 +0200 Subject: [PATCH] [IMP] helpdesk_mgmt: Test access added Forward port of dfbc3698e76b3a1330f339ca78b49557b78c05ed --- helpdesk_mgmt/tests/common.py | 3 + helpdesk_mgmt/tests/test_helpdesk_ticket.py | 93 +++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/helpdesk_mgmt/tests/common.py b/helpdesk_mgmt/tests/common.py index a41e5f35f..0eb9c9945 100644 --- a/helpdesk_mgmt/tests/common.py +++ b/helpdesk_mgmt/tests/common.py @@ -33,6 +33,9 @@ def setUpClass(cls): groups="helpdesk_mgmt.group_helpdesk_user", context=ctx, ) + cls.admin = cls.env.ref("base.user_admin") + cls.user_portal = cls.env.ref("base.demo_user0") + cls.user_demo = cls.env.ref("base.user_demo") cls.stage_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done") cls.team_a = helpdesk_ticket_team.create( {"name": "Team A", "user_ids": [(6, 0, [cls.user_own.id, cls.user.id])]} diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index 9088c117a..ff59d3649 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -1,5 +1,7 @@ import time +from odoo.tests import tagged + from .common import TestHelpdeskTicketBase @@ -173,3 +175,94 @@ def test_ticket_without_team(self): } ) self.assertEqual(self.new_stage, new_ticket.stage_id) + + def test_helpdesk_ticket_multiple(self): + partner_1 = self.Partner.create({"name": "Partner 1", "email": "partner1@test.com"}) + partner_2 = self.Partner.create({"name": "Partner 2", "email": "partner2@test.com"}) + tickets = self.Ticket.create( + [ + { + "name": "Test 1", + "description": "Ticket test number 1", + "user_id": self.user.id, + "partner_email": "partner@domain.com", + }, + { + "name": "Test 2", + "description": "Ticket test number 2", + "user_id": self.user.id, + "partner_id": partner_1.id, + }, + { + "name": "Test 3", + "description": "Ticket test number 3", + "user_id": self.user_demo.id, + "partner_id": partner_2.id, + }, + ] + ) + self.assertEqual(len(tickets), 3) + + def test_helpdesk_ticket_access(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + self.assertEqual(t.access_url, "/my/ticket/%s" % t.id) + t.partner_id = self.user_portal.partner_id.id + self.assertTrue(t.partner_can_access()) + + def test_partner_can_access(self): + p = self.env.ref("base.res_partner_1") + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + "partner_id": p.id, + } + ) + self.assertFalse(t.partner_can_access()) + t.partner_id = self.env.ref("base.user_admin").partner_id.id + self.assertTrue(t.partner_can_access()) + + def test_access_url(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + t._compute_access_url() + self.assertEqual(t.access_url, "/my/ticket/%s" % t.id) + + +@tagged("post_install", "-at_install") +class TestHelpdeskTicketPostInstall(TestHelpdeskTicketBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.Ticket = cls.env["helpdesk.ticket"] + cls.Message = cls.env["mail.message"] + + def test_helpdesk_ticket_assign_notify(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + t.user_id = self.user_demo.id + m = self.Message.search( + [ + ("model", "=", "helpdesk.ticket"), + ("res_id", "=", t.id), + ("message_type", "=", "user_notification"), + ] + ) + self.assertTrue( + "You have been assigned to the Helpdesk Ticket %s" % t.display_name + in m.body + )