def testMaintenanceWindows(self): m = MaintenanceWindow('tester') t = mktime( (2006, 1, 29, 10, 45, 12, 6, 29, 0) ) P = 60*60*2 # set(start, duration, repeat, enabled=True) m.set(t, P, m.NEVER) self.assert_(m.next() == None) m.set(t, P, m.DAILY) c = mktime( (2006, 1, 30, 10, 45, 12, 6, 29, 0) ) self.assert_(m.next(t + P + 1) == c) m.set(t, P, m.WEEKLY) c = mktime( (2006, 2, 5, 10, 45, 12, 6, 36, 0) ) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS, P, m.EVERY_WEEKDAY) c = mktime( (2006, 1, 30, 10, 45, 12, 7, 30, 0) ) self.assert_(m.next(t) == c) m.set(t, P, m.MONTHLY) c = mktime( (2006, 2, 28, 10, 45, 12, 0, 0, 0) ) self.assert_(m.next(t+1) == c) t2 = mktime( (2005, 12, 31, 10, 45, 12, 0, 0, 0) ) m.set(t2, P, m.MONTHLY) c = mktime( (2006, 1, 31, 10, 45, 12, 0, 0, 0) ) c2 = mktime( (2006, 2, 28, 10, 45, 12, 0, 0, 0) ) self.assert_(m.next(t2+1) == c) self.assert_(m.next(c+1) == c2) c = mktime( (2006, 2, 5, 10, 45, 12, 0, 0, 0) ) m.set(t, P, m.FSOTM) self.assert_(m.next(t+1) == c) # DST FSOTM_Map = { # DST day following first sunday of the month (2008, 3, 9): (2008, 4, 6), (2008, 11, 2): (2008, 12, 7), } for (yy, mm, dd), sunday in FSOTM_Map.items(): duration = 3*60 tt = mktime( (yy, mm, dd, 12, 10, 9, 0, 0, -1) ) m.set(tt, duration, m.DAILY) c = mktime( (yy, mm, dd + 1, 12, 10, 9, 0, 0, -1) ) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.WEEKLY) c = mktime( (yy, mm, dd + 7, 12, 10, 9, 0, 0, -1) ) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.EVERY_WEEKDAY) c = mktime( (yy, mm, dd + 1, 12, 10, 9, 0, 0, -1) ) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.FSOTM) c = mktime( sunday + (12, 10, 9, 0, 0, -1) ) self.assert_(m.next(tt + duration) == c) # DST: check that a 3-hour range ends at the proper time tt = mktime( (yy, mm, dd, 0, 10, 9, 0, 0, -1) ) m.set(tt, duration, m.DAILY) m.started = tt c = mktime( (yy, mm, dd, 3, 10, 8, 0, 0, -1) ) self.assert_(m.nextEvent(tt) == c) m.started = None # skips m.skip = 2 m.set(t, P, m.DAILY) c = mktime( (2006, 1, 31, 10, 45, 12, 6, 29, 0) ) self.assert_(m.next(t + 1) == c) m.set(t, P, m.WEEKLY) c = mktime( (2006, 2, 12, 10, 45, 12, 6, 36, 0) ) self.assert_(m.next(t + 1) == c) m.set(t, P, m.MONTHLY) c = mktime( (2006, 3, 29, 10, 45, 12, 6, 36, 0) ) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS * 2, P, m.EVERY_WEEKDAY) c = mktime( (2006, 1, 31, 10, 45, 12, 7, 30, 0) ) self.assert_(m.next(t + 1) == c) c = mktime( (2006, 3, 5, 10, 45, 12, 0, 0, 0) ) m.set(t, P, m.FSOTM) self.assert_(m.next(t+1) == c) m1 = MaintenanceWindow('t1') m2 = MaintenanceWindow('t2') t = mktime( (2006, 1, 29, 10, 45, 12, 6, 29, 0) ) duration = 1 m1.set(t, duration, m.NEVER) m2.set(t + duration * 60, duration, m.NEVER) m1.started = t # ending of m1 should be < start of m2 self.assert_(m1.nextEvent(t + 1) < m2.nextEvent(t + 1)) #r = FakeRequest() r = None m.manage_editMaintenanceWindow( startDate='01/29/2006', startHours='10', startMinutes='45', durationDays='1', durationHours='1', durationMinutes='1', repeat='Weekly', startProductionState=state_Maintenance, enabled=True, REQUEST=r) #self.assert_('message' in r) #self.assert_(r['message'] == 'Saved Changes') self.assert_(m.start == t - 12) self.assert_(m.duration == 24*60+61) self.assert_(m.repeat == 'Weekly') self.assert_(m.startProductionState == state_Maintenance)
def testMaintenanceWindows(self): m = MaintenanceWindow('tester') m.dmd = self.dmd t = mktime((2006, 1, 29, 10, 45, 12, 6, 29, 0)) P = 60 * 60 * 2 # set(start, duration, repeat, enabled=True) m.set(t, P, m.NEVER) self.assert_(m.next() == None) m.set(t, P, m.DAILY) c = mktime((2006, 1, 30, 10, 45, 12, 6, 29, 0)) self.assert_(m.next(t + P + 1) == c) m.set(t, P, m.WEEKLY) c = mktime((2006, 2, 5, 10, 45, 12, 6, 36, 0)) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS, P, m.EVERY_WEEKDAY) c = mktime((2006, 1, 30, 10, 45, 12, 7, 30, 0)) self.assert_(m.next(t) == c) m.set(t, P, m.MONTHLY) c = mktime((2006, 2, 28, 10, 45, 12, 0, 0, 0)) self.assert_(m.next(t + 1) == c) t2 = mktime((2005, 12, 31, 10, 45, 12, 0, 0, 0)) m.set(t2, P, m.MONTHLY) c = mktime((2006, 1, 31, 10, 45, 12, 0, 0, 0)) c2 = mktime((2006, 2, 28, 10, 45, 12, 0, 0, 0)) self.assert_(m.next(t2 + 1) == c) self.assert_(m.next(c + 1) == c2) c = mktime((2006, 2, 5, 10, 45, 12, 0, 0, 0)) m.set(t, P, m.NTHWDAY) self.assert_(m.next(t + 1) == c) c = mktime((2006, 1, 31, 10, 45, 12, 0, 0, 0)) m.set(t, P, m.NTHWDAY, 'Tuesday', 'Last') self.assert_(m.next(t + 1) == c) c = mktime((2006, 2, 19, 10, 45, 12, 0, 0, 0)) m.set(t, P, m.NTHWDAY, 'Sunday', '3rd') self.assert_(m.next(t + 1) == c) c = mktime((2006, 2, 22, 10, 45, 12, 0, 0, 0)) m.set(t, P, m.NTHWDAY, 'Wednesday', 'Last') self.assert_(m.next(t + 1) == c) # DST FSOTM_Map = { # DST day following first sunday of the month (2008, 3, 9): (2008, 4, 6), (2008, 11, 2): (2008, 12, 7), } for (yy, mm, dd), sunday in FSOTM_Map.items(): duration = 3 * 60 tt = mktime((yy, mm, dd, 12, 10, 9, 0, 0, -1)) m.set(tt, duration, m.DAILY) c = mktime((yy, mm, dd + 1, 12, 10, 9, 0, 0, -1)) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.WEEKLY) c = mktime((yy, mm, dd + 7, 12, 10, 9, 0, 0, -1)) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.EVERY_WEEKDAY) c = mktime((yy, mm, dd + 1, 12, 10, 9, 0, 0, -1)) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.NTHWDAY) c = mktime(sunday + (12, 10, 9, 0, 0, -1)) self.assert_(m.next(tt + duration) == c) # DST: check that a 3-hour range ends at the proper time tt = mktime((yy, mm, dd, 0, 10, 9, 0, 0, -1)) m.set(tt, duration, m.DAILY) m.started = tt c = mktime((yy, mm, dd, 3, 10, 8, 0, 0, -1)) self.assert_(m.nextEvent(tt) == c) m.started = None # skips m.skip = 2 m.set(t, P, m.DAILY) c = mktime((2006, 1, 31, 10, 45, 12, 6, 29, 0)) self.assert_(m.next(t + 1) == c) m.set(t, P, m.WEEKLY) c = mktime((2006, 2, 12, 10, 45, 12, 6, 36, 0)) self.assert_(m.next(t + 1) == c) m.set(t, P, m.MONTHLY) c = mktime((2006, 3, 29, 9, 45, 12, 6, 36, 0)) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS * 2, P, m.EVERY_WEEKDAY) c = mktime((2006, 1, 31, 10, 45, 12, 7, 30, 0)) self.assert_(m.next(t + 1) == c) c = mktime((2006, 3, 5, 10, 45, 12, 0, 0, 0)) m.set(t, P, m.NTHWDAY) self.assert_(m.next(t + 1) == c) m1 = MaintenanceWindow('t1') m2 = MaintenanceWindow('t2') t = mktime((2006, 1, 29, 10, 45, 12, 6, 29, 0)) duration = 1 m1.set(t, duration, m.NEVER) m2.set(t + duration * 60, duration, m.NEVER) m1.started = t # ending of m1 should be < start of m2 self.assert_(m1.nextEvent(t + 1) < m2.nextEvent(t + 1)) #r = FakeRequest() r = None m.manage_editMaintenanceWindow(startDate='01/29/2006', startHours='10', startMinutes='45', durationDays='1', durationHours='1', durationMinutes='1', repeat='Weekly', startProductionState=state_Maintenance, enabled=True, REQUEST=r) #self.assert_('message' in r) #self.assert_(r['message'] == 'Saved Changes') self.assert_(m.start == t - 12) self.assert_(m.duration == 24 * 60 + 61) self.assert_(m.repeat == 'Weekly') self.assert_(m.startProductionState == state_Maintenance)
def testUTCMaintenanceWindows(self): m = MaintenanceWindow('tester') m.dmd = self.dmd tzInstance = tz.tzutc() def getLocalizedTimestamp(year, month, day, hour, minutes, seconds): localizedExpectedDateTime = datetime(year, month, day, hour, minutes, seconds, tzinfo=tzInstance) return Time.awareDatetimeToTimestamp(localizedExpectedDateTime) t = getLocalizedTimestamp(2006, 1, 29, 10, 45, 12) P = 60 * 60 * 2 # set(start, duration, repeat, enabled=True) m.set(t, P, m.NEVER) self.assert_(m.next() == None) m.set(t, P, m.DAILY) c = getLocalizedTimestamp(2006, 1, 30, 10, 45, 12) self.assert_(m.next(t + P + 1) == c) m.set(t, P, m.WEEKLY) c = getLocalizedTimestamp(2006, 2, 5, 10, 45, 12) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS, P, m.EVERY_WEEKDAY) c = getLocalizedTimestamp(2006, 1, 30, 10, 45, 12) self.assert_(m.next(t) == c) m.set(t, P, m.MONTHLY) c = getLocalizedTimestamp(2006, 2, 28, 10, 45, 12) self.assert_(m.next(t + 1) == c) t2 = getLocalizedTimestamp(2005, 12, 31, 10, 45, 12) m.set(t2, P, m.MONTHLY) c = getLocalizedTimestamp(2006, 1, 31, 10, 45, 12) c2 = getLocalizedTimestamp(2006, 2, 28, 10, 45, 12) self.assert_(m.next(t2 + 1) == c) self.assert_(m.next(c + 1) == c2) c = getLocalizedTimestamp(2006, 2, 5, 10, 45, 12) m.set(t, P, m.NTHWDAY) self.assert_(m.next(t + 1) == c) c = getLocalizedTimestamp(2006, 1, 31, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Tuesday', 'Last') self.assert_(m.next(t + 1) == c) c = getLocalizedTimestamp(2006, 2, 19, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Sunday', '3rd') self.assert_(m.next(t + 1) == c) c = getLocalizedTimestamp(2006, 2, 22, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Wednesday', 'Last') self.assert_(m.next(t + 1) == c) c = getLocalizedTimestamp(2006, 3, 13, 10, 45, 12) n = getLocalizedTimestamp(2006, 3, 6, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Monday', '2nd') self.assert_(m.next(n) == c) c = getLocalizedTimestamp(2006, 3, 29, 10, 45, 12) n = getLocalizedTimestamp(2006, 3, 6, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Wednesday', 'Last') self.assert_(m.next(n) == c) c = getLocalizedTimestamp(2007, 1, 8, 10, 45, 12) n = getLocalizedTimestamp(2007, 1, 2, 10, 45, 12) m.set(t, P, m.NTHWDAY, 'Monday', '2nd') self.assert_(m.next(n) == c) # DST FSOTM_Map = { # DST day following first sunday of the month (2008, 3, 9): datetime(2008, 4, 6), (2008, 11, 2): datetime(2008, 12, 7), } for (yy, mm, dd), sunday in FSOTM_Map.items(): duration = 3 * 60 tt = getLocalizedTimestamp(yy, mm, dd, 12, 10, 9) m.set(tt, duration, m.DAILY) c = getLocalizedTimestamp(yy, mm, dd + 1, 12, 10, 9) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.WEEKLY) c = getLocalizedTimestamp(yy, mm, dd + 7, 12, 10, 9) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.EVERY_WEEKDAY) c = getLocalizedTimestamp(yy, mm, dd + 1, 12, 10, 9) self.assert_(m.next(tt + duration) == c) m.set(tt, duration, m.NTHWDAY) date = sunday + timedelta(hours=12, minutes=10, seconds=9) c = getLocalizedTimestamp(date.year, date.month, date.day, date.hour, date.minute, date.second) self.assert_(m.next(tt + duration) == c) # DST: check that a 3-hour range ends at the proper time tt = getLocalizedTimestamp(yy, mm, dd, 0, 10, 9) m.set(tt, duration, m.DAILY) m.started = tt c = getLocalizedTimestamp(yy, mm, dd, 3, 10, 8) self.assert_(m.nextEvent(tt) == c) m.started = None # skips m.skip = 2 m.set(t, P, m.DAILY) c = getLocalizedTimestamp(2006, 1, 31, 10, 45, 12) self.assert_(m.next(t + 1) == c) m.set(t, P, m.WEEKLY) c = getLocalizedTimestamp(2006, 2, 12, 10, 45, 12) self.assert_(m.next(t + 1) == c) m.set(t, P, m.MONTHLY) c = getLocalizedTimestamp(2006, 3, 29, 10, 45, 12) self.assert_(m.next(t + 1) == c) m.set(t - DAY_SECONDS * 2, P, m.EVERY_WEEKDAY) c = getLocalizedTimestamp(2006, 1, 31, 10, 45, 12) self.assert_(m.next(t + 1) == c) c = getLocalizedTimestamp(2006, 3, 5, 10, 45, 12) m.set(t, P, m.NTHWDAY) self.assert_(m.next(t + 1) == c) m1 = MaintenanceWindow('t1') m2 = MaintenanceWindow('t2') t = getLocalizedTimestamp(2006, 1, 29, 10, 45, 12) duration = 1 m1.set(t, duration, m.NEVER) m2.set(t + duration * 60, duration, m.NEVER) m1.started = t # ending of m1 should be < start of m2 self.assert_(m1.nextEvent(t + 1) < m2.nextEvent(t + 1)) #r = FakeRequest() r = None startDttm = 1138531500 m.manage_editMaintenanceWindow(startDate='01/29/2006', startHours='10', startMinutes='45', startDateTime=str(startDttm), durationDays='1', durationHours='1', durationMinutes='1', repeat='Weekly', startProductionState=state_Maintenance, enabled=True, REQUEST=r) #self.assert_('message' in r) #self.assert_(r['message'] == 'Saved Changes') self.assertEqual(m.start, startDttm) self.assert_(m.duration == 24 * 60 + 61) self.assert_(m.repeat == 'Weekly') self.assert_(m.startProductionState == state_Maintenance)