def test_purgeOldEvents(self): # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, None, DateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, debug=True )) self.assertEquals(total, 13) # Actually remove total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, None, DateTime(now, 4, 1, 0, 0, 0), 2, debug=True )) self.assertEquals(total, 13) # There should be no more left total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, None, DateTime(now, 4, 1, 0, 0, 0), 2, debug=True )) self.assertEquals(total, 0)
def test_purgeOldEvents(self): # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, PyCalendarDateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, verbose=False )) self.assertEquals(total, 13) # Actually remove total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, PyCalendarDateTime(now, 4, 1, 0, 0, 0), 2, verbose=False )) self.assertEquals(total, 13) # There should be no more left total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, PyCalendarDateTime(now, 4, 1, 0, 0, 0), 2, verbose=False )) self.assertEquals(total, 0)
def test_purgeOldEvents_home_filtering(self): # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "ho", DateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, debug=True )) self.assertEquals(total, 13) # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "home", DateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, debug=True )) self.assertEquals(total, 13) # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "home1", DateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, debug=True )) self.assertEquals(total, 5) # Dry run total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "home2", DateTime(now, 4, 1, 0, 0, 0), 2, dryrun=True, debug=True )) self.assertEquals(total, 8)
def command_purgeOldEvents(self, command): """ Convert RetainDays from the command dictionary into a date, then purge events older than that date. @param command: the dictionary parsed from the plist read from stdin @type command: C{dict} """ retainDays = command.get("RetainDays", DEFAULT_RETAIN_DAYS) cutoff = PyCalendarDateTime.getToday() cutoff.setDateOnly(False) cutoff.offsetDay(-retainDays) eventCount = (yield PurgeOldEventsService.purgeOldEvents(self.store, cutoff, DEFAULT_BATCH_SIZE)) self.respond(command, {'EventsRemoved' : eventCount, "RetainDays" : retainDays})
def command_purgeOldEvents(self, command): """ Convert RetainDays from the command dictionary into a date, then purge events older than that date. @param command: the dictionary parsed from the plist read from stdin @type command: C{dict} """ retainDays = command.get("RetainDays", DEFAULT_RETAIN_DAYS) cutoff = DateTime.getToday() cutoff.setDateOnly(False) cutoff.offsetDay(-retainDays) eventCount = (yield PurgeOldEventsService.purgeOldEvents(self.store, cutoff, DEFAULT_BATCH_SIZE)) self.respond(command, {'EventsRemoved': eventCount, "RetainDays": retainDays})
def test_purgeOldEvents_old_cutoff(self): # Dry run cutoff = DateTime.getToday() cutoff.setDateOnly(False) cutoff.offsetDay(-400) total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "ho", cutoff, 2, dryrun=True, debug=True )) self.assertEquals(total, 12) # Actually remove total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, None, cutoff, 2, debug=True )) self.assertEquals(total, 12) total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, "ho", cutoff, 2, dryrun=True, debug=True )) self.assertEquals(total, 0)
def test_purgeAttachmentsWithoutCutoffWithPurgeOld(self): """ L{PurgeAttachmentsService.purgeAttachments} purges only orphaned attachments, not current ones. """ home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota1 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertEqual(quota1, 0) (yield self._addAttachment("home1", "calendar1", "oldattachment1.ics", "att1")) (yield self._addAttachment("home1", "calendar1", "oldattachment2.ics", "att2.1")) (yield self._addAttachment("home1", "calendar1", "oldattachment2.ics", "att2.2")) (yield self._addAttachment("home1", "calendar1", "currentattachment3.ics", "att3")) (yield self._addAttachment("home2", "calendar2", "oldattachment1.ics", "att4")) (yield self._addAttachment("home2", "calendar2", "currentattachment2.ics", "att5")) (yield self._addAttachment("home2", "calendar2", "oldattachment3.ics", "att6")) (yield self._addAttachment("home2", "calendar2", "oldattachment4.ics", "att7")) (yield self._orphanAttachment("home1", "calendar1", "oldattachment1.ics")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment1.ics", "matt1")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment2.ics", "matt2.1")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment2.ics", "matt2.2")) (yield self._addManagedAttachment("home1", "calendar1", "currentmattachment3.ics", "matt3")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment1.ics", "matt4")) (yield self._addManagedAttachment("home2", "calendar2", "currentmattachment2.ics", "matt5")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment3.ics", "matt6")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment4.ics", "matt7")) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota2 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota2 > quota1) # Remove old events first total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, PyCalendarDateTime(now, 4, 1, 0, 0, 0), 2, verbose=False )) self.assertEquals(total, 13) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota3 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota3 < quota2) # Dry run total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=True, verbose=False)) self.assertEquals(total, 1) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota4 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota4 == quota3) # Actually remove total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=False, verbose=False)) self.assertEquals(total, 1) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota5 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota5 < quota4) # There should be no more left total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=False, verbose=False)) self.assertEquals(total, 0)
def test_purgeAttachmentsWithoutCutoffWithPurgeOld(self): """ L{PurgeAttachmentsService.purgeAttachments} purges only orphaned attachments, not current ones. """ home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota1 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertEqual(quota1, 0) (yield self._addAttachment("home1", "calendar1", "oldattachment1.ics", "att1")) (yield self._addAttachment("home1", "calendar1", "oldattachment2.ics", "att2.1")) (yield self._addAttachment("home1", "calendar1", "oldattachment2.ics", "att2.2")) (yield self._addAttachment("home1", "calendar1", "currentattachment3.ics", "att3")) (yield self._addAttachment("home2", "calendar2", "oldattachment1.ics", "att4")) (yield self._addAttachment("home2", "calendar2", "currentattachment2.ics", "att5")) (yield self._addAttachment("home2", "calendar2", "oldattachment3.ics", "att6")) (yield self._addAttachment("home2", "calendar2", "oldattachment4.ics", "att7")) (yield self._orphanAttachment("home1", "calendar1", "oldattachment1.ics")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment1.ics", "matt1")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment2.ics", "matt2.1")) (yield self._addManagedAttachment("home1", "calendar1", "oldmattachment2.ics", "matt2.2")) (yield self._addManagedAttachment("home1", "calendar1", "currentmattachment3.ics", "matt3")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment1.ics", "matt4")) (yield self._addManagedAttachment("home2", "calendar2", "currentmattachment2.ics", "matt5")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment3.ics", "matt6")) (yield self._addManagedAttachment("home2", "calendar2", "oldmattachment4.ics", "matt7")) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota2 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota2 > quota1) # Remove old events first total = (yield PurgeOldEventsService.purgeOldEvents( self._sqlCalendarStore, None, DateTime(now, 4, 1, 0, 0, 0), 2, debug=False )) self.assertEquals(total, 13) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota3 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota3 < quota2) # Dry run total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=True, verbose=False)) self.assertEquals(total, 1) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota4 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota4 == quota3) # Actually remove total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=False, verbose=False)) self.assertEquals(total, 1) home = (yield self.transactionUnderTest().calendarHomeWithUID("home1")) quota5 = (yield home.quotaUsedBytes()) (yield self.commit()) self.assertTrue(quota5 < quota4) # There should be no more left total = (yield PurgeAttachmentsService.purgeAttachments(self._sqlCalendarStore, None, 0, 2, dryrun=False, verbose=False)) self.assertEquals(total, 0)