def testcontainsOwnTargetLog(self): self.configfh = open('anotherconfig.txt','w') key = "targets /var/log/messages" value = "$2009-08-09 anything, ^regex2" targetline = key+"="+value+"\n" self.configfh.write(targetline) self.configfh.close() property = Property('anotherconfig.txt') property.parse_properties() self.assertEqual(value,property.get_value(key)) os.remove('anotherconfig.txt')
def testShouldSetupMailNotificationIfAnalyticsNotificationIsSetup(self): fh = open('aconfig','w') fh.write('analyticsnotification = mail\n') fh.write('analyticsgaptime = 3600\n') fh.close() properties = Property('aconfig') properties.parse_properties() self.assertTrue(properties.is_key('analyticsnotification')) arrayLog = [Log('out.log')] resume = reporting.Resume(arrayLog) mailactionmocker = mox.Mox() mailaction = mailactionmocker.CreateMock(notifications.Mail) if properties.get_value('analyticsnotification') == 'mail': resume.setMailNotification(mailaction) self.assertEquals('mail',resume.getNotificationType()) gaptime = properties.get_value('analyticsgaptime') if gaptime: resume.setAnalyticsGapNotification(gaptime) self.assertEquals(3600,int(resume.getGapNotificationTime())) os.remove('aconfig')
def testTargetsNoColors(self): fh = open('config.txt','w') regexes = "log$; ^2009-10-12 got something here$" targetsline = "targets /var/log/messages = "+regexes+"\n" fh.write(targetsline) fh.close() property = Property('config.txt') property.parse_properties() self.assertEqual(regexes, property.get_value('targets /var/log/messages')) log = Log('/var/log/messages', property) color = log.logTargetColor.get(re.compile('log$')) self.assertFalse(color) os.remove('config.txt')
def testshouldHaveitsOwnTargetSchemesIfProvidedInConfigFile(self): fh = open('config.txt','w') regexesColors = ("log$ : yellow, on_cyan; ^2009-10-12 got something " "here$ : black, on_cyan") targetsline = "targets /var/log/messages = "+regexesColors+"\n" fh.write(targetsline) fh.close() property = Property('config.txt') property.parse_properties() self.assertEqual(regexesColors, property.get_value('targets /var/log/messages')) log = Log('/var/log/messages', property) logTargetsColors = {re.compile('log$'): 'yellow, on_cyan', re.compile("^2009-10-12 got something here$") : 'black, on_cyan'} self.assertEqual(logTargetsColors, log.logTargetColor) os.remove('config.txt')
def testshouldReturnNoneifKeyNotFound(self): property = Property(self.configfile) property.parse_properties() key = 'hi' self.assertFalse(property.get_value(key))