Beispiel #1
0
 def test_hostname_long(self):
     """
     Calling util.hostname(long=True) or util.hostname(True) should get the
     long hostanme
     """
     self.dbgfunc()
     hn = util.hostname(long=True)
     self.assertTrue('.' in hn, "Expected long hostname but got '%s'" % hn)
     hn = util.hostname(True)
     self.assertTrue('.' in hn, "Expected long hostname but got '%s'" % hn)
Beispiel #2
0
 def test_hostname_short(self):
     """
     Calling util.hostname(long=False) or util.hostname(False) should get
     the short hostname
     """
     self.dbgfunc()
     hn = util.hostname(long=False)
     self.assertFalse('.' in hn,
                      "Expected short hostname but got '%s'" % hn)
     hn = util.hostname(False)
     self.assertFalse('.' in hn,
                      "Expected short hostname but got '%s'" % hn)
Beispiel #3
0
 def test_hostname_short(self):
     """
     Calling util.hostname(long=False) or util.hostname(False) should get
     the short hostname
     """
     self.dbgfunc()
     hn = util.hostname(long=False)
     self.assertFalse('.' in hn,
                      "Expected short hostname but got '%s'" % hn)
     hn = util.hostname(False)
     self.assertFalse('.' in hn,
                      "Expected short hostname but got '%s'" % hn)
Beispiel #4
0
 def test_hostname_long(self):
     """
     Calling util.hostname(long=True) or util.hostname(True) should get the
     long hostanme
     """
     self.dbgfunc()
     hn = util.hostname(long=True)
     self.assertTrue('.' in hn,
                     "Expected long hostname but got '%s'" % hn)
     hn = util.hostname(True)
     self.assertTrue('.' in hn,
                     "Expected long hostname but got '%s'" % hn)
Beispiel #5
0
    def test_alert_email_mtcaller(self):
        """
        Generate an e-mail alert and verify that it was sent (this is where we
        use 'monkey patching'). For this case, caller is ''.
        """
        self.dbgfunc()
        fakesmtp.inbox = []
        logfile = self.tmpdir('alert_email.log')
        targets = "[email protected], [email protected], [email protected]"
        payload = 'this is an e-mail alert'
        sender = 'hpssic@' + util.hostname(long=True)

        cfg = CrawlConfig.CrawlConfig()
        cfg.add_section('crawler')
        cfg.add_section('alerts')
        cfg.set('crawler', 'logpath', logfile)
        cfg.set('alerts', 'email', targets)
        CrawlConfig.log(logpath=logfile, close=True)

        x = Alert.Alert(caller='', msg=payload, cfg=cfg)
        m = fakesmtp.inbox[0]
        self.expected(targets, ', '.join(m.to_address))
        self.expected(m.from_address, sender)
        self.expected_in('sent mail to', util.contents(logfile))
        self.expected_in(payload, m.fullmessage)
    def test_alert_email_mtcaller(self):
        """
        Generate an e-mail alert and verify that it was sent (this is where we
        use 'monkey patching'). For this case, caller is ''.
        """
        self.dbgfunc()
        fakesmtp.inbox = []
        logfile = self.tmpdir('alert_email.log')
        targets = "[email protected], [email protected], [email protected]"
        payload = 'this is an e-mail alert'
        sender = 'hpssic@' + util.hostname(long=True)

        cfg = CrawlConfig.CrawlConfig()
        cfg.add_section('crawler')
        cfg.add_section('alerts')
        cfg.set('crawler', 'logpath', logfile)
        cfg.set('alerts', 'email', targets)
        CrawlConfig.log(logpath=logfile, close=True)

        x = Alert.Alert(caller='', msg=payload,
                        cfg=cfg)
        m = fakesmtp.inbox[0]
        self.expected(targets, ', '.join(m.to_address))
        self.expected(m.from_address, sender)
        self.expected_in('sent mail to', util.contents(logfile))
        self.expected_in(payload, m.fullmessage)
Beispiel #7
0
 def test_hostname_default(self):
     """
     Calling util.hostname() with no argument should get the short hostname
     """
     self.dbgfunc()
     hn = util.hostname()
     self.assertFalse('.' in hn,
                      "Short hostname expected but got '%s'" % hn)
Beispiel #8
0
 def test_hostname_default(self):
     """
     Calling util.hostname() with no argument should get the short hostname
     """
     self.dbgfunc()
     hn = util.hostname()
     self.assertFalse('.' in hn,
                      "Short hostname expected but got '%s'" % hn)
 def test_sender_unspec(self):
     """
     The *sender* arg to CrawlMail.send() is unspecified. The generated
     message should use the default sender.
     """
     exp = 'hpssic@' + U.hostname(long=True)
     tolist = ['[email protected]', '[email protected]']
     subject = 'This is the topic we expect'
     body = 'Message body'
     CrawlMail.send(to=','.join(tolist), subj=subject, msg=body)
     m = fakesmtp.inbox[0]
     self.expected(exp, m.from_address)
     self.expected(tolist, m.to_address)
     self.expected_in(subject, m.fullmessage)
     self.expected_in(body, m.fullmessage)
 def test_sender_unspec(self):
     """
     The *sender* arg to CrawlMail.send() is unspecified. The generated
     message should use the default sender.
     """
     exp = 'hpssic@' + U.hostname(long=True)
     tolist = ['[email protected]', '[email protected]']
     subject = 'This is the topic we expect'
     body = 'Message body'
     CrawlMail.send(to=','.join(tolist),
                    subj=subject,
                    msg=body)
     m = fakesmtp.inbox[0]
     self.expected(exp, m.from_address)
     self.expected(tolist, m.to_address)
     self.expected_in(subject, m.fullmessage)
     self.expected_in(body, m.fullmessage)
Beispiel #11
0
    def test_alert_email_defcfg(self):
        """
        Generate an e-mail alert using the default config and verify that it
        was sent (this is where we use 'monkey patching').
        """
        self.dbgfunc()
        fakesmtp.inbox = []
        CrawlConfig.add_config(close=True)
        # with U.tmpenv('CRAWL_CONF', 'hpssic_test.cfg'):
        with U.tmpenv('CRAWL_CONF', None):
            logfile = self.tmpdir('alert_email.log')
            targets = "[email protected], [email protected]"
            payload = 'this is an e-mail alert'
            sender = 'hpssic@' + util.hostname(long=True)
            CrawlConfig.log(logpath=logfile, close=True)

            x = Alert.Alert(caller='cv', msg=payload)
            m = fakesmtp.inbox[0]
            self.expected(', '.join(m.to_address), targets)
            self.expected(m.from_address, sender)
            self.expected_in('sent mail to', util.contents(logfile))
            self.expected_in(payload, m.fullmessage)
Beispiel #12
0
    def test_alert_email_defcfg(self):
        """
        Generate an e-mail alert using the default config and verify that it
        was sent (this is where we use 'monkey patching').
        """
        self.dbgfunc()
        fakesmtp.inbox = []
        CrawlConfig.add_config(close=True)
        # with U.tmpenv('CRAWL_CONF', 'hpssic_test.cfg'):
        with U.tmpenv('CRAWL_CONF', None):
            logfile = self.tmpdir('alert_email.log')
            targets = "[email protected], [email protected]"
            payload = 'this is an e-mail alert'
            sender = 'hpssic@' + util.hostname(long=True)
            CrawlConfig.log(logpath=logfile, close=True)

            x = Alert.Alert(caller='cv', msg=payload)
            m = fakesmtp.inbox[0]
            self.expected(', '.join(m.to_address), targets)
            self.expected(m.from_address, sender)
            self.expected_in('sent mail to', util.contents(logfile))
            self.expected_in(payload, m.fullmessage)