def setUp(self): self.participant = notify.ParticipantHandler() self.wid = Workitem(BASE_WORKITEM) self.wid.fields.msg = [ "message 1", "message 2", u"message unicode: \xe1\xe1", u"message utf8: \xe1\xe1".encode('utf-8') ] self.wid.fields.req = {'id': '6'} self.wid.params.subject = "Fake Mail Subject" self.wid.params.template = "mail_template.tpl" self.wid.params.mail_from = "Fake Sender <*****@*****.**>" self.wid.params.mail_to = ["Fake User <*****@*****.**>"] self.participant.email_store = "tests/test_data" self.template_body = open( os.path.join(self.participant.email_store, self.wid.params.template)).read() smtp = Mock(spec_set=smtplib.SMTP) smtp.sendmail.side_effect = self.mock_sendmail notify.smtplib = Mock() notify.smtplib.SMTP.return_value = smtp notify.smtplib.SMTPException = smtplib.SMTPException self.expect_sender = self.wid.params.mail_from[:] self.expect_recipients = self.wid.params.mail_to[:] self.in_msg = self.wid.fields.msg[:] self.in_msg.append("Subject: %s" % self.wid.params.subject) self.in_msg.append("id=%s" % self.wid.fields.req.id) self.in_msg.append('"" should be empty') self.in_msg.append('"" should also be empty') self.sendmail_count = 0 self.sendmail_fail = 0 self.rejections = {}
def test_valid_spec(self): wid = Workitem(WI_TEMPLATE) wid.fields.ev.actions = self.fake_actions self.participant.obs.getFile.return_value = spec_file_content self.participant.handle_wi(wid) self.assertTrue(wid.result)
def test_changelog_in_spec(self): wid = Workitem(WI_TEMPLATE) wid.fields.ev.actions = self.fake_actions self.participant.obs.getFile.return_value = spec_file_content \ + "\n%changelog" self.participant.handle_wi(wid) self.assertFalse(wid.result)
def workitem_callback(self, msg): """ This is where a workitem message is handled """ tag = msg.delivery_info["delivery_tag"] try: self.workitem = Workitem(msg.body) except ValueError as exobj: # Reject and don't requeue the message self._chan.basic_reject(tag, False) self.log.warning("Exception decoding incoming json\n" "%s\n" "Note: Now re-raising exception\n" % format_block(msg.body)) raise exobj # Launch consume() in separate thread so it doesn't get interrupted by # signals if not self.workitem.is_cancel: consumer = ConsumerThread(self) consumer.start() consumer.join() if consumer.exception: self.workitem.error = { "class": "Ruote::Amqp::RemoteError", "message": format_exception(consumer.exception), "trace": format_ruby_backtrace(consumer.trace) } else: self.log.warning("Ignoring a cancel message") # Acknowledge the message as received self._chan.basic_ack(tag) if not self.workitem.forget: self.reply_to_engine()
def setUp(self): BaseTestParticipantHandler.setUp(self) self.wid = Workitem(BASE_WORKITEM) self.participant.obs.getFile.return_value = TEST_SPEC
def test_bad_workitem(self): wid = Workitem(WI_TEMPLATE) wid.fields.ev.actions = [] self.assertRaises(RuntimeError, self.participant.handle_wi, wid)
def setUp(self): self.wid = Workitem(WI_TEMPLATE) self.dummy = Dummy() self.action = {"sourcepackage": "pkg", "type": "submit"}