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 test_template_vars_property():
    print 'bacon'
    ps = PendingSend('abc')
    assert ps.template_vars is None

    ps.template_vars = {"foo": 'bar'}
    assert ps.template_vars == {'foo': 'bar'}
Ejemplo n.º 3
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.º 4
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.º 5
0
def test_template_vars_property():
    print 'bacon'
    ps = PendingSend('abc')
    assert ps.template_vars is None

    ps.template_vars = {"foo": 'bar'}
    assert ps.template_vars == {'foo': 'bar'}
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_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.º 8
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.º 9
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.º 10
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.º 11
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