Fix tests for Django 5

This commit is contained in:
Christopher Broderick 2025-05-13 17:14:57 +01:00
parent a436ce0533
commit ae9e1bfe78
3 changed files with 41 additions and 31 deletions

View File

@ -1,6 +1,5 @@
import base64
from collections import OrderedDict
from datetime import datetime
import datetime
from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile
from freezegun import freeze_time
@ -15,10 +14,15 @@ from rest_framework.status import (
HTTP_403_FORBIDDEN,
)
from rest_framework.test import APITestCase
from _datetime import timedelta
from helpdesk.lib import convert_value
from django.utils import timezone
frozen_date_time_str = (datetime.datetime.now() - timedelta(days=100)).isoformat()
class TicketTest(APITestCase):
due_date = datetime(2022, 4, 10, 15, 6)
due_date = timezone.now() - timedelta(days=20)
@classmethod
def setUpTestData(cls):
@ -212,8 +216,12 @@ 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")
@freeze_time(frozen_date_time_str)
def test_create_api_ticket_with_custom_fields(self):
custom_date = "2022-04-11"
custom_time = "23:59:59"
custom_datetime = convert_value(datetime.datetime.now() - timedelta(days=30))
# Create custom fields
for field_type, field_display in CustomField.DATA_TYPE_CHOICES:
extra_data = {}
@ -273,9 +281,9 @@ class TicketTest(APITestCase):
"custom_decimal": "42.987",
"custom_list": "Red",
"custom_boolean": True,
"custom_date": "2022-4-11",
"custom_time": "23:59:59",
"custom_datetime": "2022-4-10 18:27",
"custom_date": custom_date,
"custom_time": custom_time,
"custom_datetime": custom_datetime,
"custom_email": "email@test.com",
"custom_url": "http://django-helpdesk.readthedocs.org/",
"custom_ipaddress": "127.0.0.1",
@ -284,7 +292,9 @@ class TicketTest(APITestCase):
)
self.assertEqual(response.status_code, HTTP_201_CREATED)
# Check all fields with data returned from the response
self.assertEqual(
self.maxDiff = None
# followup_set = response.data.pop("followup_set")
self.assertDictEqual(
response.data,
{
"id": 1,
@ -300,21 +310,19 @@ class TicketTest(APITestCase):
"due_date": None,
"merged_to": None,
"followup_set": [
OrderedDict(
[
("id", 1),
("ticket", 1),
("user", 1),
("title", "Ticket Opened"),
("comment", "Test description\nMulti lines"),
("public", True),
("new_status", None),
("time_spent", None),
("followupattachment_set", []),
("date", "2022-06-30T23:09:44"),
("message_id", None),
]
)
{
"id": 1,
"ticket": 1,
"user": 1,
"title": "Ticket Opened",
"comment": "Test description\nMulti lines",
"public": True,
"new_status": None,
"time_spent": None,
"followupattachment_set": [],
"date": frozen_date_time_str + "Z",
"message_id": None,
}
],
"custom_varchar": "test",
"custom_text": "multi\nline",
@ -322,9 +330,9 @@ class TicketTest(APITestCase):
"custom_decimal": "42.987",
"custom_list": "Red",
"custom_boolean": True,
"custom_date": "2022-04-11",
"custom_time": "23:59:59",
"custom_datetime": "2022-04-10T18:27",
"custom_date": custom_date,
"custom_time": custom_time,
"custom_datetime": custom_datetime,
"custom_email": "email@test.com",
"custom_url": "http://django-helpdesk.readthedocs.org/",
"custom_ipaddress": "127.0.0.1",

View File

@ -1,8 +1,9 @@
from datetime import datetime
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from helpdesk.models import Checklist, ChecklistTask, ChecklistTemplate, Queue, Ticket
from _datetime import timedelta
from django.utils import timezone
class TicketChecklistTestCase(TestCase):
@ -167,7 +168,9 @@ class TicketChecklistTestCase(TestCase):
def test_mark_task_as_undone(self):
checklist = self.ticket.checklists.create(name="Test checklist")
task = checklist.tasks.create(
description="Task", position=1, completion_date=datetime(2023, 5, 1)
description="Task",
position=1,
completion_date=timezone.now() - timedelta(days=10),
)
self.assertIsNotNone(task.completion_date)

View File

@ -8,6 +8,7 @@ from django.urls import reverse
from helpdesk.models import FollowUp, Queue, Ticket
from helpdesk import settings as helpdesk_settings
import uuid
from django.utils import timezone
@override_settings(USE_TZ=True)
@ -413,9 +414,7 @@ class TimeSpentAutoTestCase(TestCase):
"queue": queues["new"],
"assigned_to": self.user,
"status": Ticket.OPEN_STATUS,
"created": datetime.strptime(
"2024-04-09T08:00:00+00:00", "%Y-%m-%dT%H:%M:%S%z"
),
"created": timezone.now() - timedelta(days=10),
"description": "Followup time spent auto exclude queues",
}
ticket = Ticket.objects.create(**initial_data)