Ejemplo n.º 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
Ejemplo n.º 2
0
def store_template(toaddr, template_name, template_vars):
    ps = PendingSend()
    ps.toaddr = toaddr
    ps.template_name = template_name
    ps.template_vars = template_vars
    ps.save()
    return ps
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def test_simple_properties():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.last_error = 'bacon'

    assert ps.toaddr == '*****@*****.**'
    assert ps.template_name == 'template-1'
    assert ps.last_error == 'bacon'
Ejemplo n.º 5
0
def test_simple_properties():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.last_error = 'bacon'

    assert ps.toaddr == '*****@*****.**'
    assert ps.template_name == 'template-1'
    assert ps.last_error == 'bacon'
Ejemplo n.º 6
0
def test_unsent_and_sent():
    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.mark_sent()
    ps.save()

    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.save()

    unsent = list(PendingSend.Unsent())
    assert len(unsent) == 1
    ps = unsent[0]
    toaddr = ps.toaddr
    assert toaddr == '*****@*****.**'
Ejemplo n.º 7
0
def test_retried():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    assert ps.retry_count == 0

    ps.retried()
    ps.retried()
    ps.retried()

    assert ps.retry_count == 3
Ejemplo n.º 8
0
def test_unsent_and_sent():
    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.mark_sent()
    ps.save()

    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.save()

    unsent = list(PendingSend.Unsent())
    assert len(unsent) == 1
    ps = unsent[0]
    toaddr = ps.toaddr
    assert toaddr == '*****@*****.**'
Ejemplo n.º 9
0
def test_retried():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    assert ps.retry_count == 0

    ps.retried()
    ps.retried()
    ps.retried()

    assert ps.retry_count == 3
Ejemplo n.º 10
0
def test_sent():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    assert ps.sent_time is None

    then = datetime.now() - timedelta(seconds=2)
    ps.mark_sent()

    sent_time = ps.sent_time
    assert sent_time > then
    assert ps.is_sent
Ejemplo n.º 11
0
def test_sent():
    ps = PendingSend('abc')
    ps.toaddr = '*****@*****.**'
    assert ps.sent_time is None

    then = datetime.now() - timedelta(seconds = 2)
    ps.mark_sent()

    sent_time = ps.sent_time
    assert sent_time > then
    assert ps.is_sent
Ejemplo n.º 12
0
def test_creation():
    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.last_error = 'bacon'

    assert ps.id is None
    ps.save()
    assert ps.in_db
    assert ps.id > 0

    ps = PendingSend(ps.id)
    assert ps.in_db
    assert ps.toaddr == '*****@*****.**'
    assert ps.template_name == 'template-1'
    assert ps.template_vars == {'foo': 'bar'}
    assert ps.last_error == 'bacon'
    assert ps.retry_count == 0
    assert ps.age > timedelta()
    assert ps.age < timedelta(minutes=1)
Ejemplo n.º 13
0
def test_creation():
    ps = PendingSend()
    ps.toaddr = '*****@*****.**'
    ps.template_name = 'template-1'
    ps.template_vars = {"foo": 'bar'}
    ps.last_error = 'bacon'

    assert ps.id is None
    ps.save()
    assert ps.in_db
    assert ps.id > 0

    ps = PendingSend(ps.id)
    assert ps.in_db
    assert ps.toaddr == '*****@*****.**'
    assert ps.template_name == 'template-1'
    assert ps.template_vars == {'foo': 'bar'}
    assert ps.last_error == 'bacon'
    assert ps.retry_count == 0
    assert ps.age > timedelta()
    assert ps.age < timedelta(minutes = 1)
Ejemplo n.º 14
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
Ejemplo n.º 15
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