Skip to content

Commit

Permalink
fix old tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Jun 7, 2024
1 parent e623939 commit 5496708
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
27 changes: 15 additions & 12 deletions backend/samfundet/models/recruitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ def generate_interviewhours(
location: str,
interview_duration_minutes: int = 30,
) -> None:
interview_duration = timezone.timedelta(minutes=interview_duration_minutes)
# Very naive method, just fetches first user that is available
interview_duration = timezone.timedelta(minutes=interview_duration_minutes)
without_interview = RecruitmentAdmission.objects.filter(interview=None)
times_gone = 0
current_dt = start_dt
new_interviews = []
while current_dt < end_dt:
for admission in without_interview:
available = True
# Check if user is unavailable at that time
for occupied_time in Occupiedtimeslot.objects.filter(user=admission.user, recruitment=admission.recruitment).order_by('start_dt'):
if (
occupied_time.start_dt <= current_dt <= occupied_time.end_dt
Expand All @@ -156,17 +156,20 @@ def generate_interviewhours(
):
available = False
break
for other_interview in Interview.objects.filter(
id__in=RecruitmentAdmission.objects.filter(user=admission.user, recruitment=admission.recruitment)
.exclude(interview=None)
.values_list('interview')
):
if (current_dt <= other_interview.interview_time <= current_dt + interview_duration) or (
other_interview.interview_time <= current_dt <= other_interview.interview_time + interview_duration
# Check other interviewtimes
if available:
for other_interview in Interview.objects.filter(
id__in=RecruitmentAdmission.objects.filter(user=admission.user, recruitment=admission.recruitment)
.exclude(interview=None)
.values_list('interview')
):
available = False
break
if (current_dt <= other_interview.interview_time <= current_dt + interview_duration) or (
other_interview.interview_time <= current_dt <= other_interview.interview_time + interview_duration
):
available = False
break
if available:
# If available, set interview time
interview = Interview(interview_time=current_dt.replace(second=0), interview_location=location)
interview.save()
admission.interview = interview
Expand All @@ -176,7 +179,7 @@ def generate_interviewhours(
break
if len(without_interview) == 0:
break
times_gone += 1

current_dt += interview_duration
return RecruitmentAdmission.objects.filter(id__in=new_interviews)

Expand Down
2 changes: 1 addition & 1 deletion backend/samfundet/models/tests/test_recruitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_generate_interviews_occupied_due_to_interview(
):
assert fixture_recruitment_admission.interview is None
assert fixture_recruitment_admission2.interview is None

assert fixture_recruitment_admission2.recruitment_position != fixture_recruitment_admission.recruitment_position
# Generate the first interview, other does not generate
location_name = 'Mujaffas BMW'
fixture_recruitment_admission.recruitment_position.generate_interviewhours(
Expand Down
6 changes: 4 additions & 2 deletions backend/samfundet/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
InformationPage,
)
from samfundet.models.recruitment import (
Interview,
Recruitment,
RecruitmentPosition,
RecruitmentAdmission,
Expand Down Expand Up @@ -847,8 +848,9 @@ def test_get_applicants_without_interviews_when_interview_is_set(
url = reverse(routes.samfundet__applicants_without_interviews)

# Setting the interview time for the user's admission
fixture_recruitment_admission.interview.interview_time = timezone.now()
fixture_recruitment_admission.interview.save()
interview = Interview.objects.create(interview_time=timezone.now(), interview_location='Baghdad')
interview.save()
fixture_recruitment_admission.interview = interview
fixture_recruitment_admission.save()

### Act ###
Expand Down

0 comments on commit 5496708

Please sign in to comment.