fix untested error in /tickets endpoint
This commit is contained in:
parent
81a0959547
commit
0eaff2266c
2 changed files with 24 additions and 14 deletions
|
@ -21,7 +21,7 @@ from tickets.shared_serializers import RelationSerializer
|
||||||
|
|
||||||
class IssueViewSet(viewsets.ModelViewSet):
|
class IssueViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = IssueSerializer
|
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):
|
class RelationViewSet(viewsets.ModelViewSet):
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.test import TestCase, Client
|
||||||
from authentication.models import ExtendedUser
|
from authentication.models import ExtendedUser
|
||||||
from inventory.models import Event, Container, Item
|
from inventory.models import Event, Container, Item
|
||||||
from mail.models import Email, EmailAttachment
|
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 django.contrib.auth.models import Permission
|
||||||
from knox.models import AuthToken
|
from knox.models import AuthToken
|
||||||
|
|
||||||
|
@ -53,19 +53,24 @@ class IssueApiTest(TestCase):
|
||||||
in_reply_to=mail1.reference,
|
in_reply_to=mail1.reference,
|
||||||
timestamp=now + timedelta(seconds=2),
|
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(
|
comment = Comment.objects.create(
|
||||||
issue_thread=issue,
|
issue_thread=issue,
|
||||||
comment="test",
|
comment="test",
|
||||||
timestamp=now + timedelta(seconds=3),
|
timestamp=now + timedelta(seconds=4),
|
||||||
)
|
)
|
||||||
match = ItemRelation.objects.create(
|
match = ItemRelation.objects.create(
|
||||||
issue_thread=issue,
|
issue_thread=issue,
|
||||||
item = self.item,
|
item=self.item,
|
||||||
timestamp=now + timedelta(seconds=5),
|
timestamp=now + timedelta(seconds=5),
|
||||||
)
|
)
|
||||||
self.assertEqual('pending_new', issue.state)
|
self.assertEqual('pending_new', issue.state)
|
||||||
self.assertEqual('test issue', issue.name)
|
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))
|
self.assertEqual(36, len(issue.uuid))
|
||||||
response = self.client.get('/api/2/tickets/')
|
response = self.client.get('/api/2/tickets/')
|
||||||
self.assertEqual(response.status_code, 200)
|
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]['name'], "test issue")
|
||||||
self.assertEqual(response.json()[0]['state'], "pending_new")
|
self.assertEqual(response.json()[0]['state'], "pending_new")
|
||||||
self.assertEqual(response.json()[0]['event'], "evt")
|
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]['uuid'], issue.uuid)
|
||||||
self.assertEqual(response.json()[0]['last_activity'], match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
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'][0]['type'], 'state')
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['type'], 'mail')
|
self.assertEqual(response.json()[0]['timeline'][1]['type'], 'mail')
|
||||||
self.assertEqual(response.json()[0]['timeline'][2]['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'][1]['id'], mail1.id)
|
||||||
self.assertEqual(response.json()[0]['timeline'][2]['id'], mail2.id)
|
self.assertEqual(response.json()[0]['timeline'][2]['id'], mail2.id)
|
||||||
self.assertEqual(response.json()[0]['timeline'][3]['id'], comment.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]['body'], 'test')
|
||||||
self.assertEqual(response.json()[0]['timeline'][2]['timestamp'],
|
self.assertEqual(response.json()[0]['timeline'][2]['timestamp'],
|
||||||
mail2.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
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'],
|
self.assertEqual(response.json()[0]['timeline'][3]['timestamp'],
|
||||||
comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
assignment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
||||||
self.assertEqual(response.json()[0]['timeline'][4]['status'], 'possible')
|
self.assertEqual(response.json()[0]['timeline'][4]['comment'], 'test')
|
||||||
self.assertEqual(response.json()[0]['timeline'][4]['timestamp'],
|
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'))
|
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'][5]['item']['description'], "foo")
|
||||||
self.assertEqual(response.json()[0]['timeline'][4]['item']['event'], "evt")
|
self.assertEqual(response.json()[0]['timeline'][5]['item']['event'], "evt")
|
||||||
self.assertEqual(response.json()[0]['timeline'][4]['item']['box'], "box1")
|
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]['description'], "foo")
|
||||||
self.assertEqual(response.json()[0]['related_items'][0]['event'], "evt")
|
self.assertEqual(response.json()[0]['related_items'][0]['event'], "evt")
|
||||||
self.assertEqual(response.json()[0]['related_items'][0]['box'], "box1")
|
self.assertEqual(response.json()[0]['related_items'][0]['box'], "box1")
|
||||||
|
|
Loading…
Reference in a new issue