Skip to content
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

Merged
merged 16 commits into from
Mar 29, 2024

Conversation

samsplunks
Copy link
Contributor

@samsplunks samsplunks commented Feb 27, 2024

Creating a set of tests for the time tracking features.

@samsplunks samsplunks marked this pull request as draft February 27, 2024 10:00
@samsplunks samsplunks marked this pull request as ready for review March 27, 2024 16:24
@samsplunks
Copy link
Contributor Author

Hi guys, found some time for testing the time_spent calculation system.

Helped me found a bug and fixed it inside this same PR.

@uhurusurfa
Copy link
Collaborator

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. 🥳

Copy link
Collaborator

@uhurusurfa uhurusurfa left a 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

Comment on lines +64 to +75
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()
Copy link
Member

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:

Suggested change
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()

Copy link
Contributor Author

@samsplunks samsplunks Apr 2, 2024

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(
Copy link
Member

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
Copy link
Member

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 ?

Copy link
Contributor Author

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(
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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()
Copy link
Member

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

Copy link
Contributor Author

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.

@uhurusurfa uhurusurfa merged commit c9ca975 into django-helpdesk:main Mar 29, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants