def test_to_empty_cfg(self): """ The *to* arg to CrawlMail.send() is empty. A config is provided. The to address list should be taken from the config. """ exp = "[email protected],[email protected]" cdict = {'crawler': {'notify-e-mail': exp}, 'alerts': {'recipients': "[email protected],[email protected]"}, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.recipients' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to='', subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(exp.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_sectopt_nosect(self): """ The *to* arg to CrawlMail.send() is a section.option ref into a config object. However, the section is not present in the config object. CrawlMail.send() should use a default recipient. """ exp = "*****@*****.**" cdict = {'crawler': {'notify-email': "*****@*****.**"}, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.recipients' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to=to, subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(exp.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_sectopt_noopt(self): """ The *to* arg to CrawlMail.send() is a section.option ref into a config object. Should work. """ exp = "*****@*****.**" cdict = { 'crawler': { 'notify-email': "*****@*****.**" }, 'alerts': { 'recipients': exp }, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.froodle' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to=to, subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(exp.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_sectopt_nocfg(self): """ The *to* arg to CrawlMail.send() is a section.option ref into a config object. Should work. """ exp = "*****@*****.**" cdict = {'crawler': {'notify-email': "*****@*****.**"}, 'alerts': {'recipients': exp}, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.recipients' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to=to, subj=subject, msg=body, cfg=None) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected([exp], m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_sender_cfg(self): """ The *sender* arg to CrawlMail.send() is empty. Sender should be pulled from the configuration [crawler.from_address] """ exp = "*****@*****.**" cdict = { 'crawler': { 'notify-email': "*****@*****.**", 'from_address': exp }, 'alerts': { 'recipients': "[email protected],[email protected]" }, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) to = "[email protected],[email protected]" subject = 'Topic' body = 'Message body' CrawlMail.send(sender='', to=to, subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(exp, m.from_address) self.expected(to.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_sectopt(self): """ The *to* arg to CrawlMail.send() is a section.option ref into a config object. Should work. """ exp = "[email protected],[email protected]" cdict = {'crawler': {'notify-email': "*****@*****.**"}, 'alerts': {'recipients': exp}, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.recipients' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to=to, subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(exp.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_empty_cfg(self): """ The *to* arg to CrawlMail.send() is empty. A config is provided. The to address list should be taken from the config. """ exp = "[email protected],[email protected]" cdict = { 'crawler': { 'notify-e-mail': exp }, 'alerts': { 'recipients': "[email protected],[email protected]" }, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) sender = '*****@*****.**' to = 'alerts.recipients' subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to='', subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(exp.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_sender_cfg(self): """ The *sender* arg to CrawlMail.send() is empty. Sender should be pulled from the configuration [crawler.from_address] """ exp = "*****@*****.**" cdict = {'crawler': {'notify-email': "*****@*****.**", 'from_address': exp}, 'alerts': {'recipients': "[email protected],[email protected]"}, } cfg = CrawlConfig.CrawlConfig.dictor(cdict) to = "[email protected],[email protected]" subject = 'Topic' body = 'Message body' CrawlMail.send(sender='', to=to, subj=subject, msg=body, cfg=cfg) m = fakesmtp.inbox[0] self.expected(exp, m.from_address) self.expected(to.split(','), m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_msg_unspec(self): """ The *msg* arg to CrawlMail.send() is unspecified. Show throw exception. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'Topic' body = '' CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(MSG.empty_message, m.fullmessage)
def test_subj_unspec(self): """ The *subj* arg to CrawlMail.send() is unspecified. The generated message should have the default subject 'HPSS Integrity Crawler ALERT' """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] default_subj = 'HPSS Integrity Crawler ALERT' body = 'Message body' CrawlMail.send(sender=sender, to=','.join(tolist), msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(MSG.default_mail_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)
def test_msg_empty(self): """ The *msg* arg to CrawlMail.send() is empty. Send it anyway. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'Topic' body = '' CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject, msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(MSG.empty_message, m.fullmessage)
def test_subj_something(self): """ The *subj* arg to CrawlMail.send() is set. The generated message should have the correct subject. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'This is the topic we expect' body = 'Message body' CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject, msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_to_csv(self): """ The *to* arg to CrawlMail.send() is a comma separated list of addresses. Should work. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'Topic' body = 'Message body' CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject, msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_sender_something(self): """ The *sender* arg to CrawlMail.send() is set. The generated message should have the correct sender. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'Topic' body = 'Not an empty message' CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject, msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def test_msg_something(self): """ The *msg* arg to CrawlMail.send() is set. The generated message should have the correct message body. """ sender = '*****@*****.**' tolist = ['[email protected]', '[email protected]'] subject = 'Topic' body = """ This is a very elaborate message body containing very specific test information. """ CrawlMail.send(sender=sender, to=','.join(tolist), subj=subject, msg=body) m = fakesmtp.inbox[0] self.expected(sender, m.from_address) self.expected(tolist, m.to_address) self.expected_in(subject, m.fullmessage) self.expected_in(body, m.fullmessage)
def main(cfg): """ This plugin will generate a report and send it to the designated e-mail address(es). """ rval = 0 try: if cfg is None: cfg = CrawlConfig.get_config() subject = "%s %s" % (cfg.get( 'rpt', 'subject'), time.strftime("%Y.%m%d %H:%M:%S", time.localtime())) CrawlMail.send(sender=cfg.get('rpt', 'sender'), to='rpt.recipients', subj=subject, msg=rpt_lib.get_report()) except Exception as e: rval = 1 CrawlConfig.log("Failure in rpt_lib: '%s'" % str(e)) return rval
def main(cfg): """ This plugin will generate a report and send it to the designated e-mail address(es). """ rval = 0 try: if cfg is None: cfg = CrawlConfig.get_config() subject = "%s %s" % (cfg.get('rpt', 'subject'), time.strftime("%Y.%m%d %H:%M:%S", time.localtime())) CrawlMail.send(sender=cfg.get('rpt', 'sender'), to='rpt.recipients', subj=subject, msg=rpt_lib.get_report()) except Exception as e: rval = 1 CrawlConfig.log("Failure in rpt_lib: '%s'" % str(e)) return rval