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
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
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
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'
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 == '*****@*****.**'
def test_retried(): ps = PendingSend('abc') ps.toaddr = '*****@*****.**' assert ps.retry_count == 0 ps.retried() ps.retried() ps.retried() assert ps.retry_count == 3
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
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
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)
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)
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
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