-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test set for automatic time tracking of follow-ups #1164
Conversation
Hi guys, found some time for testing the time_spent calculation system. Helped me found a bug and fixed it inside this same PR. |
.. and thats why we love unit tests. 🥳 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new fearture and the unit test
followup1 = FollowUp.objects.create( | ||
ticket=ticket, | ||
date=fup_time_p, | ||
title="Testing followup", | ||
comment="Testing followup time spent", | ||
public=True, | ||
user=self.user, | ||
new_status=1, | ||
message_id=uuid.uuid4().hex, | ||
time_spent=None | ||
) | ||
followup1.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's mandatory to call save
to trigger time spent calculation, maybe you can only create Python object in order to save one SQL query:
followup1 = FollowUp.objects.create( | |
ticket=ticket, | |
date=fup_time_p, | |
title="Testing followup", | |
comment="Testing followup time spent", | |
public=True, | |
user=self.user, | |
new_status=1, | |
message_id=uuid.uuid4().hex, | |
time_spent=None | |
) | |
followup1.save() | |
followup1 = FollowUp( | |
ticket=ticket, | |
date=fup_time_p, | |
title="Testing followup", | |
comment="Testing followup time spent", | |
public=True, | |
user=self.user, | |
new_status=1, | |
message_id=uuid.uuid4().hex, | |
time_spent=None | |
) | |
followup1.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Benbb96 you are totally right.
I blindly copied the code from another test and the create method is enough.
https://github.com/django-helpdesk/django-helpdesk/blob/main/helpdesk/tests/test_time_spent.py#L40
# adding a second follow-up at different intervals | ||
for delta in (timedelta(seconds=1), timedelta(minutes=1), timedelta(hours=1), timedelta(days=1), timedelta(days=10)): | ||
|
||
followup2 = FollowUp.objects.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
@@ -230,8 +236,6 @@ def daily_time_spent_calculation(earliest, latest, open_hours): | |||
day_delta = latest - earliest | |||
|
|||
# returns up to 86399 seconds, add one second if full day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that comment still relevant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
ticket.save() | ||
|
||
fup_time_p = datetime.strptime(fup_time, "%Y-%m-%dT%H:%M:%S%z") | ||
followup1 = FollowUp.objects.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
ticket.save() | ||
|
||
fup_time_p = datetime.strptime('2024-03-10T00:00:00+00:00', "%Y-%m-%dT%H:%M:%S%z") | ||
followup1 = FollowUp.objects.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
ticket.save() | ||
|
||
fup_time_p = datetime.strptime('2024-03-10T00:00:00+00:00', "%Y-%m-%dT%H:%M:%S%z") | ||
followup1 = FollowUp.objects.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
title='test ticket', | ||
description='test ticket description') | ||
|
||
self.client = Client() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
I will clean the code with your great remarks soon.
Creating a set of tests for the time tracking features.