def testResumeBuilderWithInactivityAction(self): defaults = getDefaults() defaults.actions = [notifications.Inactivity(5)] tailer = LogTailer(defaults) resume = tailer.resumeBuilder() self.assertTrue( isinstance(resume.notifiers[0], notifications.Inactivity))
def testShouldGetInactivityNotificationTypeifInConfigFile(self): fh = open('config.txt', 'w') fh.write('inactivitynotification = mail\n') fh.close() property = Property('config.txt') property.parse_properties() notifier = notifications.Inactivity(1, property) self.assertEqual('mail', notifier.getNotificationType()) os.remove('config.txt')
def testSendingAlertBeyondInactivityTime(self): sys.stdout = MemoryWriter() message = self.message_mocker.CreateMock(Message) # when there is no message, inactivity action # is triggered if ellapsed time is greater than # inactivity time message.getPlainMessage().AndReturn((None, 'logpath')) self.message_mocker.ReplayAll() inactivityTime = 0.01 notifier = notifications.Inactivity(inactivityTime) self.log.inactivityTimer.inactivityEllapsed = overgap notifier.notify(message, self.log) self.assertTrue('Inactivity' in sys.stdout.captured[0]) self.message_mocker.VerifyAll()
def testIfMailNotificationTypeAlreadyAvailablebyMailShouldSetItUp(self): mailMocker = mox.Mox() mail = mailMocker.CreateMock(notifications.Mail) fh = open('config.txt', 'w') fh.write('inactivitynotification = mail\n') fh.close() property = Property('config.txt') property.parse_properties() notifier = notifications.Inactivity(1, property) if notifier.getNotificationType() == 'mail': notifier.setMailNotification(mail) else: self.fail('should be notifier with mail Notification') os.remove('config.txt')
def testInactivityTimeCanBeFloatingPointNumberSeconds(self): sys.stdout = MemoryWriter() message = self.message_mocker.CreateMock(Message) # when there is no message, inactivity action # is triggered if ellapsed time is greater than # inactivity time message.getPlainMessage().AndReturn((None, 'logpath')) self.message_mocker.ReplayAll() notifier = notifications.Inactivity(0.0000002543) self.options.inactivity = 0.0000002543 self.log.inactivityTimer.inactivityEllapsed = overgap notifier.notify(message, self.log) self.assertTrue('Inactivity' in sys.stdout.captured[0]) self.assertTrue(notifier.alerted) self.message_mocker.VerifyAll()
def testNotSendingAlertBelowInactivityTime(self): sys.stdout = MemoryWriter() self.message_mocker.ReplayAll() inactivityTime = 0.01 class Message(object): def __init__(self): pass def getPlainMessage(self): return (None, "alog") notifier = notifications.Inactivity(inactivityTime) self.options.inactivity = inactivityTime self.log.inactivityTimer.inactivityEllapsed = belowgap notifier.notify(Message(), self.log) self.assertTrue(len(sys.stdout.captured) == 0) self.message_mocker.VerifyAll()
def testalerted_not_alerted(self): options = Options() options.inactivity = 0.05 log = Log('out.log', None, options) message_mock = self.mocker.replace('log4tailer.message.Message') message_mock.getPlainMessage() self.mocker.count(1, None) self.mocker.result(('', 'logpath')) inactivityTime = 0.05 notifier = notifications.Inactivity(inactivityTime) self.mocker.replay() log.inactivityTimer.inactivityEllapsed = overgap notifier.notify(message_mock, log) self.assertTrue(notifier.alerted) log.inactivityTimer.inactivityEllapsed = belowgap notifier.notify(message_mock, log) self.assertFalse(notifier.alerted) notifier.notify(message_mock, log) log.inactivityTimer.inactivityEllapsed = overgap notifier.notify(message_mock, log) self.assertTrue(notifier.alerted)
def testShouldBePrintNotificationTypeifNoConfigFile(self): notifier = notifications.Inactivity(1) self.assertEqual('print', notifier.getNotificationType())