From 7288845e92589ed3f23ad8de100d3f6446f95886 Mon Sep 17 00:00:00 2001 From: Christopher Broderick Date: Wed, 9 Apr 2025 07:36:13 +0100 Subject: [PATCH] Add required POST params to tests - update uses better form validation. --- helpdesk/tests/test_checklist.py | 20 +++++++++++++++++--- helpdesk/tests/test_navigation.py | 4 ++-- helpdesk/tests/test_ticket_actions.py | 15 ++++++++++++++- helpdesk/tests/test_time_spent_auto.py | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/helpdesk/tests/test_checklist.py b/helpdesk/tests/test_checklist.py index 3454f47a..982faa38 100644 --- a/helpdesk/tests/test_checklist.py +++ b/helpdesk/tests/test_checklist.py @@ -17,8 +17,14 @@ class TicketChecklistTestCase(TestCase): self.client.login(username="User", password="pass") self.ticket = Ticket.objects.create( - queue=Queue.objects.create(title="Queue", slug="queue") + queue=Queue.objects.create(title="Queue", slug="queue"), + title="Test Queue" ) + self.default_update_post_data = { + "queue": self.ticket.queue_id, + "title": self.ticket.title, + "priority": self.ticket.priority, + } def test_create_checklist(self): self.assertEqual(self.ticket.checklists.count(), 0) @@ -141,7 +147,10 @@ class TicketChecklistTestCase(TestCase): response = self.client.post( reverse("helpdesk:update", kwargs={"ticket_id": self.ticket.id}), - data={f"checklist-{checklist.id}": task.id}, + data={ + f"checklist-{checklist.id}": task.id, + **self.default_update_post_data, + }, follow=True, ) self.assertEqual(response.status_code, 200) @@ -166,7 +175,12 @@ class TicketChecklistTestCase(TestCase): self.assertEqual(self.ticket.followup_set.count(), 0) response = self.client.post( - reverse("helpdesk:update", kwargs={"ticket_id": self.ticket.id}), + reverse("helpdesk:update", + kwargs={"ticket_id": self.ticket.id}), + data={ + + **self.default_update_post_data + }, follow=True, ) self.assertEqual(response.status_code, 200) diff --git a/helpdesk/tests/test_navigation.py b/helpdesk/tests/test_navigation.py index 9c695d20..ab6aae85 100644 --- a/helpdesk/tests/test_navigation.py +++ b/helpdesk/tests/test_navigation.py @@ -279,7 +279,7 @@ class ReturnToTicketTestCase(TestCase): user = get_staff_user() ticket = create_ticket() - response = return_to_ticket(user, helpdesk_settings, ticket) + response = return_to_ticket(user, ticket) self.assertEqual(response["location"], ticket.get_absolute_url()) def test_non_staff_user(self): @@ -291,5 +291,5 @@ class ReturnToTicketTestCase(TestCase): email="wensleydale@example.com", ) ticket = create_ticket() - response = return_to_ticket(user, helpdesk_settings, ticket) + response = return_to_ticket(user, ticket) self.assertEqual(response["location"], ticket.ticket_url) diff --git a/helpdesk/tests/test_ticket_actions.py b/helpdesk/tests/test_ticket_actions.py index 92da0b1f..537b02f0 100644 --- a/helpdesk/tests/test_ticket_actions.py +++ b/helpdesk/tests/test_ticket_actions.py @@ -119,9 +119,15 @@ class TicketActionsTestCase(TestCase): ticket = Ticket.objects.create(**initial_data) ticket_id = ticket.id + default_post_data = { + "title": ticket.title, + "priority": ticket.priority, + "queue": ticket.queue_id, + } # assign new owner post_data = { "owner": self.user2.id, + **default_post_data, } response = self.client.post( reverse("helpdesk:update", kwargs={"ticket_id": ticket_id}), @@ -139,7 +145,11 @@ class TicketActionsTestCase(TestCase): self.user2.save() self.user.email = "user1@test.com" self.user.save() - post_data = {"new_status": Ticket.CLOSED_STATUS, "public": True} + post_data = { + "new_status": Ticket.CLOSED_STATUS, + "public": True, + **default_post_data, + } # do this also to a newly assigned user (different from logged in one) ticket.assigned_to = self.user @@ -153,6 +163,7 @@ class TicketActionsTestCase(TestCase): "new_status": Ticket.OPEN_STATUS, "owner": self.user2.id, "public": True, + **default_post_data, } response = self.client.post( reverse("helpdesk:update", kwargs={"ticket_id": ticket_id}), @@ -363,6 +374,8 @@ class TicketActionsTestCase(TestCase): slug="newqueue", ) post_data = { + "title": ticket.title, + "priority": ticket.priority, "comment": "first follow-up in new queue", "queue": str(new_queue.id), } diff --git a/helpdesk/tests/test_time_spent_auto.py b/helpdesk/tests/test_time_spent_auto.py index 0055b08a..af32b90a 100644 --- a/helpdesk/tests/test_time_spent_auto.py +++ b/helpdesk/tests/test_time_spent_auto.py @@ -416,6 +416,7 @@ class TimeSpentAutoTestCase(TestCase): "created": datetime.strptime( "2024-04-09T08:00:00+00:00", "%Y-%m-%dT%H:%M:%S%z" ), + "description": "ollowup time spent auto exclude queues" } ticket = Ticket.objects.create(**initial_data) @@ -427,6 +428,8 @@ class TimeSpentAutoTestCase(TestCase): post_data = { "comment": "ticket in queue {}".format(queue), "queue": queues[queue].id, + "title": ticket.title, + "priority": ticket.priority, } self.client.post( reverse("helpdesk:update", kwargs={"ticket_id": ticket.id}), post_data