Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt: Test access added
Browse files Browse the repository at this point in the history
Forward port of dfbc369
  • Loading branch information
eLBati authored and ypapouin committed Oct 24, 2023
1 parent c7a5342 commit f977858
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions helpdesk_mgmt/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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])]}
Expand Down
76 changes: 76 additions & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time

from odoo.tests import tagged

from .common import TestHelpdeskTicketBase


Expand Down Expand Up @@ -97,3 +99,77 @@ def test_helpdesk_ticket_message_new(self):
self.assertEqual(
t.name, title, "The ticket should have the correct (new) title."
)

def test_helpdesk_ticket_multiple(self):
Ticket = self.env["helpdesk.ticket"]
Partner = self.env["res.partner"]

partner_1 = Partner.create({"name": "Partner 1", "email": "[email protected]"})
partner_2 = Partner.create({"name": "Partner 2", "email": "[email protected]"})
tickets = Ticket.create(
[
{
"name": "Test 1",
"description": "Ticket test number 1",
"user_id": self.user.id,
"partner_email": "[email protected]",
},
{
"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):
Ticket = self.env["helpdesk.ticket"]

t = 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())


@tagged("post_install", "-at_install")
class TestHelpdeskTicketPostInstall(TestHelpdeskTicketBase):
@classmethod
def setUpClass(cls):
super().setUpClass()

def test_helpdesk_ticket_assign_notify(self):
Ticket = self.env["helpdesk.ticket"]
Message = self.env["mail.message"]

t = Ticket.create(
{
"name": "Test 1",
"description": "Ticket test",
}
)
t.user_id = self.user_demo.id
m = 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
)
self.assertTrue("res_id=%s" % t.id in m.body)

0 comments on commit f977858

Please sign in to comment.