def test_ok_split(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=False),
         TimeSlot(time=_make_time(11, 00), taken=False),
         TimeSlot(time=_make_time(11, 30), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=False),
         TimeSlot(time=_make_time(12, 30), taken=False),
     ]
     split = time_slot_utils.split_slots(time_slots)
     self.assertEqual(len(split), 1)
 def test_fits_same_time(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=True),
         TimeSlot(time=_make_time(11, 00), taken=False),
         TimeSlot(time=_make_time(11, 30), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=False),
         TimeSlot(time=_make_time(12, 30), taken=False),
     ]
     # max - 60 - 2+1 slots
     result = time_slot_utils.service_fits_into_slots(
         self.service, time_slots, datetime.time(hour=11, minute=30))
     self.assertTrue(result)
 def test_find_avaiable_slots_no_slots(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=False),
         TimeSlot(time=_make_time(11, 00), taken=True),
         TimeSlot(time=_make_time(11, 30), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=True),
         TimeSlot(time=_make_time(12, 30), taken=False),
     ]
     # TimeSlot.objects.bulk_create(time)
     # max - 60 - 2+1 slots
     result = time_slot_utils.find_available_starting_slots(
         self.service, time_slots)
     self.assertEqual(len(result), 0)
 def test_find_avaiable_slots_mid_day_slot(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=True),
         TimeSlot(time=_make_time(11, 00), taken=False),
         TimeSlot(time=_make_time(11, 30), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=False),
         TimeSlot(time=_make_time(12, 30), taken=True),
     ]
     # TimeSlot.objects.bulk_create(time)
     # max - 60 - 2+1 slots
     result = time_slot_utils.find_available_starting_slots(
         self.service, time_slots)
     self.assertEqual(len(result), 1)
     self.assertEqual(result[0].value, datetime.time(hour=11, minute=0))
 def test_split_two_groups(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=False),
         TimeSlot(time=_make_time(11, 00), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=False),
         TimeSlot(time=_make_time(12, 30), taken=False),
         TimeSlot(time=_make_time(13, 00), taken=False),
     ]
     split = time_slot_utils.split_slots(time_slots)
     self.assertEqual(len(split), 2)
     self.assertEqual(len(split[0]), 2)
     self.assertEqual(split[0][0].value, datetime.time(hour=10, minute=30))
     self.assertEqual(split[0][1].value, datetime.time(hour=11, minute=00))
     self.assertEqual(len(split[1]), 3)
     self.assertEqual(split[1][0].value, datetime.time(hour=12, minute=00))
     self.assertEqual(split[1][1].value, datetime.time(hour=12, minute=30))
     self.assertEqual(split[1][2].value, datetime.time(hour=13, minute=00))
 def test_fits_duration(self):
     time_slots = [
         TimeSlot(time=_make_time(10, 30), taken=True),
         TimeSlot(time=_make_time(11, 00), taken=False),
         TimeSlot(time=_make_time(11, 30), taken=False),
         TimeSlot(time=_make_time(12, 00), taken=False),
         TimeSlot(time=_make_time(12, 30), taken=False),
     ]
     # max - 60 - 2+1 slots
     time_from = datetime.time(hour=11, minute=30)
     duration = 2 * TimeSlot.DURATION
     result = time_slot_utils.duration_fits_into_slots(
         duration,
         time_slots,
         time_from=time_from,
         time_to=add_time(time_from, minutes=duration))
     self.assertTrue(result)