Ejemplo n.º 1
0
    def test_ignore(self):
        ignored = [ RegexConversion('^bad start')
                  , RegexConversion('(.*)Some String')
                  , RegexConversion('(.*)http:(.*)\/view')
                  ]
        self.handler = MailingLogger( '*****@*****.**'
                                    , ('*****@*****.**',)
                                    , ignore=ignored
                                    )
        logger = self.getLogger()
        logger.addHandler(self.handler)
        # make it 11pm
        setTime('2007-03-15 23:00:00')
        # paranoid check
        self.assertEqual(len(DummySMTP.sent),0)

        # Now test a few variations
        logger.critical('This Line Contains Some String.')
        self.assertEqual(len(DummySMTP.sent),0)

        logger.critical('bad starts and terrible endings')
        self.assertEqual(len(DummySMTP.sent),0)

        logger.critical('NotFoundError: http://my.site.com/some/path/view')
        self.assertEqual(len(DummySMTP.sent),0)

        # Interpolations are also ignored
        logger.critical('NotFoundError: %s',
                        'http://my.site.com/some/path/view')
        self.assertEqual(len(DummySMTP.sent),0)

        # Non-matching stuff still gets through
        logger.critical('message1')
        self.assertEqual(len(DummySMTP.sent),1)
Ejemplo n.º 2
0
 def test_subject_contains_date(self):
     # set up logger
     self.handler = MailingLogger('*****@*****.**',('*****@*****.**',),
                                  subject="%(asctime)s")
     logger = self.getLogger()
     logger.addHandler(self.handler)
     setTime('2007-03-15 23:00:00')
     logger.critical('message')
     self.assertEqual(len(DummySMTP.sent),1)
     m = DummySMTP.sent[0][3]
     self.failUnless('Subject: 2007-03-15 23:00:00,000' in m)
Ejemplo n.º 3
0
 def test_flood_protection_bug(self):
     # set up logger
     self.handler = MailingLogger('*****@*****.**',('*****@*****.**',),
                                  flood_level=1)
     logger = self.getLogger()
     logger.addHandler(self.handler)
     # make it 11pm
     setTime('2007-03-15 23:00:00')
     # paranoid check
     self.assertEqual(len(DummySMTP.sent),0)
     # log until flood protection kicked in
     logger.critical('message1')
     logger.critical('message2')
     # check - 1 logged, 1 final warning
     self.assertEqual(len(DummySMTP.sent),2)
     # check nothing emitted
     logger.critical('message3')
     self.assertEqual(len(DummySMTP.sent),2)
     # advance time past midnight
     setTime('2007-03-15 00:00:00')
     # log again
     logger.critical('message4')
     # check we are emitted now!
     self.assertEqual(len(DummySMTP.sent),3)
Ejemplo n.º 4
0
 def setUp(self):
     DummySMTP.install(stdout=False)
     setTime()