Updating time_spent test with multiple follow-ups at multiple time intervals

This commit is contained in:
Sam Splunks 2024-03-27 14:20:34 +00:00
parent f4bde19511
commit d6b37f1c11

View File

@ -45,7 +45,7 @@ class TimeSpentAutoTestCase(TestCase):
# friday # friday
('2024-03-01T00:00:00+00:00', '2024-03-01T09:30:10+00:00', timedelta(hours=9, minutes=30, seconds=10)), ('2024-03-01T00:00:00+00:00', '2024-03-01T09:30:10+00:00', timedelta(hours=9, minutes=30, seconds=10)),
('2024-03-01T00:00:00+00:00', '2024-03-01T23:59:58+00:00', timedelta(hours=23, minutes=59, seconds=58)), ('2024-03-01T00:00:00+00:00', '2024-03-01T23:59:58+00:00', timedelta(hours=23, minutes=59, seconds=58)),
('2024-03-01T00:00:00+00:00', '2024-03-01T23:59:59+00:00', timedelta(hours=24)), ('2024-03-01T00:00:00+00:00', '2024-03-01T23:59:59+00:00', timedelta(hours=23, minutes=59, seconds=59)),
('2024-03-01T00:00:00+00:00', '2024-03-02T00:00:00+00:00', timedelta(hours=24)), ('2024-03-01T00:00:00+00:00', '2024-03-02T00:00:00+00:00', timedelta(hours=24)),
('2024-03-01T00:00:00+00:00', '2024-03-02T09:00:00+00:00', timedelta(hours=33)), ('2024-03-01T00:00:00+00:00', '2024-03-02T09:00:00+00:00', timedelta(hours=33)),
('2024-03-01T00:00:00+00:00', '2024-03-03T00:00:00+00:00', timedelta(hours=48)), ('2024-03-01T00:00:00+00:00', '2024-03-03T00:00:00+00:00', timedelta(hours=48)),
@ -54,15 +54,15 @@ class TimeSpentAutoTestCase(TestCase):
for (ticket_time, fup_time, assertion_delta) in TEST_VALUES: for (ticket_time, fup_time, assertion_delta) in TEST_VALUES:
# create and setup test ticket time # create and setup test ticket time
ticket = Ticket.objects.create(**self.ticket_data) ticket = Ticket.objects.create(**self.ticket_data)
ticket_time = datetime.strptime(ticket_time, "%Y-%m-%dT%H:%M:%S%z") ticket_time_p = datetime.strptime(ticket_time, "%Y-%m-%dT%H:%M:%S%z")
ticket.created = ticket_time ticket.created = ticket_time_p
ticket.modified = ticket_time ticket.modified = ticket_time_p
ticket.save() ticket.save()
fup_time = datetime.strptime(fup_time, "%Y-%m-%dT%H:%M:%S%z") fup_time_p = datetime.strptime(fup_time, "%Y-%m-%dT%H:%M:%S%z")
followup1 = FollowUp.objects.create( followup1 = FollowUp.objects.create(
ticket=ticket, ticket=ticket,
date=fup_time, date=fup_time_p,
title="Testing followup", title="Testing followup",
comment="Testing followup time spent", comment="Testing followup time spent",
public=True, public=True,
@ -76,24 +76,24 @@ class TimeSpentAutoTestCase(TestCase):
self.assertEqual(followup1.time_spent.total_seconds(), assertion_delta.total_seconds()) self.assertEqual(followup1.time_spent.total_seconds(), assertion_delta.total_seconds())
self.assertEqual(ticket.time_spent.total_seconds(), assertion_delta.total_seconds()) self.assertEqual(ticket.time_spent.total_seconds(), assertion_delta.total_seconds())
# adding a second follow-up 1 hour later # adding a second follow-up at different intervals
hour_delta = timedelta(hours=1) for delta in (timedelta(seconds=1), timedelta(minutes=1), timedelta(hours=1), timedelta(days=1), timedelta(days=10)):
followup2 = FollowUp.objects.create(
ticket=ticket, followup2 = FollowUp.objects.create(
date=followup1.date + hour_delta, ticket=ticket,
title="Testing followup 2", date=followup1.date + delta,
comment="Testing followup time spent 2", title="Testing followup 2",
public=True, comment="Testing followup time spent 2",
user=self.user, public=True,
new_status=1, user=self.user,
message_id=uuid.uuid4().hex, new_status=1,
time_spent=None message_id=uuid.uuid4().hex,
) time_spent=None
followup2.save() )
followup2.save()
# we have a special case with the last second of the day being added if day ends at 23:59:59 self.assertEqual(followup2.time_spent.total_seconds(), delta.total_seconds())
day_overlap = followup2.date.toordinal() - followup1.date.toordinal() self.assertEqual(ticket.time_spent.total_seconds(), assertion_delta.total_seconds() + delta.total_seconds())
hour_delta = hour_delta - timedelta(seconds=1 * day_overlap)
self.assertEqual(followup2.time_spent.total_seconds(), hour_delta.total_seconds()) # delete second follow-up as we test it with many intervals
self.assertEqual(ticket.time_spent.total_seconds(), assertion_delta.total_seconds() + hour_delta.total_seconds()) followup2.delete()