def get(self, id): email = Email.by_id(id) if email is None: abort(404, message="Mail not found") return email.as_dict()
def test_mail_service_error_should_set_status(): m = new_email() ms = MailService(db) class MockPostman(object): def deliver(self, from_email, to, subject, text, html=None): return {'success': False, 'status': 400} ms.postman = MockPostman() ms.send_mail(m) mail = Email.by_id(str(m.id)) assert mail.status == Statuses.error
def test_successfull_mail(): m = new_email() ms = MailService(db) class MockPostman(object): def deliver(self, from_email, to, subject, text, html=None): return {'success': True, 'status': 200} ms.postman = MockPostman() ms.send_mail(m) mail = Email.by_id(str(m.id)) assert mail.status == Statuses.success
def post(self, id=None): data = request.form validation_messages = validate_form(data) if len(validation_messages) > 0: abort(400, message=validation_messages) logging.info(data) email_id = Email.insert(data) logging.info("Commit completed " + email_id) mail = Email.by_id(email_id).as_dict() mail.update({'success': True}) return mail
def test_mail_service_failover(): m = new_email() ms = MailService(db) class MockPostman(object): def __init__(self): self.switched = False def deliver(self, from_email, to, subject, text, html=None): return {'success': False, 'status': 500} def switch(self): self.switched = True ms.postman = MockPostman() ms.send_mail(m) mail = Email.by_id(str(m.id)) assert ms.postman.switched