Exemple #1
0
    def test_try_send_throws(self):
        exp_addr = '*****@*****.**'
        exp_tpl  = 'example'
        exp_vars = {'foo':'bar'}

        ps = PendingSend()
        ps.toaddr = exp_addr
        ps.template_name = exp_tpl
        ps.template_vars = exp_vars

        exc_msg = "I am a teapot"
        def throws(to, subject, msg):
            raise Exception(exc_msg)

        mailer.send_email = throws
        mailer.try_send(ps)

        ps_stored = PendingSend(ps.id)

        sent = ps_stored.is_sent
        assert not sent
        last_error = ps_stored.last_error
        assert exc_msg in last_error
        retries = ps_stored.retry_count
        assert 1 == retries
Exemple #2
0
    def test_try_send_throws(self):
        exp_addr = '*****@*****.**'
        exp_tpl = 'example'
        exp_vars = {'foo': 'bar'}

        ps = PendingSend()
        ps.toaddr = exp_addr
        ps.template_name = exp_tpl
        ps.template_vars = exp_vars

        exc_msg = "I am a teapot"

        def throws(to, subject, msg):
            raise Exception(exc_msg)

        mailer.send_email = throws
        mailer.try_send(ps)

        ps_stored = PendingSend(ps.id)

        sent = ps_stored.is_sent
        assert not sent
        last_error = ps_stored.last_error
        assert exc_msg in last_error
        retries = ps_stored.retry_count
        assert 1 == retries
Exemple #3
0
    def test_try_send_ok(self):
        exp_addr = '*****@*****.**'
        exp_tpl  = 'example'
        exp_vars = {'foo':'bar'}

        ps = PendingSend()
        ps.toaddr = exp_addr
        ps.template_name = exp_tpl
        ps.template_vars = exp_vars

        mailer.try_send(ps)

        tpl_lines = test_helpers.template(exp_tpl + '.txt')
        exp_subject = tpl_lines[0]

        assert exp_addr == self._to
        assert self._subject in exp_subject
        assert 'foo' not in self._msg
        assert 'bar' in self._msg

        ps_stored = PendingSend(ps.id)

        sent = ps_stored.is_sent
        assert sent
Exemple #4
0
    def test_try_send_ok(self):
        exp_addr = '*****@*****.**'
        exp_tpl = 'example'
        exp_vars = {'foo': 'bar'}

        ps = PendingSend()
        ps.toaddr = exp_addr
        ps.template_name = exp_tpl
        ps.template_vars = exp_vars

        mailer.try_send(ps)

        tpl_lines = test_helpers.template(exp_tpl + '.txt')
        exp_subject = tpl_lines[0]

        assert exp_addr == self._to
        assert self._subject in exp_subject
        assert 'foo' not in self._msg
        assert 'bar' in self._msg

        ps_stored = PendingSend(ps.id)

        sent = ps_stored.is_sent
        assert sent
Exemple #5
0
def send_emails(limit = 50):
    unsent_mails = PendingSend.Unsent(max_results = limit)
    for ps in unsent_mails:
        mailer.try_send(ps)
Exemple #6
0
def send_emails(limit=50, max_retry=5):
    unsent_mails = PendingSend.Unsent(max_retry=max_retry, max_results=limit)
    for ps in unsent_mails:
        mailer.try_send(ps)