From d79eb8ef5307ff1676f788c56a4183878da9700b Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Mon, 18 May 2020 13:33:57 +0200 Subject: [PATCH] Add new tests to check for email failures --- ihatemoney/tests/tests.py | 79 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index 3bd47e4c..f900bd7e 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -5,15 +5,18 @@ try: except ImportError: import unittest # NOQA try: - from unittest.mock import patch + from unittest.mock import patch, MagicMock except ImportError: - from mock import patch + from mock import patch, MagicMock import datetime import os import json from collections import defaultdict import six +import re +import smtplib +import socket from time import sleep from werkzeug.security import generate_password_hash, check_password_hash @@ -1632,5 +1635,77 @@ class CommandTestCase(BaseTestCase): self.assertEqual(len(models.Project.query.all()), 0) +class EmailFailureTestCase(IhatemoneyTestCase): + def test_creation_email_failure_smtp(self): + self.login("raclette") + with patch.object( + self.app.mail, "send", MagicMock(side_effect=smtplib.SMTPException) + ): + resp = self.post_project("raclette", follow_redirects=True) + # Check that an error message is displayed + self.assertIn( + "We tried to send you an reminder email, but there was an error", + resp.data.decode("utf-8"), + ) + # Check that we are redirected anyway + self.assertIn( + 'You probably want to