Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt: Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralmau committed Jan 16, 2025
1 parent 3f11397 commit 8e2d92a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 61 deletions.
32 changes: 13 additions & 19 deletions helpdesk_mgmt/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
# Copyright 2023 Tecnativa - Víctor Martínez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests import common, new_test_user
from odoo.tests import new_test_user

from odoo.addons.base.tests.common import BaseCommon

class TestHelpdeskTicketBase(common.TransactionCase):

class TestHelpdeskTicketBase(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
helpdesk_ticket_team = cls.env["helpdesk.ticket.team"]
ctx = {
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.company = cls.env.company
cls.user_own = new_test_user(
cls.env,
login="helpdesk_mgmt-user_own",
groups="helpdesk_mgmt.group_helpdesk_user_own",
context=ctx,
)
cls.user_team = new_test_user(
cls.env,
login="helpdesk_mgmt-user_team",
groups="helpdesk_mgmt.group_helpdesk_user_team",
context=ctx,
)
cls.user = new_test_user(
cls.env,
login="helpdesk_mgmt-user",
groups="helpdesk_mgmt.group_helpdesk_user",
context=ctx,
)
cls.stage_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done")
cls.team_a = helpdesk_ticket_team.create(
Expand All @@ -41,16 +34,17 @@ def setUpClass(cls):
{"name": "Team B", "user_ids": [(6, 0, [cls.user_team.id])]}
)
cls.new_stage = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new")
cls.ticket_a_unassigned = cls._create_ticket(cls, cls.team_a)
cls.ticket_a_unassigned = cls._create_ticket(cls.team_a)
cls.ticket_a_unassigned.priority = "3"
cls.ticket_a_user_own = cls._create_ticket(cls, cls.team_a, cls.user_own)
cls.ticket_a_user_team = cls._create_ticket(cls, cls.team_a, cls.user_team)
cls.ticket_b_unassigned = cls._create_ticket(cls, cls.team_b)
cls.ticket_b_user_own = cls._create_ticket(cls, cls.team_b, cls.user_own)
cls.ticket_b_user_team = cls._create_ticket(cls, cls.team_b, cls.user_team)
cls.ticket_a_user_own = cls._create_ticket(cls.team_a, cls.user_own)
cls.ticket_a_user_team = cls._create_ticket(cls.team_a, cls.user_team)
cls.ticket_b_unassigned = cls._create_ticket(cls.team_b)
cls.ticket_b_user_own = cls._create_ticket(cls.team_b, cls.user_own)
cls.ticket_b_user_team = cls._create_ticket(cls.team_b, cls.user_team)

def _create_ticket(self, team, user=False):
ticket = self.env["helpdesk.ticket"].create(
@classmethod
def _create_ticket(cls, team, user=False):
ticket = cls.env["helpdesk.ticket"].create(
{
"name": "Ticket {} ({})".format(
team.name, user.login if user else "unassigned"
Expand Down
35 changes: 16 additions & 19 deletions helpdesk_mgmt/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from odoo import http
from odoo.tests.common import new_test_user, tagged

from odoo.addons.base.tests.common import HttpCaseWithUserPortal
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT, HttpCaseWithUserPortal


@tagged("post_install", "-at_install")
Expand All @@ -14,33 +14,30 @@ class TestHelpdeskPortalBase(HttpCaseWithUserPortal):
HTML produced by our routes.
"""

def setUp(self):
super().setUp()
ctx = {
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
self.new_ticket_title = "portal-new-submitted-ticket-subject"
self.new_ticket_desc_lines = ( # multiline description to check line breaks
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.new_ticket_title = "portal-new-submitted-ticket-subject"
cls.new_ticket_desc_lines = ( # multiline description to check line breaks
"portal-new-submitted-ticket-description-line-1",
"portal-new-submitted-ticket-description-line-2",
)
self.company = self.env.ref("base.main_company")
self.partner_portal.parent_id = self.company.partner_id
cls.company = cls.env.ref("base.main_company")
cls.partner_portal.parent_id = cls.company.partner_id
# Create a basic user with no helpdesk permissions.
self.basic_user = new_test_user(self.env, login="test-basic-user", context=ctx)
self.basic_user.parent_id = self.company.partner_id
cls.basic_user = new_test_user(cls.env, login="test-basic-user")
cls.basic_user.parent_id = cls.company.partner_id
# Create a ticket submitted by our portal user.
self.portal_ticket = self._create_ticket(
self.partner_portal, "portal-ticket-title"
cls.portal_ticket = cls._create_ticket(
cls.partner_portal, "portal-ticket-title"
)

def get_new_tickets(self, user):
return self.env["helpdesk.ticket"].with_user(user).search([])

def _create_ticket(self, partner, ticket_title, **values):
@classmethod
def _create_ticket(cls, partner, ticket_title, **values):
"""Create a ticket submitted by the specified partner."""
data = {
"name": ticket_title,
Expand All @@ -50,7 +47,7 @@ def _create_ticket(self, partner, ticket_title, **values):
"partner_name": partner.name,
}
data.update(**values)
return self.env["helpdesk.ticket"].create(data)
return cls.env["helpdesk.ticket"].create(data)

def _submit_ticket(self, **values):
data = {
Expand Down
47 changes: 24 additions & 23 deletions helpdesk_mgmt/tests/test_res_partner.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
from odoo.tests.common import TransactionCase
from odoo.addons.base.tests.common import BaseCommon


class TestPartner(TransactionCase):
def setUp(self):
super().setUp()
self.partner_obj = self.env["res.partner"]
self.ticket_obj = self.env["helpdesk.ticket"]
self.stage_id_closed = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done")
self.parent_id = self.partner_obj.create({"name": "Parent 1"})
self.child_id_1 = self.partner_obj.create({"name": "Child 1"})
self.child_id_2 = self.partner_obj.create({"name": "Child 2"})
self.child_id_3 = self.partner_obj.create({"name": "Child 3"})
self.tickets = []
self.parent_id.child_ids = [
(4, self.child_id_1.id),
(4, self.child_id_2.id),
(4, self.child_id_3.id),
class TestPartner(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner_obj = cls.env["res.partner"]
cls.ticket_obj = cls.env["helpdesk.ticket"]
cls.stage_id_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done")
cls.parent_id = cls.partner_obj.create({"name": "Parent 1"})
cls.child_id_1 = cls.partner_obj.create({"name": "Child 1"})
cls.child_id_2 = cls.partner_obj.create({"name": "Child 2"})
cls.child_id_3 = cls.partner_obj.create({"name": "Child 3"})
cls.tickets = []
cls.parent_id.child_ids = [
(4, cls.child_id_1.id),
(4, cls.child_id_2.id),
(4, cls.child_id_3.id),
]
for i in [69, 155, 314, 420]:
self.tickets.append(
self.ticket_obj.create(
cls.tickets.append(
cls.ticket_obj.create(
{
"name": f"Nice ticket {i}",
"description": f"Nice ticket {i} description",
}
)
)
self.parent_id.helpdesk_ticket_ids = [(4, self.tickets[0].id)]
self.child_id_1.helpdesk_ticket_ids = [(4, self.tickets[1].id)]
self.child_id_2.helpdesk_ticket_ids = [(4, self.tickets[2].id)]
self.child_id_3.helpdesk_ticket_ids = [(4, self.tickets[3].id)]
self.child_id_3.helpdesk_ticket_ids[-1].stage_id = self.stage_id_closed
cls.parent_id.helpdesk_ticket_ids = [(4, cls.tickets[0].id)]
cls.child_id_1.helpdesk_ticket_ids = [(4, cls.tickets[1].id)]
cls.child_id_2.helpdesk_ticket_ids = [(4, cls.tickets[2].id)]
cls.child_id_3.helpdesk_ticket_ids = [(4, cls.tickets[3].id)]
cls.child_id_3.helpdesk_ticket_ids[-1].stage_id = cls.stage_id_closed

def test_ticket_count(self):
self.assertEqual(self.parent_id.helpdesk_ticket_count, 4)
Expand Down

0 comments on commit 8e2d92a

Please sign in to comment.