test(core): Ensure that when parent_ticket changes on a ticket an action comment is created

ref: #495 #558 #577
This commit is contained in:
2025-02-11 17:16:34 +09:30
parent 81e856967b
commit 2e0b835af9

View File

@ -19,7 +19,7 @@ from app.tests.abstract.model_permissions import ModelPermissions
from project_management.models.projects import Project
from project_management.models.project_milestone import ProjectMilestone
from core.models.ticket.ticket import Ticket, RelatedTickets
from core.models.ticket.ticket import Ticket, RelatedTickets, TicketCategory
from core.models.ticket.ticket_comment import TicketComment
from core.tests.unit.ticket.ticket_permission.field_based_permissions import ITSMTicketFieldBasedPermissions, ProjectTicketFieldBasedPermissions
@ -92,6 +92,16 @@ class SetUp:
user_settings.default_organization = self.organization
user_settings.save()
self.category = TicketCategory.objects.create(
organization = organization,
name = 'a category'
)
self.category_two = TicketCategory.objects.create(
organization = organization,
name = 'a category_two'
)
self.item = self.model.objects.create(
organization=organization,
@ -111,6 +121,15 @@ class SetUp:
status = int(Ticket.TicketStatus.All.NEW.value)
)
self.third_item = self.model.objects.create(
organization=organization,
title = 'A third ' + self.ticket_type + ' ticket',
description = 'the ticket body of item two',
ticket_type = self.ticket_type_enum,
opened_by = self.add_user,
status = int(Ticket.TicketStatus.All.NEW.value)
)
self.project = Project.objects.create(
name = 'ticket permissions project name',
organization = organization
@ -615,6 +634,93 @@ class ActionComments(SetUp):
def test_ticket_action_comment_parent_ticket_added(self):
"""Action Comment test
Confirm an' action comment is created when a `parent_ticket` is added
"""
self.item.parent_ticket = self.second_item
self.item.save()
comments = TicketComment.objects.filter(
ticket=self.item.pk,
comment_type = TicketComment.CommentType.ACTION
)
action_comment: bool = False
for comment in comments:
if re.match(r"parent ticket changed from none to #" + str(self.second_item.id) , str(comment.body).lower()):
action_comment = True
assert action_comment
def test_ticket_action_comment_parent_ticket_remove(self):
"""Action Comment test
Confirm an action comment is created when the `category` is removed
"""
self.item.parent_ticket = self.second_item
self.item.save()
self.item.parent_ticket = None
self.item.save()
comments = TicketComment.objects.filter(
ticket=self.item.pk,
comment_type = TicketComment.CommentType.ACTION
)
action_comment: bool = False
for comment in comments:
if re.match(r"parent ticket changed from #" + str(self.second_item.id) + " to none", str(comment.body).lower()):
action_comment = True
assert action_comment
def test_ticket_action_comment_parent_ticket_change(self):
"""Action Comment test
Confirm an action comment is created when a `category` is changed
"""
self.item.parent_ticket = self.second_item
self.item.save()
self.item.parent_ticket = self.third_item
self.item.save()
comments = TicketComment.objects.filter(
ticket=self.item.pk,
comment_type = TicketComment.CommentType.ACTION
)
action_comment: bool = False
for comment in comments:
if re.match(r"parent ticket changed from #" + str(self.second_item.id) + r" to #" + str(self.third_item.id) , str(comment.body).lower()):
action_comment = True
assert action_comment
def test_ticket_action_comment_subscribed_users_added_user_subscribed(self):
"""Action Comment test
Confirm a 'user subscribed' action comment is created when a user is added as subscribed