Exemple #1
0
    def etl_not_valid(self, err=''):

        self.is_valid = False
        self.is_scheduled = False
        db.session.merge(self)
        db.session.commit()

        msq = '[etl_not_valid] {}'.format(err[:1000])
        logger.exception(msq)

        # TODO SET USER OBJECT

        # send user email
        email = '*****@*****.**'
        subject = 'Etl table ({}) not valid'.format(self.sql_table_name)

        # move to template emails
        message = 'Etl table <b>({table_name})</b>, ' \
                  'has changed.<br/>Please login ' \
                  'and repair or create new table.'.format(
                        table_name=self.sql_table_name
                  )
        send_email_smtp(email,
                        subject,
                        message,
                        app.config,
                        dryrun=not app.config.get('EMAIL_NOTIFICATIONS'))
        raise Exception('[etl_not_valid] {}'.format(err[:1000]))
def _deliver_email(schedule, subject, email):
    for (to, bcc) in _get_recipients(schedule):
        send_email_smtp(
            to, subject, email.body, config,
            data=email.data,
            images=email.images,
            bcc=bcc,
            mime_subtype='related',
        )
Exemple #3
0
 def test_send_bcc_smtp(self, mock_send_mime):
     attachment = tempfile.NamedTemporaryFile()
     attachment.write(b'attachment')
     attachment.seek(0)
     utils.send_email_smtp(
         'to', 'subject', 'content', app.config, files=[attachment.name],
         cc='cc', bcc='bcc')
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     assert call_args[0] == app.config.get('SMTP_MAIL_FROM')
     assert call_args[1] == ['to', 'cc', 'bcc']
     msg = call_args[2]
     assert msg['Subject'] == 'subject'
     assert msg['From'] == app.config.get('SMTP_MAIL_FROM')
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEApplication('attachment')
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
 def test_send_bcc_smtp(self, mock_send_mime):
     attachment = tempfile.NamedTemporaryFile()
     attachment.write(b'attachment')
     attachment.seek(0)
     utils.send_email_smtp(
         'to', 'subject', 'content', app.config, files=[attachment.name],
         cc='cc', bcc='bcc')
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     assert call_args[0] == app.config.get('SMTP_MAIL_FROM')
     assert call_args[1] == ['to', 'cc', 'bcc']
     msg = call_args[2]
     assert msg['Subject'] == 'subject'
     assert msg['From'] == app.config.get('SMTP_MAIL_FROM')
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEApplication('attachment')
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
 def test_send_smtp_data(self, mock_send_mime):
     utils.send_email_smtp('to',
                           'subject',
                           'content',
                           app.config,
                           data={'1.txt': b'data'})
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     logging.debug(call_args)
     assert call_args[0] == app.config.get('SMTP_MAIL_FROM')
     assert call_args[1] == ['to']
     msg = call_args[2]
     assert msg['Subject'] == 'subject'
     assert msg['From'] == app.config.get('SMTP_MAIL_FROM')
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEApplication('data')
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
 def test_send_smtp_inline_images(self, mock_send_mime):
     image = read_fixture('sample.png')
     utils.send_email_smtp('to',
                           'subject',
                           'content',
                           app.config,
                           images=dict(blah=image))
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     logging.debug(call_args)
     assert call_args[0] == app.config.get('SMTP_MAIL_FROM')
     assert call_args[1] == ['to']
     msg = call_args[2]
     assert msg['Subject'] == 'subject'
     assert msg['From'] == app.config.get('SMTP_MAIL_FROM')
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEImage(image)
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()