Skip to content

Commit d069d49

Browse files
committed
Fixed tests
1 parent 1cf9d05 commit d069d49

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

appointment/tests/test_services.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -432,71 +432,72 @@ def setUp(self):
432432
self.wh2 = WorkingHours.objects.create(staff_member=self.staff_member1, day_of_week=3,
433433
start_time=datetime.time(9, 0), end_time=datetime.time(17, 0))
434434
# But decides to take a day off next Monday
435-
DayOff.objects.create(staff_member=self.staff_member1, start_date=get_next_weekday(self.today, 0),
436-
end_date=get_next_weekday(self.today, 1))
435+
self.next_monday = get_next_weekday(self.today, 0)
436+
self.next_tuesday = get_next_weekday(self.today, 1)
437+
self.next_wednesday = get_next_weekday(self.today, 2)
438+
self.next_thursday = get_next_weekday(self.today, 3)
439+
self.next_friday = get_next_weekday(self.today, 4)
440+
self.next_saturday = get_next_weekday(self.today, 5)
441+
self.next_sunday = get_next_weekday(self.today, 6)
442+
DayOff.objects.create(staff_member=self.staff_member1, start_date=self.next_monday, end_date=self.next_monday)
437443
Config.objects.create(slot_duration=60, lead_time=datetime.time(9, 0), finish_time=datetime.time(17, 0),
438444
appointment_buffer_time=0)
439445

440446
def test_day_off(self):
441447
"""Test if a day off is handled correctly when getting available slots."""
442-
# Get a day in the future that is a Monday (for python weekday: 0 = Monday)
443-
date = get_next_weekday(datetime.datetime.today(), 0)
444448
# Ask for slots for it, and it should return an empty list since next Monday is a day off
445-
slots = get_available_slots_for_staff(date, self.staff_member1)
449+
slots = get_available_slots_for_staff(self.next_monday, self.staff_member1)
446450
self.assertEqual(slots, [])
447451

448452
def test_staff_does_not_work(self):
449453
"""Test if a staff member who doesn't work on a given day is handled correctly when getting available slots."""
450454
# For next week, the staff member works only on Monday and Wednesday, but puts a day off on Monday
451455
# So the staff member should not have any available slots except for Wednesday, which is day #2 (python weekday)
452-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 1), self.staff_member1)
456+
slots = get_available_slots_for_staff(self.next_monday, self.staff_member1)
453457
self.assertEqual(slots, [])
454-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 3), self.staff_member1)
458+
slots = get_available_slots_for_staff(self.next_tuesday, self.staff_member1)
455459
self.assertEqual(slots, [])
456-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 4), self.staff_member1)
460+
slots = get_available_slots_for_staff(self.next_thursday, self.staff_member1)
457461
self.assertEqual(slots, [])
458-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 5), self.staff_member1)
462+
slots = get_available_slots_for_staff(self.next_friday, self.staff_member1)
459463
self.assertEqual(slots, [])
460-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 6), self.staff_member1)
464+
slots = get_available_slots_for_staff(self.next_saturday, self.staff_member1)
461465
self.assertEqual(slots, [])
462-
slots = get_available_slots_for_staff(get_next_weekday(self.today, 0), self.staff_member1)
466+
slots = get_available_slots_for_staff(self.next_sunday, self.staff_member1)
463467
self.assertEqual(slots, [])
464468

465469
def test_available_slots(self):
466470
"""Test if available slots are returned correctly."""
467471
# On a Wednesday, the staff member should have slots from 9 AM to 5 PM
468-
date = get_next_weekday(self.today, 2)
469-
slots = get_available_slots_for_staff(date, self.staff_member1)
472+
slots = get_available_slots_for_staff(self.next_wednesday, self.staff_member1)
470473
expected_slots = [f"{hour:02d}:00 AM" for hour in range(9, 12)] + ["12:00 PM"] + \
471474
[f"{hour:02d}:00 PM" for hour in range(1, 5)]
472475
self.assertEqual(slots, expected_slots)
473476

474477
def test_booked_slots(self):
475478
"""On a given day, if a staff member has an appointment, that time slot should not be available."""
476479
# Let's book a slot for the staff member on next Wednesday
477-
appt_date = get_next_weekday(self.today, 2)
478480
start_time = datetime.time(10, 0)
479481
end_time = datetime.time(11, 0)
480482

481483
# Create an appointment request for that time
482484
appt_request = self.create_appointment_request_(service=self.service1, staff_member=self.staff_member1,
483-
date_=appt_date, start_time=start_time, end_time=end_time)
485+
date_=self.next_wednesday, start_time=start_time, end_time=end_time)
484486
# Create an appointment using that request
485487
self.create_appointment_(user=self.client1, appointment_request=appt_request)
486488

487489
# Now, the staff member should not have that slot available
488-
slots = get_available_slots_for_staff(appt_date, self.staff_member1)
490+
slots = get_available_slots_for_staff(self.next_wednesday, self.staff_member1)
489491
expected_slots = ['09:00 AM', '11:00 AM', '12:00 PM', '01:00 PM', '02:00 PM', '03:00 PM', '04:00 PM']
490492
self.assertEqual(slots, expected_slots)
491493

492494
def test_no_working_hours(self):
493495
"""If a staff member doesn't have working hours on a given day, no slots should be available."""
494496
# Let's ask for slots on a Thursday, which the staff member doesn't work
495-
date = get_next_weekday(self.today, 3)
496497
# Let's remove the config object also since it may contain default working days
497498
Config.objects.all().delete()
498499
# Now no slots should be available
499-
slots = get_available_slots_for_staff(date, self.staff_member1)
500+
slots = get_available_slots_for_staff(self.next_thursday, self.staff_member1)
500501
self.assertEqual(slots, [])
501502

502503

0 commit comments

Comments
 (0)