forked from extern/django-helpdesk
Create two new tests for ticket followups and followup attachments + adapt one test (needed to use freezegun)
This commit is contained in:
parent
9dbe283dd4
commit
e47170858e
@ -1,8 +1,11 @@
|
||||
import base64
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from freezegun import freeze_time
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from pytz import UTC
|
||||
from rest_framework import HTTP_HEADER_ENCODING
|
||||
from rest_framework.exceptions import ErrorDetail
|
||||
from rest_framework.status import HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST, HTTP_403_FORBIDDEN
|
||||
@ -72,6 +75,7 @@ class TicketTest(APITestCase):
|
||||
self.assertEqual(created_ticket.description, 'Test description\nMulti lines')
|
||||
self.assertEqual(created_ticket.submitter_email, 'test@mail.com')
|
||||
self.assertEqual(created_ticket.priority, 4)
|
||||
self.assertEqual(created_ticket.followup_set.count(), 1)
|
||||
|
||||
def test_create_api_ticket_with_basic_auth(self):
|
||||
username = 'admin'
|
||||
@ -178,6 +182,7 @@ class TicketTest(APITestCase):
|
||||
self.assertEqual(response.status_code, HTTP_204_NO_CONTENT)
|
||||
self.assertFalse(Ticket.objects.exists())
|
||||
|
||||
@freeze_time('2022-06-30 23:09:44')
|
||||
def test_create_api_ticket_with_custom_fields(self):
|
||||
# Create custom fields
|
||||
for field_type, field_display in CustomField.DATA_TYPE_CHOICES:
|
||||
@ -247,6 +252,19 @@ class TicketTest(APITestCase):
|
||||
'priority': 4,
|
||||
'due_date': None,
|
||||
'merged_to': None,
|
||||
'followup_set': [OrderedDict([
|
||||
('id', 1),
|
||||
('ticket', 1),
|
||||
('date', '2022-06-30T23:09:44'),
|
||||
('title', 'Ticket Opened'),
|
||||
('comment', 'Test description\nMulti lines'),
|
||||
('public', True),
|
||||
('user', 1),
|
||||
('new_status', None),
|
||||
('message_id', None),
|
||||
('time_spent', None),
|
||||
('followupattachment_set', [])
|
||||
])],
|
||||
'custom_varchar': 'test',
|
||||
'custom_text': 'multi\nline',
|
||||
'custom_integer': 1,
|
||||
@ -262,3 +280,54 @@ class TicketTest(APITestCase):
|
||||
'custom_slug': 'test-slug'
|
||||
})
|
||||
|
||||
def test_create_api_ticket_with_attachment(self):
|
||||
staff_user = User.objects.create_user(username='test', is_staff=True)
|
||||
self.client.force_authenticate(staff_user)
|
||||
test_file = SimpleUploadedFile('file.jpg', b'file_content', content_type='image/jpg')
|
||||
response = self.client.post('/api/tickets/', {
|
||||
'queue': self.queue.id,
|
||||
'title': 'Test title',
|
||||
'description': 'Test description\nMulti lines',
|
||||
'submitter_email': 'test@mail.com',
|
||||
'priority': 4,
|
||||
'attachment': test_file
|
||||
})
|
||||
self.assertEqual(response.status_code, HTTP_201_CREATED)
|
||||
created_ticket = Ticket.objects.get()
|
||||
self.assertEqual(created_ticket.title, 'Test title')
|
||||
self.assertEqual(created_ticket.description, 'Test description\nMulti lines')
|
||||
self.assertEqual(created_ticket.submitter_email, 'test@mail.com')
|
||||
self.assertEqual(created_ticket.priority, 4)
|
||||
self.assertEqual(created_ticket.followup_set.count(), 1)
|
||||
self.assertEqual(created_ticket.followup_set.get().followupattachment_set.count(), 1)
|
||||
attachment = created_ticket.followup_set.get().followupattachment_set.get()
|
||||
self.assertEqual(
|
||||
attachment.file.name,
|
||||
f'helpdesk/attachments/test-queue-1-{created_ticket.secret_key}/1/file.jpg'
|
||||
)
|
||||
|
||||
def test_create_follow_up_with_attachments(self):
|
||||
staff_user = User.objects.create_user(username='test', is_staff=True)
|
||||
self.client.force_authenticate(staff_user)
|
||||
ticket = Ticket.objects.create(queue=self.queue, title='Test')
|
||||
test_file_1 = SimpleUploadedFile('file.jpg', b'file_content', content_type='image/jpg')
|
||||
test_file_2 = SimpleUploadedFile('doc.pdf', b'Doc content', content_type='application/pdf')
|
||||
|
||||
response = self.client.post('/api/followups/', {
|
||||
'ticket': ticket.id,
|
||||
'title': 'Test',
|
||||
'comment': 'Test answer\nMulti lines',
|
||||
'attachments': [
|
||||
test_file_1,
|
||||
test_file_2
|
||||
]
|
||||
})
|
||||
self.assertEqual(response.status_code, HTTP_201_CREATED)
|
||||
created_followup = ticket.followup_set.last()
|
||||
self.assertEqual(created_followup.title, 'Test')
|
||||
self.assertEqual(created_followup.comment, 'Test answer\nMulti lines')
|
||||
self.assertEqual(created_followup.followupattachment_set.count(), 2)
|
||||
self.assertEqual(created_followup.followupattachment_set.first().filename, 'doc.pdf')
|
||||
self.assertEqual(created_followup.followupattachment_set.first().mime_type, 'application/pdf')
|
||||
self.assertEqual(created_followup.followupattachment_set.last().filename, 'file.jpg')
|
||||
self.assertEqual(created_followup.followupattachment_set.last().mime_type, 'image/jpg')
|
||||
|
@ -5,3 +5,4 @@ coverage
|
||||
argparse
|
||||
pbr
|
||||
mock
|
||||
freezegun
|
||||
|
Loading…
Reference in New Issue
Block a user