@@ -432,71 +432,72 @@ def setUp(self):
432
432
self .wh2 = WorkingHours .objects .create (staff_member = self .staff_member1 , day_of_week = 3 ,
433
433
start_time = datetime .time (9 , 0 ), end_time = datetime .time (17 , 0 ))
434
434
# 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 )
437
443
Config .objects .create (slot_duration = 60 , lead_time = datetime .time (9 , 0 ), finish_time = datetime .time (17 , 0 ),
438
444
appointment_buffer_time = 0 )
439
445
440
446
def test_day_off (self ):
441
447
"""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 )
444
448
# 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 )
446
450
self .assertEqual (slots , [])
447
451
448
452
def test_staff_does_not_work (self ):
449
453
"""Test if a staff member who doesn't work on a given day is handled correctly when getting available slots."""
450
454
# For next week, the staff member works only on Monday and Wednesday, but puts a day off on Monday
451
455
# 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 )
453
457
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 )
455
459
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 )
457
461
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 )
459
463
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 )
461
465
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 )
463
467
self .assertEqual (slots , [])
464
468
465
469
def test_available_slots (self ):
466
470
"""Test if available slots are returned correctly."""
467
471
# 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 )
470
473
expected_slots = [f"{ hour :02d} :00 AM" for hour in range (9 , 12 )] + ["12:00 PM" ] + \
471
474
[f"{ hour :02d} :00 PM" for hour in range (1 , 5 )]
472
475
self .assertEqual (slots , expected_slots )
473
476
474
477
def test_booked_slots (self ):
475
478
"""On a given day, if a staff member has an appointment, that time slot should not be available."""
476
479
# Let's book a slot for the staff member on next Wednesday
477
- appt_date = get_next_weekday (self .today , 2 )
478
480
start_time = datetime .time (10 , 0 )
479
481
end_time = datetime .time (11 , 0 )
480
482
481
483
# Create an appointment request for that time
482
484
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 )
484
486
# Create an appointment using that request
485
487
self .create_appointment_ (user = self .client1 , appointment_request = appt_request )
486
488
487
489
# 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 )
489
491
expected_slots = ['09:00 AM' , '11:00 AM' , '12:00 PM' , '01:00 PM' , '02:00 PM' , '03:00 PM' , '04:00 PM' ]
490
492
self .assertEqual (slots , expected_slots )
491
493
492
494
def test_no_working_hours (self ):
493
495
"""If a staff member doesn't have working hours on a given day, no slots should be available."""
494
496
# Let's ask for slots on a Thursday, which the staff member doesn't work
495
- date = get_next_weekday (self .today , 3 )
496
497
# Let's remove the config object also since it may contain default working days
497
498
Config .objects .all ().delete ()
498
499
# 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 )
500
501
self .assertEqual (slots , [])
501
502
502
503
0 commit comments