From a58cb1ee9501c1a746d30b9ecd4bbe9d7289406d Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 16:02:59 +0930 Subject: [PATCH 01/16] feat(core): When changing a ticket milestone create an action comment with the changed details ref: #497 #508 --- app/core/models/ticket/ticket.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index 29a2401c0..537fa0ec4 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -876,6 +876,21 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields comment_field_value = f"changed {field.replace('_id','')} to {self.project}" + if field == 'milestone_id': + + value = 'nothing' + + try: + + get_milestone = ProjectMilestone.objects.get( pk = before[field]) + + value = get_milestone.name + + except: + pass + + comment_field_value = f"changed milestone from _{value}_ to **{self.milestone}**" + if comment_field_value: From c91857850b1a284f60bae7f268c7489cc1f13b87 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:13:04 +0930 Subject: [PATCH 02/16] feat(core): When changing a ticket planned start date create an action comment with the details ref: #498 #508 --- app/core/models/ticket/ticket.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index 537fa0ec4..0a0bbde50 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -891,6 +891,9 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields comment_field_value = f"changed milestone from _{value}_ to **{self.milestone}**" + if field == 'planned_start_date': + + comment_field_value = f"changed Planned Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" if comment_field_value: From efd205c2446912aea1a2451f07c94b585f1e2db4 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:13:33 +0930 Subject: [PATCH 03/16] feat(core): When changing a ticket planned finish date create an action comment with the details ref: #500 #508 --- app/core/models/ticket/ticket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index 0a0bbde50..bd7792010 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -895,6 +895,10 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields comment_field_value = f"changed Planned Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + if field == 'planned_finish_date': + + comment_field_value = f"changed Planned Finish Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + if comment_field_value: if request: From 2865c3d32a3c729006733e5620d0406e0703fd23 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:14:07 +0930 Subject: [PATCH 04/16] feat(core): When changing a ticket real start date create an action comment with the details ref: #499 #508 --- app/core/models/ticket/ticket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index bd7792010..c2b5bb01a 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -899,6 +899,10 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields comment_field_value = f"changed Planned Finish Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + if field == 'real_start_date': + + comment_field_value = f"changed Real Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + if comment_field_value: if request: From 4c5c460d880ade961324f3a45fa5f3a06ae9a5ee Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:14:38 +0930 Subject: [PATCH 05/16] feat(core): When changing a ticket real finish date create an action comment with the details ref: #501 #508 --- app/core/models/ticket/ticket.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index c2b5bb01a..6c0a94744 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -903,6 +903,11 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields comment_field_value = f"changed Real Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + if field == 'real_finish_date': + + comment_field_value = f"changed Real Finish Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + + if comment_field_value: if request: From 120380a95c98a379072ea6309b8081247ce41748 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:15:22 +0930 Subject: [PATCH 06/16] docs(roadmap): update ref: #508 --- docs/projects/centurion_erp/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/projects/centurion_erp/index.md b/docs/projects/centurion_erp/index.md index 17c779ad2..71ef2ed1f 100644 --- a/docs/projects/centurion_erp/index.md +++ b/docs/projects/centurion_erp/index.md @@ -137,7 +137,7 @@ Below is a list of modules/features we intend to add to Centurion. To find out w - Software _[see #3](https://github.com/nofusscomputing/centurion_erp/issues/3)_ - - IT Operations + - IT Operations _[see #493](https://github.com/nofusscomputing/centurion_erp/issues/493)_ - Release and Deployment Management _[see #462](https://github.com/nofusscomputing/centurion_erp/issues/462)_ From 76e7d64341b487ba6f598eea8d9fed68bd27ce1a Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:57:01 +0930 Subject: [PATCH 07/16] refactor(core): Ticket action comment for changing project to use item tasg ref: #492 #508 --- app/core/models/ticket/ticket.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index 6c0a94744..bc6624bcd 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -874,7 +874,20 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields if field == 'project_id': - comment_field_value = f"changed {field.replace('_id','')} to {self.project}" + value = 'None' + + if before[field]: + + value = f"$project-{before[field]}" + + to_value = getattr(self.project, 'id', 'None') + + if to_value != 'None': + + to_value = f"$project-{getattr(self.project, 'id', 'None')}" + + + comment_field_value = f"changed project from {value} to {to_value}" if field == 'milestone_id': From 7572763129deb83848e74c6dabad819c71836661 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 17:58:02 +0930 Subject: [PATCH 08/16] refactor(core): Ticket action comment for changing milestone to use item tasg ref: #497 #508 --- app/core/models/ticket/ticket.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index bc6624bcd..d65c9c126 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -891,18 +891,20 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields if field == 'milestone_id': - value = 'nothing' + value = 'None' + + if before[field]: - try: + value = f"$milestone-{before[field]}" - get_milestone = ProjectMilestone.objects.get( pk = before[field]) + to_value = getattr(self.milestone, 'id', 'None') + + if to_value != 'None': - value = get_milestone.name + to_value = f"$milestone-{getattr(self.milestone, 'id', 'None')}" - except: - pass - comment_field_value = f"changed milestone from _{value}_ to **{self.milestone}**" + comment_field_value = f"changed milestone from {value} to {to_value}" if field == 'planned_start_date': From 467fc18bd102c2e484ca5af727b99b3f0e86d8c8 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 18:59:22 +0930 Subject: [PATCH 09/16] test(core): Ticket Action comment tests moved to their own suite ref: #497 #508 --- .../unit/ticket/test_ticket_permission.py | 163 +++++++++++++++++- 1 file changed, 157 insertions(+), 6 deletions(-) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index 29771fdcb..d92e8f4e1 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -24,9 +24,8 @@ from settings.models.user_settings import UserSettings -class TicketPermissions( - ModelPermissions, -): + +class SetUp: ticket_type:str = None @@ -280,11 +279,9 @@ def setUpTestData(self): ) - @pytest.mark.skip(reason="To be written") - def test_permission_purge(self): - pass +class ActionComments(SetUp): def test_ticket_action_comment_assign_user_added_status_change(self): """Action Comment test @@ -848,6 +845,19 @@ def test_ticket_action_comment_related_ticket_removed(self): +class TicketPermissions( + SetUp, + ModelPermissions, +): + + + @pytest.mark.skip(reason="To be written") + def test_permission_purge(self): + + pass + + + class ITSMTicketPermissions( TicketPermissions, ITSMTicketFieldBasedPermissions, @@ -999,3 +1009,144 @@ class RequestTicketPermissions(ITSMTicketPermissions, TestCase): url_name_delete = '_ticket_request_delete' url_delete_response = reverse('Assistance:Requests') + + + + + +class ChangeTicketActionComments(ActionComments, TestCase): + + ticket_type = 'change' + + ticket_type_enum: int = int(Ticket.TicketType.CHANGE.value) + + app_namespace = 'ITIM' + + url_name_view = '_ticket_change_view' + + url_name_add = '_ticket_change_add' + + url_name_change = '_ticket_change_change' + + url_name_delete = '_ticket_change_delete' + + url_delete_response = reverse('ITIM:Changes') + + + +class IncidentTicketActionComments(ActionComments, TestCase): + + ticket_type = 'incident' + + ticket_type_enum: int = int(Ticket.TicketType.INCIDENT.value) + + app_namespace = 'ITIM' + + url_name_view = '_ticket_incident_view' + + url_name_add = '_ticket_incident_add' + + url_name_change = '_ticket_incident_change' + + url_name_delete = '_ticket_incident_delete' + + url_delete_response = reverse('ITIM:Incidents') + + + +class ProblemTicketActionComments(ActionComments, TestCase): + + ticket_type = 'problem' + + ticket_type_enum: int = int(Ticket.TicketType.PROBLEM.value) + + app_namespace = 'ITIM' + + url_name_view = '_ticket_problem_view' + + url_name_add = '_ticket_problem_add' + + url_name_change = '_ticket_problem_change' + + url_name_delete = '_ticket_problem_delete' + + url_delete_response = reverse('ITIM:Problems') + + + +class ProjectTaskActionComments(ActionComments, TestCase): + + ticket_type = 'project_task' + + ticket_type_enum: int = int(Ticket.TicketType.PROJECT_TASK.value) + + app_namespace = 'Project Management' + + url_name_view = '_project_task_view' + + url_name_add = '_project_task_add' + + url_name_change = '_project_task_change' + + url_name_delete = '_project_task_delete' + + + + + @classmethod + def setUpTestData(self): + """Setup Test + + 1. Create an organization for user and item + . create an organization that is different to item + 2. Create a manufacturer + 3. create teams with each permission: view, add, change, delete + 4. create a user per team + """ + + super().setUpTestData() + + self.item = self.model.objects.create( + organization = self.organization, + title = 'Amended ' + self.ticket_type + ' ticket', + description = 'the ticket body', + ticket_type = int(Ticket.TicketType.REQUEST.value), + opened_by = self.add_user, + status = int(Ticket.TicketStatus.All.NEW.value), + project = self.project + ) + + self.url_add_kwargs = {'project_id': self.project.id, 'ticket_type': self.ticket_type} + + self.url_change_kwargs = {'project_id': self.project.id, 'ticket_type': self.ticket_type, 'pk': self.item.id} + + self.url_delete_kwargs = {'project_id': self.project.id, 'ticket_type': self.ticket_type, 'pk': self.project.id} + + # self.url_delete_kwargs = {'pk': self.project.id} + + self.url_view_kwargs = {'project_id': self.project.id, 'ticket_type': self.ticket_type, 'pk': self.item.id} + + self.url_delete_response = reverse('Project Management:_project_view', kwargs={'pk': self.project.id}) + + + +class RequestTicketActionComments(ActionComments, TestCase): + + ticket_type = 'request' + + ticket_type_enum: int = int(Ticket.TicketType.REQUEST.value) + + app_namespace = 'Assistance' + + url_name_view = '_ticket_request_view' + + url_name_add = '_ticket_request_add' + + url_name_change = '_ticket_request_change' + + url_name_delete = '_ticket_request_delete' + + url_delete_response = reverse('Assistance:Requests') + + + From 7190354d6a564db65803d5d348043b02bc817346 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 19:01:07 +0930 Subject: [PATCH 10/16] test(core): Ticket Action comment test cases for project actions ref: #395 #508 --- .../unit/ticket/test_ticket_permission.py | 131 +++++++++++++++++- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index d92e8f4e1..230912150 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -826,22 +826,143 @@ def test_ticket_action_comment_related_ticket_added_type_blocked_by_destination( @pytest.mark.skip(reason='to be written') + def test_ticket_action_comment_related_ticket_removed(self): + """Action Comment test + Confirm an action comment is created when a related ticket is removed + """ + + pass + + + def test_ticket_action_comment_project_added(self): """Action Comment test Confirm a 'project added' action comment is created for the ticket when a project is added """ - pass + from_ticket = self.item + to_ticket = self.second_item + # prepare + self.item.project = None + self.item.save() - @pytest.mark.skip(reason='to be written') - def test_ticket_action_comment_related_ticket_removed(self): + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_add' + ) + + # add project + self.item.project = project + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed project from None to $project-{project.id}' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_project_removed(self): """Action Comment test - Confirm an action comment is created when a related ticket is removed + Confirm a 'project added' action comment is created for the ticket + when a project is added """ - pass + from_ticket = self.item + to_ticket = self.second_item + + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_remove' + ) + + # prepare + self.item.project = project + self.item.save() + + # remove project + self.item.project = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed project from $project-{project.id} to None' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_project_changed(self): + """Action Comment test + Confirm a 'project added' action comment is created for the ticket + when a project is added + """ + + from_ticket = self.item + to_ticket = self.second_item + + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_change' + ) + + project_two = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_change_two' + ) + + # prepare + self.item.project = project + self.item.save() + + # remove project + self.item.project = project_two + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed project from $project-{project.id} to $project-{project_two.id}' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + From f7543ced8d24166fdca9a77dc99bb9ea73d2b275 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 19:16:02 +0930 Subject: [PATCH 11/16] test(core): Ticket Action comment test cases for milestone actions ref: #508 closes #497 --- .../unit/ticket/test_ticket_permission.py | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index 230912150..d57e8148e 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -15,6 +15,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_comment import TicketComment @@ -964,6 +965,158 @@ def test_ticket_action_comment_project_changed(self): + def test_ticket_action_comment_milestone_added(self): + """Action Comment test + Confirm a 'project added' action comment is created for the ticket + when a project is added + """ + + from_ticket = self.item + to_ticket = self.second_item + + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_milestone_add' + ) + + milestone = ProjectMilestone.objects.create( + organization = self.item.organization, + name = 'ticket_milestone_add', + project = project + ) + + # prepare + self.item.project = project + self.item.save() + + # add milestone + self.item.milestone = milestone + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed milestone from None to $milestone-{milestone.id}' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_milestone_removed(self): + """Action Comment test + Confirm a 'project added' action comment is created for the ticket + when a project is added + """ + + from_ticket = self.item + to_ticket = self.second_item + + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_milestone_remove' + ) + + milestone = ProjectMilestone.objects.create( + organization = self.item.organization, + name = 'ticket_milestone_remove', + project = project + ) + + # prepare + self.item.project = project + self.item.milestone = milestone + self.item.save() + + # remove milestone + self.item.milestone = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed milestone from $milestone-{milestone.id} to None' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_milestone_changed(self): + """Action Comment test + Confirm a 'project added' action comment is created for the ticket + when a project is added + """ + + from_ticket = self.item + to_ticket = self.second_item + + # create fresh project as id will be unique for test + project = Project.objects.create( + organization = self.item.organization, + name = 'ticket_project_milestone_change' + ) + + + milestone = ProjectMilestone.objects.create( + organization = self.item.organization, + name = 'ticket_milestone_change', + project = project + ) + + + milestone_two = ProjectMilestone.objects.create( + organization = self.item.organization, + name = 'ticket_milestone_change_two', + project = project + ) + + + # prepare + self.item.project = project + self.item.milestone = milestone + self.item.save() + + # change milestone + self.item.milestone = milestone_two + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed milestone from $milestone-{milestone.id} to $milestone-{milestone_two.id}' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + class TicketPermissions( From 98bc0fc1d75bbd0a7d6b14ab1b2b8069b187e934 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 19:49:30 +0930 Subject: [PATCH 12/16] fix(core): Ticket Action comment date fields must be checked if empty before use ref: #492 #508 --- app/core/models/ticket/ticket.py | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index d65c9c126..c75928167 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -908,19 +908,49 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields if field == 'planned_start_date': - comment_field_value = f"changed Planned Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + to_value = after[field] + + if to_value: + + to_value = str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00' + + comment_field_value = f"changed Planned Start Date from _{before[field]}_ to **{to_value}**" if field == 'planned_finish_date': - comment_field_value = f"changed Planned Finish Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + to_value = after[field] + + if to_value: + + to_value = str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00' + + comment_field_value = f"changed Planned Finish Date from _{before[field]}_ to **{to_value}**" if field == 'real_start_date': - comment_field_value = f"changed Real Start Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + to_value = after[field] + + if to_value: + + to_value = str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00' + + comment_field_value = f"changed Real Start Date from _{before[field]}_ to **{to_value}**" + + to_value = after[field] + + if to_value: + + to_value = str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00' if field == 'real_finish_date': - comment_field_value = f"changed Real Finish Date from _{before[field]}_ to **{str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00'}**" + to_value = after[field] + + if to_value: + + to_value = str(after[field].utcfromtimestamp(after[field].timestamp()))+ '+00:00' + + comment_field_value = f"changed Real Finish Date from _{before[field]}_ to **{to_value}**" if comment_field_value: From 744d9a2ec4421520ccac0b9f5564e709e2e429ef Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 20:02:02 +0930 Subject: [PATCH 13/16] test(core): Ticket Action comment test cases for planned_start_date actions ref: #508 closes #498 --- .../unit/ticket/test_ticket_permission.py | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index d57e8148e..1c3b015f3 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -1,5 +1,7 @@ import re +from datetime import datetime + from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser, User from django.contrib.contenttypes.models import ContentType @@ -1118,6 +1120,114 @@ def test_ticket_action_comment_milestone_changed(self): + def test_ticket_action_comment_planned_start_date_added(self): + """Action Comment test + + When the field `planned_start_date` has a value added it must create + an action comment + """ + + from_value = None + to_value = '2025-01-27 00:01:00+00:00' + + # prepare + self.item.planned_start_date = from_value + self.item.save() + + # add desired value + self.item.planned_start_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_planned_start_date_change(self): + """Action Comment test + + When the field `planned_start_date` has a value change it must create + an action comment + """ + + from_value = '2025-01-27 00:02:00+00:00' + to_value = '2025-01-27 00:03:00+00:00' + + # prepare + self.item.planned_start_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.planned_start_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_planned_start_date_remove(self): + """Action Comment test + + When the field `planned_start_date` has a value removed it must create + an action comment + """ + + from_value = '2025-01-27 00:02:00+00:00' + to_value = None + + # prepare + self.item.planned_start_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.planned_start_date = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + class TicketPermissions( SetUp, From 32913895c93b929ffd8fe0057dd5fb99764425cc Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 20:02:37 +0930 Subject: [PATCH 14/16] test(core): Ticket Action comment test cases for planned_finish_date actions ref: #508 closes #500 --- .../unit/ticket/test_ticket_permission.py | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index 1c3b015f3..4be6d8e12 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -1229,6 +1229,114 @@ def test_ticket_action_comment_planned_start_date_remove(self): + def test_ticket_action_comment_planned_finish_date_added(self): + """Action Comment test + + When the field `planned_finish_date` has a value added it must create + an action comment + """ + + from_value = None + to_value = '2025-01-27 01:01:00+00:00' + + # prepare + self.item.planned_finish_date = from_value + self.item.save() + + # add desired value + self.item.planned_finish_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_planned_finish_date_change(self): + """Action Comment test + + When the field `planned_finish_date` has a value change it must create + an action comment + """ + + from_value = '2025-01-27 01:02:00+00:00' + to_value = '2025-01-27 01:03:00+00:00' + + # prepare + self.item.planned_finish_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.planned_finish_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_planned_finish_date_remove(self): + """Action Comment test + + When the field `planned_finish_date` has a value removed it must create + an action comment + """ + + from_value = '2025-01-27 01:04:00+00:00' + to_value = None + + # prepare + self.item.planned_finish_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.planned_finish_date = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Planned Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + class TicketPermissions( SetUp, ModelPermissions, From de2722f6cad14990c61d9ea28e51efd04ae545d0 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 20:03:25 +0930 Subject: [PATCH 15/16] test(core): Ticket Action comment test cases for real_start_date actions ref: #508 closes #499 --- .../unit/ticket/test_ticket_permission.py | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index 4be6d8e12..5437d68ad 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -1337,6 +1337,114 @@ def test_ticket_action_comment_planned_finish_date_remove(self): assert action_comment + + def test_ticket_action_comment_real_start_date_added(self): + """Action Comment test + + When the field `real_start_date` has a value added it must create + an action comment + """ + + from_value = None + to_value = '2025-01-27 00:01:00+00:00' + + # prepare + self.item.real_start_date = from_value + self.item.save() + + # add desired value + self.item.real_start_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_real_start_date_change(self): + """Action Comment test + + When the field `real_start_date` has a value change it must create + an action comment + """ + + from_value = '2025-01-27 00:02:00+00:00' + to_value = '2025-01-27 00:03:00+00:00' + + # prepare + self.item.real_start_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.real_start_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_real_start_date_remove(self): + """Action Comment test + + When the field `real_start_date` has a value removed it must create + an action comment + """ + + from_value = '2025-01-27 00:02:00+00:00' + to_value = None + + # prepare + self.item.real_start_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.real_start_date = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Start Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + class TicketPermissions( SetUp, ModelPermissions, From 26e475a42ff12f91ff1a72d765cd1f174ca4d6cc Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 27 Jan 2025 20:04:16 +0930 Subject: [PATCH 16/16] test(core): Ticket Action comment test cases for real_finish_date actions ref: #508 closes #501 --- .../unit/ticket/test_ticket_permission.py | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/app/core/tests/unit/ticket/test_ticket_permission.py b/app/core/tests/unit/ticket/test_ticket_permission.py index 5437d68ad..2e9b7109a 100644 --- a/app/core/tests/unit/ticket/test_ticket_permission.py +++ b/app/core/tests/unit/ticket/test_ticket_permission.py @@ -1445,6 +1445,117 @@ def test_ticket_action_comment_real_start_date_remove(self): assert action_comment + + + def test_ticket_action_comment_real_finish_date_added(self): + """Action Comment test + + When the field `real_finish_date` has a value added it must create + an action comment + """ + + from_value = None + to_value = '2025-01-27 01:01:00+00:00' + + # prepare + self.item.real_finish_date = from_value + self.item.save() + + # add desired value + self.item.real_finish_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_real_finish_date_change(self): + """Action Comment test + + When the field `real_finish_date` has a value change it must create + an action comment + """ + + from_value = '2025-01-27 01:02:00+00:00' + to_value = '2025-01-27 01:03:00+00:00' + + # prepare + self.item.real_finish_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.real_finish_date = datetime.strptime(to_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + def test_ticket_action_comment_real_finish_date_remove(self): + """Action Comment test + + When the field `real_finish_date` has a value removed it must create + an action comment + """ + + from_value = '2025-01-27 01:04:00+00:00' + to_value = None + + # prepare + self.item.real_finish_date = datetime.strptime(from_value, '%Y-%m-%d %H:%M:%S%z') + self.item.save() + + # add desired value + self.item.real_finish_date = None + self.item.save() + + comments = TicketComment.objects.filter( + ticket=self.item, + comment_type = TicketComment.CommentType.ACTION + ) + + action_comment: bool = False + + comment_body: str = f'changed Real Finish Date from _{from_value}_ to **{to_value}**' + + for comment in comments: + + if str(comment_body).lower() == str(comment.body).lower(): + + action_comment = True + + assert action_comment + + + class TicketPermissions( SetUp, ModelPermissions,