def test_previous_overlaps(self): """Test that we handle overlap checks involving editing previous slots correctly.""" block1 = ScheduleBlock.objects.create( start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 19, 0, 0, tzinfo=timezone.utc)) slot1 = Slot(start_time=D.datetime(2013, 9, 26, 10, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 12, 0, 0, tzinfo=timezone.utc)) slot1.clean() slot1.save() slot2 = Slot(previous_slot=slot1, end_time=D.datetime(2013, 9, 26, 13, 0, 0, tzinfo=timezone.utc)) slot2.clean() slot2.save() # Check that updating slot1's end_time to 12:30 works as expected slot1.end_time = D.datetime(2013, 9, 26, 12, 30, 0, tzinfo=timezone.utc) slot1.clean() slot1.save() self.assertEqual( slot2.get_start_time(), D.datetime(2013, 9, 26, 12, 30, 0, tzinfo=timezone.utc)) # Check that updating slot1's end_time to 13:30 fails, though slot1.end_time = D.datetime(2013, 9, 26, 13, 30, 0, tzinfo=timezone.utc) self.assertRaises(ValidationError, slot1.clean)
def test_changing_slots(self): """Test that we can update slots and get the correct validation behaviour.""" block1 = ScheduleBlock.objects.create( start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 19, 0, 0, tzinfo=timezone.utc)) slot1 = Slot(start_time=D.datetime(2013, 9, 26, 10, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 12, 0, 0, tzinfo=timezone.utc)) slot1.clean() slot1.save() # This should work slot1.start_time = D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc) slot1.clean() slot1.save() slot1.end_time = D.datetime(2013, 9, 26, 11, 0, 0, tzinfo=timezone.utc) slot1.clean() slot1.save() # This should fail slot1.start_time = D.datetime(2013, 9, 26, 12, 0, 0, tzinfo=timezone.utc) self.assertRaises(ValidationError, slot1.clean) slot1.delete() block1.delete()
def test_overlapping_slots(self): """Test that we can't create overlapping slots.""" block1 = ScheduleBlock.objects.create( start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 19, 0, 0, tzinfo=timezone.utc)) slot1 = Slot(start_time=D.datetime(2013, 9, 26, 10, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 12, 0, 0, tzinfo=timezone.utc)) slot1.clean() slot1.save() # Start time is in the middle of slot1 slot2 = Slot(start_time=D.datetime(2013, 9, 26, 11, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 13, 0, 0, tzinfo=timezone.utc)) self.assertRaises(ValidationError, slot2.clean) # End time is in the middle of slot2 slot2 = Slot(start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 11, 0, 0, tzinfo=timezone.utc)) self.assertRaises(ValidationError, slot2.clean) # Slot 2 totally encloses slot 1 slot2 = Slot(start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 13, 0, 0, tzinfo=timezone.utc)) self.assertRaises(ValidationError, slot2.clean) # Slot 2 totally included in slot 1 slot2 = Slot(start_time=D.datetime(2013, 9, 26, 11, 30, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 12, 30, 0, tzinfo=timezone.utc)) self.assertRaises(ValidationError, slot2.clean) # Slot 2 has the same times as slot 1 slot2 = Slot(start_time=D.datetime(2013, 9, 26, 11, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 13, 0, 0, tzinfo=timezone.utc)) self.assertRaises(ValidationError, slot2.clean) # Check we don't raise errors on slots that touch as intended # slot 1 start time is slot 2's end time slot2 = Slot(start_time=D.datetime(2013, 9, 26, 9, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 10, 0, 0, tzinfo=timezone.utc)) slot2.clean() slot2.save() # slot 1 end time is slot 2's start time slot3 = Slot(start_time=D.datetime(2013, 9, 26, 12, 0, 0, tzinfo=timezone.utc), end_time=D.datetime(2013, 9, 26, 13, 0, 0, tzinfo=timezone.utc)) slot3.clean() slot1.delete() slot2.delete() block1.delete()