def test_clash(self): """ If we create a one-off occurrence that clashes * event + start-time is unique, so it must be added as an exception first. * the one-off occurrence shouldn't be generated. """ generator_fixture(self) # Check there is an auto occurrence clashingtime = datetime(2010, 1, 8, 10, 30) auto_occs = self.bin_night.occurrences.filter(start=clashingtime) self.ae(auto_occs.count(), 1) self.assertTrue(auto_occs[0].generated_by is not None) # we can't add another occurrence with a clashing start time. self.assertRaises(IntegrityError, self.bin_night.occurrences.create, start=clashingtime) # let's add the Exclusions self.exclusion = self.bin_night.exclusions.create(start=clashingtime) # now we should have a manual occurrence oneoff_occ = self.bin_night.occurrences.get(start=clashingtime) self.assertTrue(oneoff_occ.generated_by is None) # let's delete it: oneoff_occ.delete() # and now it's OK to create a one-off one: self.bin_night.occurrences.create(start=clashingtime) # and if we remove the Exclusion, the generators don't try to generate # anything clashing with the one-off occurrence self.exclusion.delete() self.weekly_generator.save() self.endless_generator.save() oneoff_occs = self.bin_night.occurrences.filter(start=clashingtime) self.ae(oneoff_occs.count(), 1) self.assertTrue(oneoff_occs[0].generated_by is None)
def test_generation_then_exclusion(self): """ If an Exclusion is saved, then: * Generated Occurrences that should be excluded are converted to one-off. * Re-generating from generators will not re-generate that occurrence. """ generator_fixture(self) clashingtime = datetime(2010, 1, 8, 10, 30) # Check we're starting the occurrence with a generator self.existing_occurrence = self.bin_night.occurrences.get( start=clashingtime) self.existing_occurrence_id = self.existing_occurrence.id self.assertTrue(self.existing_occurrence.generated_by is not None) #exclude the second occurrence of the weekly_ and endless_generators. self.exclusion = self.bin_night.exclusions.create(start=clashingtime) # Assert that the clashing occurrence has the same ID, but # now has no generator (ie is one-off) self.existing_occurrence = self.bin_night.occurrences.get( start=clashingtime) self.ae(self.existing_occurrence_id, self.existing_occurrence.id) self.assertTrue(self.existing_occurrence.generated_by is None) # delete the clashing occurrence self.existing_occurrence.delete() # Let's re-save the generators self.weekly_generator.save() self.dupe_weekly_generator.save() # no excluded occurrence is (re)generated self.ae( self.bin_night.occurrences.filter(start=clashingtime).count(), 0)
def setUp(self): super(TestGenerators, self).setUp() generator_fixture(self)