From 0eaff2266c0c214b46597b55b2e40072926740f2 Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 21 Nov 2024 22:37:49 +0100 Subject: [PATCH] fix untested error in /tickets endpoint --- core/tickets/api_v2.py | 2 +- core/tickets/tests/v2/test_tickets.py | 36 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/core/tickets/api_v2.py b/core/tickets/api_v2.py index 1f2696d..e90da49 100644 --- a/core/tickets/api_v2.py +++ b/core/tickets/api_v2.py @@ -21,7 +21,7 @@ from tickets.shared_serializers import RelationSerializer class IssueViewSet(viewsets.ModelViewSet): serializer_class = IssueSerializer - queryset = IssueThread.objects.all().prefetch_related('state_changes', 'comments', 'emails', 'emails__attachments', 'assignments', 'assignments__assigned_to__username', 'item_relation_changes', 'shipping_vouchers') + queryset = IssueThread.objects.all().prefetch_related('state_changes', 'comments', 'emails', 'emails__attachments', 'assignments', 'item_relation_changes', 'shipping_vouchers') class RelationViewSet(viewsets.ModelViewSet): diff --git a/core/tickets/tests/v2/test_tickets.py b/core/tickets/tests/v2/test_tickets.py index 105de93..9720625 100644 --- a/core/tickets/tests/v2/test_tickets.py +++ b/core/tickets/tests/v2/test_tickets.py @@ -5,7 +5,7 @@ from django.test import TestCase, Client from authentication.models import ExtendedUser from inventory.models import Event, Container, Item from mail.models import Email, EmailAttachment -from tickets.models import IssueThread, StateChange, Comment, ItemRelation +from tickets.models import IssueThread, StateChange, Comment, ItemRelation, Assignment from django.contrib.auth.models import Permission from knox.models import AuthToken @@ -53,19 +53,24 @@ class IssueApiTest(TestCase): in_reply_to=mail1.reference, timestamp=now + timedelta(seconds=2), ) + assignment = Assignment.objects.create( + issue_thread=issue, + assigned_to=self.user, + timestamp=now + timedelta(seconds=3), + ) comment = Comment.objects.create( issue_thread=issue, comment="test", - timestamp=now + timedelta(seconds=3), + timestamp=now + timedelta(seconds=4), ) match = ItemRelation.objects.create( issue_thread=issue, - item = self.item, + item=self.item, timestamp=now + timedelta(seconds=5), ) self.assertEqual('pending_new', issue.state) self.assertEqual('test issue', issue.name) - self.assertEqual(None, issue.assigned_to) + self.assertEqual(self.user, issue.assigned_to) self.assertEqual(36, len(issue.uuid)) response = self.client.get('/api/2/tickets/') self.assertEqual(response.status_code, 200) @@ -74,14 +79,16 @@ class IssueApiTest(TestCase): self.assertEqual(response.json()[0]['name'], "test issue") self.assertEqual(response.json()[0]['state'], "pending_new") self.assertEqual(response.json()[0]['event'], "evt") - self.assertEqual(response.json()[0]['assigned_to'], None) + self.assertEqual(response.json()[0]['assigned_to'], self.user.username) self.assertEqual(response.json()[0]['uuid'], issue.uuid) self.assertEqual(response.json()[0]['last_activity'], match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(len(response.json()[0]['timeline']), 5) + self.assertEqual(len(response.json()[0]['timeline']), 6) self.assertEqual(response.json()[0]['timeline'][0]['type'], 'state') self.assertEqual(response.json()[0]['timeline'][1]['type'], 'mail') self.assertEqual(response.json()[0]['timeline'][2]['type'], 'mail') - self.assertEqual(response.json()[0]['timeline'][3]['type'], 'comment') + self.assertEqual(response.json()[0]['timeline'][3]['type'], 'assignment') + self.assertEqual(response.json()[0]['timeline'][4]['type'], 'comment') + self.assertEqual(response.json()[0]['timeline'][5]['type'], 'item_relation') self.assertEqual(response.json()[0]['timeline'][1]['id'], mail1.id) self.assertEqual(response.json()[0]['timeline'][2]['id'], mail2.id) self.assertEqual(response.json()[0]['timeline'][3]['id'], comment.id) @@ -98,15 +105,18 @@ class IssueApiTest(TestCase): self.assertEqual(response.json()[0]['timeline'][2]['body'], 'test') self.assertEqual(response.json()[0]['timeline'][2]['timestamp'], mail2.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(response.json()[0]['timeline'][3]['comment'], 'test') + self.assertEqual(response.json()[0]['timeline'][3]['assigned_to'], self.user.username) self.assertEqual(response.json()[0]['timeline'][3]['timestamp'], - comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(response.json()[0]['timeline'][4]['status'], 'possible') + assignment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) + self.assertEqual(response.json()[0]['timeline'][4]['comment'], 'test') self.assertEqual(response.json()[0]['timeline'][4]['timestamp'], + comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) + self.assertEqual(response.json()[0]['timeline'][5]['status'], 'possible') + self.assertEqual(response.json()[0]['timeline'][5]['timestamp'], match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(response.json()[0]['timeline'][4]['item']['description'], "foo") - self.assertEqual(response.json()[0]['timeline'][4]['item']['event'], "evt") - self.assertEqual(response.json()[0]['timeline'][4]['item']['box'], "box1") + self.assertEqual(response.json()[0]['timeline'][5]['item']['description'], "foo") + self.assertEqual(response.json()[0]['timeline'][5]['item']['event'], "evt") + self.assertEqual(response.json()[0]['timeline'][5]['item']['box'], "box1") self.assertEqual(response.json()[0]['related_items'][0]['description'], "foo") self.assertEqual(response.json()[0]['related_items'][0]['event'], "evt") self.assertEqual(response.json()[0]['related_items'][0]['box'], "box1")