mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-12-27 00:59:00 +01:00
Merge branch 'formatting' of /home/martin/git/django-helpdesk into
formatting
This commit is contained in:
commit
f0109d7280
@ -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
|
||||
@ -73,6 +76,7 @@ class TicketTest(APITestCase):
|
||||
'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'
|
||||
@ -191,6 +195,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:
|
||||
@ -262,6 +267,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,
|
||||
@ -276,3 +294,64 @@ class TicketTest(APITestCase):
|
||||
'custom_ipaddress': '127.0.0.1',
|
||||
'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')
|
||||
|
11
setup.py
11
setup.py
@ -24,6 +24,8 @@ standard_exclude_directories = (
|
||||
# Note: you may want to copy this into your setup.py file verbatim, as
|
||||
# you can't import this from another package, when you don't know if
|
||||
# that package is installed yet.
|
||||
|
||||
|
||||
def find_package_data(
|
||||
where=".",
|
||||
package="",
|
||||
@ -72,7 +74,8 @@ def find_package_data(
|
||||
bad_name = True
|
||||
if show_ignored:
|
||||
print(
|
||||
"Directory %s ignored by pattern %s" % (fn, pattern),
|
||||
"Directory %s ignored by pattern %s" % (
|
||||
fn, pattern),
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
@ -86,7 +89,8 @@ def find_package_data(
|
||||
new_package = package + "." + name
|
||||
stack.append((fn, "", new_package, False))
|
||||
else:
|
||||
stack.append((fn, prefix + name + "/", package, only_in_packages))
|
||||
stack.append((fn, prefix + name + "/",
|
||||
package, only_in_packages))
|
||||
elif package or not only_in_packages:
|
||||
# is a file
|
||||
bad_name = False
|
||||
@ -95,7 +99,8 @@ def find_package_data(
|
||||
bad_name = True
|
||||
if show_ignored:
|
||||
print(
|
||||
"File %s ignored by pattern %s" % (fn, pattern),
|
||||
"File %s ignored by pattern %s" % (
|
||||
fn, pattern),
|
||||
file=sys.stderr,
|
||||
)
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user