示例#1
0
    def test_save_model_change_slot(self):
        """Test save_model changing a slot"""
        slot = Slot(start_time=D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc),
                    end_time=D.datetime(2013, 9, 22, 12, 30, 0, tzinfo=timezone.utc))
        # end_time is chosen as 12:30 so it stays valid through all the
        # subsequent fiddling
        slot.save()
        # check that it's saved in the database
        self.assertEqual(Slot.objects.count(), 1)
        request = HttpRequest()
        dummy = make_dummy_form(0)
        slot.start_time = D.datetime(2013, 9, 22, 12, 0, 0, tzinfo=timezone.utc)
        self.assertEqual(
            Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)).count(), 1)
        self.admin.save_model(request, slot, dummy, True)
        # Check that the database has changed
        self.assertEqual(
            Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)).count(), 0)
        self.assertEqual(Slot.objects.count(), 1)
        slot2 = Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 12, 0, 0, tzinfo=timezone.utc)).get()
        self.assertEqual(slot, slot2)

        # Check that setting additional has no influence on the change path
        dummy = make_dummy_form(3)
        slot.start_time = D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)
        self.assertEqual(
            Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)).count(), 0)
        self.admin.save_model(request, slot, dummy, True)
        # Still only 1 object
        self.assertEqual(Slot.objects.count(), 1)
        # And it has been updated
        self.assertEqual(
            Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 12, 0, 0, tzinfo=timezone.utc)).count(), 0)
        self.assertEqual(
            Slot.objects.filter(start_time=D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)).count(), 1)
示例#2
0
    def test_save_model_change_slot(self):
        """Test save_model changing a slot"""
        slot = Slot(day=self.day, start_time=D.time(11, 0, 0), end_time=D.time(12, 30, 0))
        # end_time is chosen as 12:30 so it stays valid through all the
        # subsequent fiddling
        slot.save()
        # check that it's saved in the database
        self.assertEqual(Slot.objects.count(), 1)
        request = HttpRequest()
        dummy = make_dummy_form(0)
        slot.start_time = D.time(12, 0, 0)
        self.assertEqual(Slot.objects.filter(start_time=D.time(11, 0, 0)).count(), 1)
        self.admin.save_model(request, slot, dummy, True)
        # Check that the database has changed
        self.assertEqual(Slot.objects.filter(start_time=D.time(11, 0, 0)).count(), 0)
        self.assertEqual(Slot.objects.count(), 1)
        slot2 = Slot.objects.filter(start_time=D.time(12, 0, 0)).get()
        self.assertEqual(slot, slot2)

        # Check that setting additional has no influence on the change path
        dummy = make_dummy_form(3)
        slot.start_time = D.time(11, 0, 0)
        self.assertEqual(Slot.objects.filter(start_time=D.time(11, 0, 0)).count(), 0)
        self.admin.save_model(request, slot, dummy, True)
        # Still only 1 object
        self.assertEqual(Slot.objects.count(), 1)
        # And it has been updated
        self.assertEqual(Slot.objects.filter(start_time=D.time(12, 0, 0)).count(), 0)
        self.assertEqual(Slot.objects.filter(start_time=D.time(11, 0, 0)).count(), 1)
示例#3
0
 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()