From 6fc9ddeaeefaca60c30756c53bf5be27c3fb2966 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 | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index 7065a43b..c55a5199 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -5,6 +5,8 @@ import io import json import os import re +import smtplib +import socket from time import sleep import unittest from unittest.mock import MagicMock, patch @@ -2288,6 +2290,78 @@ class ModelsTestCase(IhatemoneyTestCase): self.assertEqual(bill.pay_each(), pay_each_expected) +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 %s<\/em>' % string