diff --git a/tests/test_pagure_flask_ui_login.py b/tests/test_pagure_flask_ui_login.py index 966a35f..c59d50c 100644 --- a/tests/test_pagure_flask_ui_login.py +++ b/tests/test_pagure_flask_ui_login.py @@ -23,7 +23,7 @@ import os import flask import pygit2 -from mock import patch +from mock import patch, MagicMock sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -53,6 +53,7 @@ class PagureFlaskLogintests(tests.Modeltests): self.app = pagure.APP.test_client() + @patch('pagure.lib.notify.send_email', MagicMock(return_value=True)) def test_new_user(self): """ Test the new_user endpoint. """ @@ -329,6 +330,7 @@ class PagureFlaskLogintests(tests.Modeltests): self.assertIn( 'Email confirmed, account activated', output.data) + @patch('pagure.lib.notify.send_email', MagicMock(return_value=True)) def test_lost_password(self): """ Test the lost_password endpoint. """ @@ -381,6 +383,7 @@ class PagureFlaskLogintests(tests.Modeltests): 'check your spam folder? Otherwise, try again after some time.', output.data) + @patch('pagure.lib.notify.send_email', MagicMock(return_value=True)) def test_reset_password(self): """ Test the reset_password endpoint. """ diff --git a/tests/test_pagure_lib_notify.py b/tests/test_pagure_lib_notify.py index e8f2ba4..99ad3ce 100644 --- a/tests/test_pagure_lib_notify.py +++ b/tests/test_pagure_lib_notify.py @@ -16,7 +16,7 @@ import shutil import sys import os -from mock import patch +from mock import patch, MagicMock sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -169,8 +169,11 @@ class PagureLibNotifytests(tests.Modeltests): out = pagure.lib.notify._get_emails_for_obj(iss) self.assertEqual(out, exp) - def test_get_emails_for_obj_pr(self): + @patch('pagure.lib.notify.smtplib.SMTP') + def test_get_emails_for_obj_pr(self, mock_smtp): """ Test the _get_emails_for_obj method from pagure.lib.notify. """ + mock_smtp.return_value = MagicMock() + tests.create_projects(self.session) # Create the project ns/test @@ -246,8 +249,11 @@ class PagureLibNotifytests(tests.Modeltests): out = pagure.lib.notify._get_emails_for_obj(req) self.assertEqual(out, exp) - def test_get_emails_for_obj_pr_watching_project(self): + @patch('pagure.lib.notify.smtplib.SMTP') + def test_get_emails_for_obj_pr_watching_project(self, mock_smtp): """ Test the _get_emails_for_obj method from pagure.lib.notify. """ + mock_smtp.return_value = MagicMock() + tests.create_projects(self.session) # Create the project ns/test @@ -324,8 +330,11 @@ class PagureLibNotifytests(tests.Modeltests): out = pagure.lib.notify._get_emails_for_obj(req) self.assertEqual(out, exp) - def test_send_email(self): + @patch('pagure.lib.notify.smtplib.SMTP') + def test_send_email(self, mock_smtp): """ Test the notify_new_comment method from pagure.lib.notify. """ + mock_smtp.return_value = MagicMock() + email = pagure.lib.notify.send_email( 'Email content', 'Email “Subject“',